diff --git a/app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php b/app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php index 45c03cffd89823002d8fbed52ec8937cc15312ce..cf9eed3e84d26860792c4d3751e138ad84863eb8 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 cd2fa379619497dd4d2f7da767bec996576b741b..27f3c375c91c5a70de74c3ed620838ec358144db 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);