Skip to content

Commit d9601ec

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 4393143 commit d9601ec

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,33 @@ protected function _processActionData($action = null)
270270
if (isset($data) && isset($data['coupon']['code'])) {
271271
$couponCode = trim($data['coupon']['code']);
272272
}
273+
273274
if (!empty($couponCode)) {
274-
if ($this->_getQuote()->getCouponCode() !== $couponCode) {
275+
$isApplyDiscount = false;
276+
foreach ($this->_getQuote()->getAllItems() as $item) {
277+
if ($item->getIsApplyDiscount() === true) {
278+
$isApplyDiscount = true;
279+
break;
280+
}
281+
}
282+
if (!$isApplyDiscount) {
275283
$this->messageManager->addError(
276284
__(
277-
'"%1" coupon code is not valid.',
285+
'"%1" coupon code for item(s) selected do not apply discount',
278286
$this->_objectManager->get('Magento\Framework\Escaper')->escapeHtml($couponCode)
279287
)
280288
);
281289
} else {
282-
$this->messageManager->addSuccess(__('The coupon code has been accepted.'));
290+
if ($this->_getQuote()->getCouponCode() !== $couponCode) {
291+
$this->messageManager->addError(
292+
__(
293+
'"%1" coupon code is not valid.',
294+
$this->_objectManager->get('Magento\Framework\Escaper')->escapeHtml($couponCode)
295+
)
296+
);
297+
} else {
298+
$this->messageManager->addSuccess(__('The coupon code has been accepted.'));
299+
}
283300
}
284301
}
285302

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ 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);
9091
$item->setBaseDiscountAmount(0);
9192

9293
// ensure my children are zeroed out
@@ -119,6 +120,7 @@ public function collect(Address $address)
119120
$this->_calculator->process($item);
120121
$this->_aggregateItemDiscount($item);
121122
}
123+
$item->setIsApplyDiscount(true);
122124
}
123125

124126
/**

0 commit comments

Comments
 (0)