Skip to content

Commit 1db9cef

Browse files
committed
MAGETWO-60996: [Github]Shopping cart sales rule not removed when applicable product removed from cart #7388
1 parent d8a4b22 commit 1db9cef

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
4646
$quote->getCustomerGroupId(),
4747
$quote->getCouponCode()
4848
);
49-
49+
$shippingAddress = $quote->getShippingAddress();
50+
$shippingAddress->setFreeShipping(0);
5051
/** @var \Magento\Quote\Api\Data\CartItemInterface $item */
5152
foreach ($items as $item) {
5253
if ($item->getNoDiscount()) {
@@ -71,7 +72,7 @@ public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
7172
/** Parent free shipping we apply to all children*/
7273
$this->applyToChildren($item, $itemFreeShipping);
7374
}
74-
return (bool)$quote->getShippingAddress()->getFreeShipping();
75+
return (bool)$shippingAddress->getFreeShipping();
7576
}
7677

7778
/**

app/code/Magento/OfflineShipping/Test/Unit/Model/Quote/Address/FreeShippingTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\OfflineShipping\Test\Unit\Model\Quote\Address;
88

9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
911
class FreeShippingTest extends \PHPUnit_Framework_TestCase
1012
{
1113
/**
@@ -51,6 +53,7 @@ public function testIsFreeShipping()
5153
$storeId = 100;
5254
$websiteId = 200;
5355
$customerGroupId = 300;
56+
$objectManagerMock = new ObjectManagerHelper($this);
5457
$quoteMock = $this->getMock(
5558
\Magento\Quote\Model\Quote::class,
5659
['getShippingAddress', 'getStoreId', 'getCustomerGroupId', 'getCouponCode'],
@@ -92,18 +95,9 @@ public function testIsFreeShipping()
9295
$this->calculatorMock->expects($this->exactly(2))->method('processFreeShipping')->willReturnSelf();
9396
$itemMock->expects($this->once())->method('getFreeShipping')->willReturn(true);
9497

95-
$addressMock = $this->getMock(
96-
\Magento\Quote\Model\Quote\Address::class,
97-
['getFreeShipping', 'setFreeShipping'],
98-
[],
99-
'',
100-
false
101-
);
102-
$itemMock->expects($this->exactly(2))->method('getAddress')->willReturn($addressMock);
103-
$addressMock->expects($this->at(1))->method('getFreeShipping')->willReturn(false);
104-
$addressMock->expects($this->at(2))->method('getFreeShipping')->willReturn(true);
105-
$addressMock->expects($this->once())->method('setFreeShipping')->with(true)->willReturnSelf();
98+
$addressMock = $objectManagerMock->getObject(\Magento\Quote\Model\Quote\Address::class);
10699
$quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($addressMock);
100+
$itemMock->expects($this->exactly(2))->method('getAddress')->willReturn($addressMock);
107101

108102
$itemMock->expects($this->once())->method('getHasChildren')->willReturn(true);
109103
$itemMock->expects($this->once())->method('isChildrenCalculated')->willReturn(true);

0 commit comments

Comments
 (0)