Skip to content

Commit 7c40321

Browse files
committed
Resolve No alert when user "Apply empty Coupon Code" in create new order form (issue 24015)
1 parent 866a154 commit 7c40321

File tree

2 files changed

+23
-15
lines changed
  • app/code/Magento/Sales/view/adminhtml

2 files changed

+23
-15
lines changed

app/code/Magento/Sales/view/adminhtml/templates/order/create/coupons/form.phtml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<div class="admin__field-control">
1313
<?php if (!$block->getCouponCode()) : ?>
1414
<input type="text" class="admin__control-text" id="coupons:code" value="" name="coupon_code" />
15-
<?= $block->getButtonHtml(__('Apply'), 'order.applyCoupon($F(\'coupons:code\'))') ?>
15+
<?= $block->getButtonHtml(__('Apply'), 'order.handleOnclickCoupon($F(\'coupons:code\'))') ?>
1616
<?php endif; ?>
1717
<?php if ($block->getCouponCode()) : ?>
1818
<p class="added-coupon-code">
@@ -22,9 +22,23 @@
2222
</p>
2323
<?php endif; ?>
2424
<script>
25-
require(["Magento_Sales/order/create/form"], function() {
25+
require([
26+
"jquery",
27+
'Magento_Ui/js/modal/alert',
28+
'mage/translate',
29+
"Magento_Sales/order/create/form"
30+
], function($, alert) {
2631
order.overlay('shipping-method-overlay', <?php if ($block->getQuote()->isVirtual()) : ?>false<?php else : ?>true<?php endif; ?>);
2732
order.overlay('address-shipping-overlay', <?php if ($block->getQuote()->isVirtual()) : ?>false<?php else : ?>true<?php endif; ?>);
33+
order.handleOnclickCoupon = function (code) {
34+
if (!code) {
35+
alert({
36+
content: $.mage.__('Please enter a coupon code!')
37+
});
38+
} else {
39+
order.applyCoupon(code);
40+
}
41+
};
2842
});
2943
</script>
3044
</div>

app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ define([
445445
*/
446446
loadShippingRates: function () {
447447
var addressContainer = this.shippingAsBilling ?
448-
'billingAddressContainer' :
449-
'shippingAddressContainer',
448+
'billingAddressContainer' :
449+
'shippingAddressContainer',
450450
data = this.serializeData(this[addressContainer]).toObject();
451451

452452
data['collect_shipping_rates'] = 1;
@@ -571,17 +571,11 @@ define([
571571
},
572572

573573
applyCoupon : function(code){
574-
if (!code) {
575-
alert({
576-
content: jQuery.mage.__('Please enter a coupon code!')
577-
});
578-
} else {
579-
this.loadArea(['items', 'shipping_method', 'totals', 'billing_method'], true, {'order[coupon][code]':code, reset_shipping: 0});
580-
this.orderItemChanged = false;
581-
jQuery('html, body').animate({
582-
scrollTop: 0
583-
});
584-
}
574+
this.loadArea(['items', 'shipping_method', 'totals', 'billing_method'], true, {'order[coupon][code]':code, reset_shipping: 0});
575+
this.orderItemChanged = false;
576+
jQuery('html, body').animate({
577+
scrollTop: 0
578+
});
585579
},
586580

587581
addProduct : function(id){

0 commit comments

Comments
 (0)