diff --git a/app/code/Magento/Quote/Model/Quote/Item/Processor.php b/app/code/Magento/Quote/Model/Quote/Item/Processor.php index 9c0894a785ef5b343be81f6d03b95e221bb6139e..ad17f5a8ea5be4e4571d9ae9136742a1665e09b2 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Processor.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Processor.php @@ -94,7 +94,7 @@ class Processor /** * We specify qty after we know about parent (for stock) */ - if ($request->getResetCount()) { + if ($request->getResetCount() && !$candidate->getStickWithinParent() && $item->getId() == $request->getId()) { $item->setData(CartItemInterface::KEY_QTY, 0); } $item->addQty($candidate->getCartQty()); diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php index b27d2ca465a3ed917f61c7973ae980f9619ada18..84864eab6296e38a55b1fe3cb0c56987c27d140f 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php @@ -72,7 +72,16 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase $this->itemMock = $this->getMock( 'Magento\Quote\Model\Quote\Item', - ['getId', 'setOptions', '__wakeup', 'setProduct', 'addQty', 'setCustomPrice', 'setOriginalCustomPrice'], + [ + 'getId', + 'setOptions', + '__wakeup', + 'setProduct', + 'addQty', + 'setCustomPrice', + 'setOriginalCustomPrice', + 'setData' + ], [], '', false @@ -109,7 +118,7 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase $this->productMock = $this->getMock( 'Magento\Catalog\Model\Product', - ['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty'], + ['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty', 'getStickWithinParent'], [], '', false @@ -148,8 +157,12 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue($itemId)); $this->itemMock->expects($this->any()) ->method('setData') - ->with($this->equalTo('qty'), $this->equalTo(0)); - + ->willReturnMap( + [ + ['store_id', $storeId], + ['qty', 0], + ] + ); $this->storeMock->expects($this->any()) ->method('getId') @@ -177,7 +190,6 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase ->method('getParentProductId') ->will($this->returnValue(true)); - $this->itemMock->expects($this->never())->method('setOptions'); $this->itemMock->expects($this->never())->method('setProduct'); @@ -185,7 +197,13 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase ->method('getId') ->will($this->returnValue($itemId)); - $this->itemMock->expects($this->never())->method('setData'); + $this->itemMock->expects($this->any()) + ->method('setData') + ->willReturnMap( + [ + ['store_id', $storeId], + ] + ); $this->storeMock->expects($this->any()) ->method('getId') @@ -222,7 +240,13 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase ->method('getId') ->will($this->returnValue($itemId)); - $this->itemMock->expects($this->never())->method('setData'); + $this->itemMock->expects($this->any()) + ->method('setData') + ->willReturnMap( + [ + ['store_id', $storeId], + ] + ); $this->storeMock->expects($this->any()) ->method('getId') @@ -238,58 +262,171 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase { $qty = 3000000000; $customPrice = 400000000; + $itemId = 1; + $requestItemId = 1; $this->productMock->expects($this->any()) ->method('getCartQty') ->will($this->returnValue($qty)); + $this->productMock->expects($this->any()) + ->method('getStickWithinParent') + ->will($this->returnValue(false)); - $this->itemMock->expects($this->any()) + $this->itemMock->expects($this->once()) ->method('addQty') ->with($qty); + $this->itemMock->expects($this->any()) + ->method('getId') + ->will($this->returnValue($itemId)); + $this->itemMock->expects($this->never()) + ->method('setData'); $this->objectMock->expects($this->any()) ->method('getCustomPrice') ->will($this->returnValue($customPrice)); + $this->objectMock->expects($this->any()) + ->method('getResetCount') + ->will($this->returnValue(false)); + $this->objectMock->expects($this->any()) + ->method('getId') + ->will($this->returnValue($requestItemId)); + + $this->itemMock->expects($this->once()) + ->method('setCustomPrice') + ->will($this->returnValue($customPrice)); + $this->itemMock->expects($this->once()) + ->method('setOriginalCustomPrice') + ->will($this->returnValue($customPrice)); + $this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock); + } + + public function testPrepareWithResetCountAndStick() + { + $qty = 3000000000; + $customPrice = 400000000; + $itemId = 1; + $requestItemId = 1; + + $this->productMock->expects($this->any()) + ->method('getCartQty') + ->will($this->returnValue($qty)); + $this->productMock->expects($this->any()) + ->method('getStickWithinParent') + ->will($this->returnValue(true)); + + $this->itemMock->expects($this->once()) + ->method('addQty') + ->with($qty); $this->itemMock->expects($this->any()) + ->method('getId') + ->will($this->returnValue($itemId)); + $this->itemMock->expects($this->never()) + ->method('setData'); + + $this->objectMock->expects($this->any()) + ->method('getCustomPrice') + ->will($this->returnValue($customPrice)); + $this->objectMock->expects($this->any()) + ->method('getResetCount') + ->will($this->returnValue(true)); + $this->objectMock->expects($this->any()) + ->method('getId') + ->will($this->returnValue($requestItemId)); + + $this->itemMock->expects($this->once()) ->method('setCustomPrice') ->will($this->returnValue($customPrice)); + $this->itemMock->expects($this->once()) + ->method('setOriginalCustomPrice') + ->will($this->returnValue($customPrice)); + + $this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock); + } + + public function testPrepareWithResetCountAndNotStickAndOtherItemId() + { + $qty = 3000000000; + $customPrice = 400000000; + $itemId = 1; + $requestItemId = 2; + + $this->productMock->expects($this->any()) + ->method('getCartQty') + ->will($this->returnValue($qty)); + $this->productMock->expects($this->any()) + ->method('getStickWithinParent') + ->will($this->returnValue(false)); + + $this->itemMock->expects($this->once()) + ->method('addQty') + ->with($qty); $this->itemMock->expects($this->any()) + ->method('getId') + ->will($this->returnValue($itemId)); + $this->itemMock->expects($this->never()) + ->method('setData'); + + $this->objectMock->expects($this->any()) + ->method('getCustomPrice') + ->will($this->returnValue($customPrice)); + $this->objectMock->expects($this->any()) + ->method('getResetCount') + ->will($this->returnValue(true)); + $this->objectMock->expects($this->any()) + ->method('getId') + ->will($this->returnValue($requestItemId)); + + $this->itemMock->expects($this->once()) + ->method('setCustomPrice') + ->will($this->returnValue($customPrice)); + $this->itemMock->expects($this->once()) ->method('setOriginalCustomPrice') ->will($this->returnValue($customPrice)); $this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock); } - public function testPrepareResetCount() + public function testPrepareWithResetCountAndNotStickAndSameItemId() { $qty = 3000000000; $customPrice = 400000000; + $itemId = 1; + $requestItemId = 1; $this->objectMock->expects($this->any()) ->method('getResetCount') ->will($this->returnValue(true)); $this->itemMock->expects($this->any()) + ->method('getId') + ->will($this->returnValue($itemId)); + $this->itemMock->expects($this->once()) ->method('setData') ->with(CartItemInterface::KEY_QTY, 0); $this->productMock->expects($this->any()) ->method('getCartQty') ->will($this->returnValue($qty)); + $this->productMock->expects($this->any()) + ->method('getStickWithinParent') + ->will($this->returnValue(false)); - $this->itemMock->expects($this->any()) + $this->itemMock->expects($this->once()) ->method('addQty') ->with($qty); $this->objectMock->expects($this->any()) ->method('getCustomPrice') ->will($this->returnValue($customPrice)); + $this->objectMock->expects($this->any()) + ->method('getId') + ->will($this->returnValue($requestItemId)); - $this->itemMock->expects($this->any()) + $this->itemMock->expects($this->once()) ->method('setCustomPrice') ->will($this->returnValue($customPrice)); - $this->itemMock->expects($this->any()) + $this->itemMock->expects($this->once()) ->method('setOriginalCustomPrice') ->will($this->returnValue($customPrice)); diff --git a/app/code/Magento/Reports/Model/Event/Observer.php b/app/code/Magento/Reports/Model/Event/Observer.php index cde42e07e9f5923a1752f8ad1e833f009dce37f3..560e58b337bf69b22b44f09abeae86b60357dba6 100644 --- a/app/code/Magento/Reports/Model/Event/Observer.php +++ b/app/code/Magento/Reports/Model/Event/Observer.php @@ -151,7 +151,7 @@ class Observer $productId = $observer->getEvent()->getProduct()->getId(); $viewData['product_id'] = $productId; - + $viewData['store_id'] = $this->_storeManager->getStore()->getId(); if ($this->_customerSession->isLoggedIn()) { $viewData['customer_id'] = $this->_customerSession->getCustomerId(); } else { diff --git a/app/code/Magento/Reports/Test/Unit/Model/Event/ObserverTest.php b/app/code/Magento/Reports/Test/Unit/Model/Event/ObserverTest.php index 7e53522ac6680d17587318727bf538a6bebbdd0e..f1ecde466b1d9438c59ee0f41603407504db91bd 100644 --- a/app/code/Magento/Reports/Test/Unit/Model/Event/ObserverTest.php +++ b/app/code/Magento/Reports/Test/Unit/Model/Event/ObserverTest.php @@ -85,7 +85,6 @@ class ObserverTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject $storeManager */ $storeManager = $this->getMock('Magento\Store\Model\StoreManagerInterface'); - $this->storeMock = $this->getMockBuilder('\Magento\Store\Model\Store') ->disableOriginalConstructor()->getMock(); @@ -128,7 +127,8 @@ class ObserverTest extends \PHPUnit_Framework_TestCase $storeId = 1; $expectedViewedData = [ 'product_id' => $productId, - 'customer_id' => $customerId + 'customer_id' => $customerId, + 'store_id' => $storeId, ]; $expectedEventData = [ @@ -160,7 +160,8 @@ class ObserverTest extends \PHPUnit_Framework_TestCase $storeId = 1; $expectedViewedData = [ 'product_id' => $productId, - 'visitor_id' => $visitorId + 'visitor_id' => $visitorId, + 'store_id' => $storeId, ]; $expectedEventData = [