Skip to content

Commit 4bd7bd2

Browse files
AC-2044::Cart Price Rule with shipping method set as condition is not working Magento
1 parent 9c4ade9 commit 4bd7bd2

File tree

4 files changed

+84
-21
lines changed

4 files changed

+84
-21
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'ko',
8+
'Magento_Checkout/js/model/quote',
9+
'Magento_Checkout/js/model/resource-url-manager',
10+
'mage/storage',
11+
'Magento_Checkout/js/model/error-processor',
12+
'Magento_Checkout/js/model/full-screen-loader',
13+
'Magento_Checkout/js/action/select-billing-address'
14+
], function (
15+
ko,
16+
quote,
17+
resourceUrlManager,
18+
storage,
19+
errorProcessor,
20+
fullScreenLoader,
21+
selectBillingAddressAction
22+
) {
23+
'use strict';
24+
25+
return {
26+
/**
27+
* @return {jQuery.Deferred}
28+
*/
29+
saveShippingInformation: function () {
30+
var payload;
31+
32+
if (!quote.billingAddress() && quote.shippingAddress().canUseForBilling()) {
33+
selectBillingAddressAction(quote.shippingAddress());
34+
}
35+
36+
payload = {
37+
addressInformation: {
38+
'shipping_address': quote.shippingAddress(),
39+
'billing_address': quote.billingAddress(),
40+
'shipping_method_code': quote.shippingMethod()['method_code'],
41+
'shipping_carrier_code': quote.shippingMethod()['carrier_code']
42+
}
43+
};
44+
45+
fullScreenLoader.startLoader();
46+
47+
return storage.post(
48+
resourceUrlManager.getUrlForSetShippingInformation(quote),
49+
JSON.stringify(payload)
50+
).done(
51+
function (response) {
52+
fullScreenLoader.stopLoader();
53+
}
54+
).fail(
55+
function (response) {
56+
errorProcessor.process(response);
57+
fullScreenLoader.stopLoader();
58+
}
59+
);
60+
}
61+
};
62+
});

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ define([
201201
addressFlat = uiRegistry.get('checkoutProvider').shippingAddress;
202202
address = addressConverter.formAddressDataToQuoteAddress(addressFlat);
203203
selectShippingAddress(address);
204-
205-
if (quote.shippingMethod()) {
206-
setShippingInformationAction();
207-
}
208204
}
209205
},
210206

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-save-processor/default.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ define([
3333
* @return {jQuery.Deferred}
3434
*/
3535
saveShippingInformation: function () {
36-
var payload,
37-
email;
36+
var payload;
3837

3938
if (!quote.billingAddress() && quote.shippingAddress().canUseForBilling()) {
4039
selectBillingAddressAction(quote.shippingAddress());
@@ -50,7 +49,6 @@ define([
5049
};
5150

5251
payloadExtender(payload);
53-
5452
fullScreenLoader.startLoader();
5553

5654
return storage.post(
@@ -59,12 +57,7 @@ define([
5957
).done(
6058
function (response) {
6159
quote.setTotals(response.totals);
62-
email = quote.shippingAddress().email;
63-
64-
if (!_.isUndefined(email) && email) {
65-
paymentService.setPaymentMethods(methodConverter(response['payment_methods']));
66-
}
67-
60+
paymentService.setPaymentMethods(methodConverter(response['payment_methods']));
6861
fullScreenLoader.stopLoader();
6962
}
7063
).fail(

app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-rates.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,21 @@ define([
1111
'Magento_Catalog/js/price-utils',
1212
'Magento_Checkout/js/model/quote',
1313
'Magento_Checkout/js/action/select-shipping-method',
14-
'Magento_Checkout/js/action/set-shipping-information',
14+
'Magento_Checkout/js/model/shipping-save-processor',
15+
'Magento_Checkout/js/model/cart/shipping-save-processor/default',
1516
'Magento_Checkout/js/checkout-data'
16-
], function (ko, _, Component, shippingService, priceUtils, quote, selectShippingMethodAction, setShippingInformationAction, checkoutData) {
17+
], function (
18+
ko,
19+
_,
20+
Component,
21+
shippingService,
22+
priceUtils,
23+
quote,
24+
selectShippingMethodAction,
25+
shippingSaveProcessor,
26+
cartShippingProcessor,
27+
checkoutData
28+
) {
1729
'use strict';
1830

1931
return Component.extend({
@@ -35,9 +47,14 @@ define([
3547
*/
3648
initObservable: function () {
3749
var self = this;
38-
50+
shippingSaveProcessor.registerProcessor('cart', cartShippingProcessor);
3951
this._super();
4052

53+
this.selectedShippingMethod.subscribe(function (value) {
54+
if (quote.shippingMethod()) {
55+
shippingSaveProcessor.saveShippingInformation('cart');
56+
}
57+
});
4158
this.shippingRates.subscribe(function (rates) {
4259
self.shippingRateGroups([]);
4360
_.each(rates, function (rate) {
@@ -78,11 +95,6 @@ define([
7895
selectShippingMethod: function (methodData) {
7996
selectShippingMethodAction(methodData);
8097
checkoutData.setSelectedShippingRate(methodData['carrier_code'] + '_' + methodData['method_code']);
81-
82-
if (quote.shippingMethod()) {
83-
setShippingInformationAction();
84-
}
85-
8698
return true;
8799
}
88100
});

0 commit comments

Comments
 (0)