Skip to content

Commit fcc7d9b

Browse files
author
Olexandr Lysenko
committed
MAGETWO-30913: Error when trying to apply coupon code in backend reorder after unchecking the discount apply checkbox
1 parent 5dde9ea commit fcc7d9b

File tree

4 files changed

+9
-22
lines changed

4 files changed

+9
-22
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ protected function _processActionData($action = null)
285285
if (!empty($couponCode)) {
286286
$isApplyDiscount = false;
287287
foreach ($this->_getQuote()->getAllItems() as $item) {
288-
if ($item->getIsApplyDiscount() === true) {
288+
if (!$item->getNoDiscount()) {
289289
$isApplyDiscount = true;
290290
break;
291291
}

app/code/Magento/SalesRule/Model/Quote/Discount.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public function collect(Address $address)
8787
foreach ($items as $item) {
8888
if ($item->getNoDiscount() || !$this->_calculator->canApplyDiscount($item)) {
8989
$item->setDiscountAmount(0);
90-
$item->setIsApplyDiscount(false);
9190
$item->setBaseDiscountAmount(0);
9291

9392
// ensure my children are zeroed out
@@ -120,7 +119,6 @@ public function collect(Address $address)
120119
$this->_calculator->process($item);
121120
$this->_aggregateItemDiscount($item);
122121
}
123-
$item->setIsApplyDiscount(true);
124122
}
125123

126124
/**

dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/ProcessDataTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ protected function setUp()
123123
}
124124

125125
/**
126-
* @param bool $isApplyDiscount
126+
* @param bool $noDiscount
127127
* @param string $couponCode
128128
* @param string $errorMessage
129129
* @param string $actualCouponCode
130130
* @dataProvider isApplyDiscountDataProvider
131131
*/
132-
public function testExecute($isApplyDiscount, $couponCode, $errorMessage, $actualCouponCode)
132+
public function testExecute($noDiscount, $couponCode, $errorMessage, $actualCouponCode)
133133
{
134134
$quote = $this->getMock(
135135
'Magento\Sales\Model\Quote',
@@ -200,11 +200,11 @@ public function testExecute($isApplyDiscount, $couponCode, $errorMessage, $actua
200200
false,
201201
true,
202202
true,
203-
['getIsApplyDiscount']
203+
['getNoDiscount']
204204
);
205205
$quote->expects($this->any())->method('getAllItems')->willReturn([$item]);
206-
$item->expects($this->any())->method('getIsApplyDiscount')->willReturn($isApplyDiscount);
207-
if ($isApplyDiscount) {
206+
$item->expects($this->any())->method('getNoDiscount')->willReturn($noDiscount);
207+
if (!$noDiscount) {
208208
$quote->expects($this->once())->method('getCouponCode')->willReturn($actualCouponCode);
209209
}
210210

@@ -227,8 +227,8 @@ public function testExecute($isApplyDiscount, $couponCode, $errorMessage, $actua
227227
public function isApplyDiscountDataProvider()
228228
{
229229
return [
230-
[false, '123', '"%1" coupon code was not applied. Do not apply discount is selected for item(s)', null],
231-
[true, '123', '"%1" coupon code is not valid.', '132'],
230+
[true, '123', '"%1" coupon code was not applied. Do not apply discount is selected for item(s)', null],
231+
[false, '123', '"%1" coupon code is not valid.', '132'],
232232
];
233233
}
234234
}

dev/tests/unit/testsuite/Magento/SalesRule/Model/Quote/DiscountTest.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,11 @@ public function testCollectItemNoDiscount()
8989
{
9090
$itemNoDiscount = $this->getMockBuilder('Magento\Sales\Model\Quote\Item')
9191
->disableOriginalConstructor()
92-
->setMethods(['getNoDiscount', 'setIsApplyDiscount', '__wakeup'])
92+
->setMethods(['getNoDiscount', '__wakeup'])
9393
->getMock();
9494
$itemNoDiscount->expects($this->once())
9595
->method('getNoDiscount')
9696
->willReturn(true);
97-
$itemNoDiscount->expects($this->once())
98-
->method('setIsApplyDiscount')
99-
->willReturn(false);
10097

10198
$this->validatorMock->expects($this->any())
10299
->method('sortItemsByPriority')
@@ -204,7 +201,6 @@ public function testCollectItemHasChildren($childItemData, $parentData, $expecte
204201
'getHasChildren',
205202
'isChildrenCalculated',
206203
'getChildren',
207-
'setIsApplyDiscount',
208204
'__wakeup',
209205
]
210206
)
@@ -218,9 +214,6 @@ public function testCollectItemHasChildren($childItemData, $parentData, $expecte
218214
$itemWithChildren->expects($this->once())
219215
->method('getHasChildren')
220216
->willReturn(true);
221-
$itemWithChildren->expects($this->once())
222-
->method('setIsApplyDiscount')
223-
->willReturn(true);
224217
$itemWithChildren->expects($this->once())
225218
->method('isChildrenCalculated')
226219
->willReturn(true);
@@ -339,17 +332,13 @@ public function testCollectItemHasNoChildren()
339332
'getHasChildren',
340333
'isChildrenCalculated',
341334
'getChildren',
342-
'setIsApplyDiscount',
343335
'__wakeup',
344336
]
345337
)
346338
->getMock();
347339
$itemWithChildren->expects($this->once())
348340
->method('getNoDiscount')
349341
->willReturn(false);
350-
$itemWithChildren->expects($this->once())
351-
->method('setIsApplyDiscount')
352-
->willReturn(true);
353342
$itemWithChildren->expects($this->once())
354343
->method('getParentItem')
355344
->willReturn(false);

0 commit comments

Comments
 (0)