From 1db9cef7462af6d39ddc5de0dd53f4c9f70cbb23 Mon Sep 17 00:00:00 2001 From: Iryna Lagno <ilagno@magento.com> Date: Wed, 23 Nov 2016 13:49:49 +0200 Subject: [PATCH] MAGETWO-60996: [Github]Shopping cart sales rule not removed when applicable product removed from cart #7388 --- .../Model/Quote/Address/FreeShipping.php | 5 +++-- .../Model/Quote/Address/FreeShippingTest.php | 16 +++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php b/app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php index 45c03cffd89..cf9eed3e84d 100644 --- a/app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php +++ b/app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php @@ -46,7 +46,8 @@ class FreeShipping implements \Magento\Quote\Model\Quote\Address\FreeShippingInt $quote->getCustomerGroupId(), $quote->getCouponCode() ); - + $shippingAddress = $quote->getShippingAddress(); + $shippingAddress->setFreeShipping(0); /** @var \Magento\Quote\Api\Data\CartItemInterface $item */ foreach ($items as $item) { if ($item->getNoDiscount()) { @@ -71,7 +72,7 @@ class FreeShipping implements \Magento\Quote\Model\Quote\Address\FreeShippingInt /** Parent free shipping we apply to all children*/ $this->applyToChildren($item, $itemFreeShipping); } - return (bool)$quote->getShippingAddress()->getFreeShipping(); + return (bool)$shippingAddress->getFreeShipping(); } /** diff --git a/app/code/Magento/OfflineShipping/Test/Unit/Model/Quote/Address/FreeShippingTest.php b/app/code/Magento/OfflineShipping/Test/Unit/Model/Quote/Address/FreeShippingTest.php index cd2fa379619..27f3c375c91 100644 --- a/app/code/Magento/OfflineShipping/Test/Unit/Model/Quote/Address/FreeShippingTest.php +++ b/app/code/Magento/OfflineShipping/Test/Unit/Model/Quote/Address/FreeShippingTest.php @@ -6,6 +6,8 @@ namespace Magento\OfflineShipping\Test\Unit\Model\Quote\Address; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; + class FreeShippingTest extends \PHPUnit_Framework_TestCase { /** @@ -51,6 +53,7 @@ class FreeShippingTest extends \PHPUnit_Framework_TestCase $storeId = 100; $websiteId = 200; $customerGroupId = 300; + $objectManagerMock = new ObjectManagerHelper($this); $quoteMock = $this->getMock( \Magento\Quote\Model\Quote::class, ['getShippingAddress', 'getStoreId', 'getCustomerGroupId', 'getCouponCode'], @@ -92,18 +95,9 @@ class FreeShippingTest extends \PHPUnit_Framework_TestCase $this->calculatorMock->expects($this->exactly(2))->method('processFreeShipping')->willReturnSelf(); $itemMock->expects($this->once())->method('getFreeShipping')->willReturn(true); - $addressMock = $this->getMock( - \Magento\Quote\Model\Quote\Address::class, - ['getFreeShipping', 'setFreeShipping'], - [], - '', - false - ); - $itemMock->expects($this->exactly(2))->method('getAddress')->willReturn($addressMock); - $addressMock->expects($this->at(1))->method('getFreeShipping')->willReturn(false); - $addressMock->expects($this->at(2))->method('getFreeShipping')->willReturn(true); - $addressMock->expects($this->once())->method('setFreeShipping')->with(true)->willReturnSelf(); + $addressMock = $objectManagerMock->getObject(\Magento\Quote\Model\Quote\Address::class); $quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($addressMock); + $itemMock->expects($this->exactly(2))->method('getAddress')->willReturn($addressMock); $itemMock->expects($this->once())->method('getHasChildren')->willReturn(true); $itemMock->expects($this->once())->method('isChildrenCalculated')->willReturn(true); -- GitLab