From 6ec24b52bdf5dfd71c7e4fb1c11e0800569e9a0c Mon Sep 17 00:00:00 2001 From: Yaroslav Onischenko Date: Fri, 18 Mar 2016 12:30:21 +0200 Subject: [PATCH 01/22] MAGETWO-50507: Exception error appears if Merchant resets "Product Attributes mass update" Admin form --- .../Product/Action/Attribute/Edit.php | 21 +- .../Product/Action/Attribute/EditTest.php | 191 ++++++++++++++++++ 2 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/EditTest.php diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php index 29f30ad573f03..0a623f6a4ca7f 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php @@ -53,8 +53,12 @@ public function __construct( */ public function execute() { - $collection = $this->filter->getCollection($this->collectionFactory->create()); - $this->attributeHelper->setProductIds($collection->getAllIds()); + $this->verifyNamespace(); + + if ($this->getRequest()->getParam('filters')) { + $collection = $this->filter->getCollection($this->collectionFactory->create()); + $this->attributeHelper->setProductIds($collection->getAllIds()); + } if (!$this->_validateProducts()) { return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]); @@ -63,4 +67,17 @@ public function execute() $resultPage->getConfig()->getTitle()->prepend(__('Update Attributes')); return $resultPage; } + + /** + * Check if namespace is specified + * @return void + */ + private function verifyNamespace() + { + if (!$this->getRequest()->getParam('namespace')) { + $params = $this->getRequest()->getParams(); + $params['namespace'] = 'product_listing'; + $this->getRequest()->setParams($params); + } + } } diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/EditTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/EditTest.php new file mode 100644 index 0000000000000..4c268a8857674 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/EditTest.php @@ -0,0 +1,191 @@ +attributeHelper = $this->getMockBuilder('Magento\Catalog\Helper\Product\Edit\Action\Attribute') + ->setMethods(['getProductIds', 'setProductIds']) + ->disableOriginalConstructor()->getMock(); + + $this->resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->filter = $this->getMockBuilder('Magento\Ui\Component\MassAction\Filter') + ->setMethods(['getCollection'])->disableOriginalConstructor()->getMock(); + + $this->collectionFactory = $this->getMockBuilder( + 'Magento\Catalog\Model\ResourceModel\Product\CollectionFactory' + )->setMethods(['create'])->disableOriginalConstructor()->getMock(); + + $this->resultPage = $this->getMockBuilder('Magento\Framework\View\Result\Page') + ->setMethods(['getConfig'])->disableOriginalConstructor()->getMock(); + + $resultPageFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->setMethods(['create'])->disableOriginalConstructor()->getMock(); + $resultPageFactory->expects($this->any())->method('create')->willReturn($this->resultPage); + + $this->prepareContext(); + + $this->object = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject( + 'Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Edit', + [ + 'context' => $this->context, + 'attributeHelper' => $this->attributeHelper, + 'filter' => $this->filter, + 'resultPageFactory' => $resultPageFactory, + 'collectionFactory' => $this->collectionFactory + ] + ); + } + + private function prepareContext() + { + $this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http') + ->setMethods(['getParam', 'getParams', 'setParams']) + ->disableOriginalConstructor()->getMock(); + + $objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface'); + $product = $this->getMockBuilder('Magento\Catalog\Model\Product') + ->setMethods(['isProductsHasSku']) + ->disableOriginalConstructor()->getMock(); + $product->expects($this->any())->method('isProductsHasSku') + ->with([1, 2, 3]) + ->willReturn(true); + $objectManager->expects($this->any())->method('create') + ->with('Magento\Catalog\Model\Product') + ->willReturn($product); + $messageManager = $this->getMockBuilder('\Magento\Framework\Message\ManagerInterface') + ->setMethods([]) + ->disableOriginalConstructor()->getMock(); + $messageManager->expects($this->any())->method('addError')->willReturn(true); + $this->context = $this->getMockBuilder('Magento\Backend\App\Action\Context') + ->setMethods(['getRequest', 'getObjectManager', 'getMessageManager', 'getResultRedirectFactory']) + ->disableOriginalConstructor()->getMock(); + $this->context->expects($this->any())->method('getRequest')->willReturn($this->request); + $this->context->expects($this->any())->method('getObjectManager')->willReturn($objectManager); + $this->context->expects($this->any())->method('getMessageManager')->willReturn($messageManager); + $this->context->expects($this->any())->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactory); + } + + public function testExecutePageRequested() + { + $this->request->expects($this->any())->method('getParam')->willReturnMap( + [ + ['namespace', null, 'product_listing'], + ['filters', null, ['placeholder' => true]] + ] + ); + $this->request->expects($this->any())->method('getParams')->willReturn( + [ + 'namespace' => 'product_listing', + 'exclude' => true, + 'filters' => ['placeholder' => true] + ] + ); + + $this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn([1, 2, 3]); + $this->attributeHelper->expects($this->any())->method('setProductIds')->with([1, 2, 3]); + + $collection = $this->getMockBuilder('Magento\Catalog\Model\ResourceModel\Product\Collection') + ->setMethods(['getAllIds']) + ->disableOriginalConstructor()->getMock(); + $collection->expects($this->any())->method('getAllIds')->willReturn([1, 2, 3]); + $this->filter->expects($this->any())->method('getCollection')->with($collection)->willReturn($collection); + $this->collectionFactory->expects($this->any())->method('create')->willReturn($collection); + + $title = $this->getMockBuilder('Magento\Framework\View\Page\Title') + ->setMethods(['prepend']) + ->disableOriginalConstructor()->getMock(); + $config = $this->getMockBuilder('Magento\Framework\View\Page\Config') + ->setMethods(['getTitle']) + ->disableOriginalConstructor()->getMock(); + $config->expects($this->any())->method('getTitle')->willReturn($title); + $this->resultPage->expects($this->any())->method('getConfig')->willReturn($config); + + $this->assertSame($this->resultPage, $this->object->execute()); + } + + public function testExecutePageReload() + { + $this->request->expects($this->any())->method('getParam')->willReturnMap( + [ + ['namespace', null, null], + ['filters', null, null] + ] + ); + $this->request->expects($this->any())->method('getParams')->willReturn([]); + + $this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn([1, 2, 3]); + $this->attributeHelper->expects($this->any())->method('setProductIds')->with([1, 2, 3]); + + $title = $this->getMockBuilder('Magento\Framework\View\Page\Title') + ->setMethods(['prepend']) + ->disableOriginalConstructor()->getMock(); + $config = $this->getMockBuilder('Magento\Framework\View\Page\Config') + ->setMethods(['getTitle']) + ->disableOriginalConstructor()->getMock(); + $config->expects($this->any())->method('getTitle')->willReturn($title); + $this->resultPage->expects($this->any())->method('getConfig')->willReturn($config); + + $this->assertSame($this->resultPage, $this->object->execute()); + } + + public function testExecutePageDirectAccess() + { + $this->request->expects($this->any())->method('getParam')->willReturnMap( + [ + ['namespace', null, null], + ['filters', null, null] + ] + ); + $this->request->expects($this->any())->method('getParams')->willReturn([]); + $this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn(null); + + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->setMethods(['setPath']) + ->disableOriginalConstructor() + ->getMock(); + $resultRedirect->expects($this->any())->method('setPath') + ->with('catalog/product/', ['_current' => true]) + ->willReturnSelf(); + $this->resultRedirectFactory->expects($this->any()) + ->method('create') + ->willReturn($resultRedirect); + + $this->assertSame($resultRedirect, $this->object->execute()); + } +} From 795ff97e369215d2634537ce764a909c0e40dcc8 Mon Sep 17 00:00:00 2001 From: Yaroslav Onischenko Date: Mon, 21 Mar 2016 11:57:41 +0200 Subject: [PATCH 02/22] MAGETWO-50507: Exception error appears if Merchant resets "Product Attributes mass update" Admin form - CR changes --- .../Product/Action/Attribute/Edit.php | 15 ------------- .../Product/Action/Attribute/EditTest.php | 21 +++---------------- 2 files changed, 3 insertions(+), 33 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php index 0a623f6a4ca7f..f24d8ea1e84ae 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php @@ -53,8 +53,6 @@ public function __construct( */ public function execute() { - $this->verifyNamespace(); - if ($this->getRequest()->getParam('filters')) { $collection = $this->filter->getCollection($this->collectionFactory->create()); $this->attributeHelper->setProductIds($collection->getAllIds()); @@ -67,17 +65,4 @@ public function execute() $resultPage->getConfig()->getTitle()->prepend(__('Update Attributes')); return $resultPage; } - - /** - * Check if namespace is specified - * @return void - */ - private function verifyNamespace() - { - if (!$this->getRequest()->getParam('namespace')) { - $params = $this->getRequest()->getParams(); - $params['namespace'] = 'product_listing'; - $this->getRequest()->setParams($params); - } - } } diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/EditTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/EditTest.php index 4c268a8857674..d329ec1aabafc 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/EditTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/EditTest.php @@ -103,12 +103,7 @@ private function prepareContext() public function testExecutePageRequested() { - $this->request->expects($this->any())->method('getParam')->willReturnMap( - [ - ['namespace', null, 'product_listing'], - ['filters', null, ['placeholder' => true]] - ] - ); + $this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(['placeholder' => true]); $this->request->expects($this->any())->method('getParams')->willReturn( [ 'namespace' => 'product_listing', @@ -141,12 +136,7 @@ public function testExecutePageRequested() public function testExecutePageReload() { - $this->request->expects($this->any())->method('getParam')->willReturnMap( - [ - ['namespace', null, null], - ['filters', null, null] - ] - ); + $this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(null); $this->request->expects($this->any())->method('getParams')->willReturn([]); $this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn([1, 2, 3]); @@ -166,12 +156,7 @@ public function testExecutePageReload() public function testExecutePageDirectAccess() { - $this->request->expects($this->any())->method('getParam')->willReturnMap( - [ - ['namespace', null, null], - ['filters', null, null] - ] - ); + $this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(null); $this->request->expects($this->any())->method('getParams')->willReturn([]); $this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn(null); From 41c8dd49ff73212360d58f9623f76499d74c5171 Mon Sep 17 00:00:00 2001 From: Yurii Hryhoriev Date: Tue, 22 Mar 2016 12:02:29 +0200 Subject: [PATCH 03/22] MAGETWO-48239: Improper escaping on RSS page on Storefront --- app/code/Magento/Rss/view/frontend/templates/feeds.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Rss/view/frontend/templates/feeds.phtml b/app/code/Magento/Rss/view/frontend/templates/feeds.phtml index 86211e9977d7b..81ac6fd803259 100644 --- a/app/code/Magento/Rss/view/frontend/templates/feeds.phtml +++ b/app/code/Magento/Rss/view/frontend/templates/feeds.phtml @@ -14,7 +14,7 @@ getFeeds() as $feed): ?> - + escapeHtml($feed['label']) ?> @@ -23,7 +23,7 @@ - + escapeHtml($item['label']) ?> From c4d33abaa2d62138b253959ae2603819431cafd3 Mon Sep 17 00:00:00 2001 From: Yurii Hryhoriev Date: Thu, 31 Mar 2016 15:30:06 +0300 Subject: [PATCH 04/22] MAGETWO-51238: Swatches are not displayed on category page --- .../ConfigurableProduct/Model/Product/Type/Configurable.php | 3 +++ .../view/frontend/templates/product/layered/renderer.phtml | 2 +- .../view/frontend/templates/product/listing/renderer.phtml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php index e2a2cdf527fd5..0cd50337b8f85 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php @@ -508,6 +508,9 @@ public function getUsedProducts($product, $requiredAttributeIds = null) $collection = $this->getUsedProductCollection($product) ->addAttributeToSelect('name') ->addAttributeToSelect('price') + ->addAttributeToSelect('color') + ->addAttributeToSelect('size') + ->addAttributeToSelect('image') // ->addAttributeToSelect('msrp') // ->addAttributeToSelect('media_gallery') ->addFilterByRequiredOptions() diff --git a/app/code/Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml b/app/code/Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml index 5f26d947a5d4f..2b3c9f148360f 100644 --- a/app/code/Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml +++ b/app/code/Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml @@ -69,7 +69,7 @@