Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - magento#18984: [Backport] Reload cart totals when cart data changes (by @tdgroot)
 - magento#18908: [Backport] fixed - Unable to select payment method according to country of the address at checkout time (by @rahulwebkul)


Fixed GitHub Issues:
 - magento#18907: Unable to select payment method according to country of the address at checkout time (reported by @rahulwebkul) has been fixed in magento#18908 by @rahulwebkul in 2.2-develop branch
   Related commits:
     1. f1b2360
  • Loading branch information
magento-engcom-team authored Nov 2, 2018
2 parents 20a3ebe + 3b3dba9 commit 8648f52
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,71 @@ define([
'use strict';

var rateProcessors = [],
totalsProcessors = [];
totalsProcessors = [],

quote.shippingAddress.subscribe(function () {
var type = quote.shippingAddress().getType();
/**
* Estimate totals for shipping address and update shipping rates.
*/
estimateTotalsAndUpdateRates = function () {
var type = quote.shippingAddress().getType();

if (
quote.isVirtual() ||
window.checkoutConfig.activeCarriers && window.checkoutConfig.activeCarriers.length === 0
) {
// update totals block when estimated address was set
totalsProcessors['default'] = totalsDefaultProvider;
totalsProcessors[type] ?
totalsProcessors[type].estimateTotals(quote.shippingAddress()) :
totalsProcessors['default'].estimateTotals(quote.shippingAddress());
} else {
// check if user data not changed -> load rates from cache
if (!cartCache.isChanged('address', quote.shippingAddress()) &&
!cartCache.isChanged('cartVersion', customerData.get('cart')()['data_id']) &&
cartCache.get('rates')
if (
quote.isVirtual() ||
window.checkoutConfig.activeCarriers && window.checkoutConfig.activeCarriers.length === 0
) {
shippingService.setShippingRates(cartCache.get('rates'));
// update totals block when estimated address was set
totalsProcessors['default'] = totalsDefaultProvider;
totalsProcessors[type] ?
totalsProcessors[type].estimateTotals(quote.shippingAddress()) :
totalsProcessors['default'].estimateTotals(quote.shippingAddress());
} else {
// check if user data not changed -> load rates from cache
if (!cartCache.isChanged('address', quote.shippingAddress()) &&
!cartCache.isChanged('cartVersion', customerData.get('cart')()['data_id']) &&
cartCache.get('rates')
) {
shippingService.setShippingRates(cartCache.get('rates'));

return;
return;
}

// update rates list when estimated address was set
rateProcessors['default'] = defaultProcessor;
rateProcessors[type] ?
rateProcessors[type].getRates(quote.shippingAddress()) :
rateProcessors['default'].getRates(quote.shippingAddress());

// save rates to cache after load
shippingService.getShippingRates().subscribe(function (rates) {
cartCache.set('rates', rates);
});
}
},

// update rates list when estimated address was set
rateProcessors['default'] = defaultProcessor;
rateProcessors[type] ?
rateProcessors[type].getRates(quote.shippingAddress()) :
rateProcessors['default'].getRates(quote.shippingAddress());
/**
* Estimate totals for shipping address.
*/
estimateTotalsShipping = function () {
totalsDefaultProvider.estimateTotals(quote.shippingAddress());
},

// save rates to cache after load
shippingService.getShippingRates().subscribe(function (rates) {
cartCache.set('rates', rates);
});
}
});
quote.shippingMethod.subscribe(function () {
totalsDefaultProvider.estimateTotals(quote.shippingAddress());
});
quote.billingAddress.subscribe(function () {
var type = quote.billingAddress().getType();
/**
* Estimate totals for billing address.
*/
estimateTotalsBilling = function () {
var type = quote.billingAddress().getType();

if (quote.isVirtual()) {
// update totals block when estimated address was set
totalsProcessors['default'] = totalsDefaultProvider;
totalsProcessors[type] ?
totalsProcessors[type].estimateTotals(quote.billingAddress()) :
totalsProcessors['default'].estimateTotals(quote.billingAddress());
}
};

if (quote.isVirtual()) {
// update totals block when estimated address was set
totalsProcessors['default'] = totalsDefaultProvider;
totalsProcessors[type] ?
totalsProcessors[type].estimateTotals(quote.billingAddress()) :
totalsProcessors['default'].estimateTotals(quote.billingAddress());
}
});
quote.shippingAddress.subscribe(estimateTotalsAndUpdateRates);
quote.shippingMethod.subscribe(estimateTotalsShipping);
quote.billingAddress.subscribe(estimateTotalsBilling);
customerData.get('cart').subscribe(estimateTotalsShipping);
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ define([
saveShippingInformation: function () {
var payload;

if (!quote.billingAddress()) {
selectBillingAddressAction(quote.shippingAddress());
}
/* Assign selected address every time buyer selects address*/
selectBillingAddressAction(quote.shippingAddress());

payload = {
addressInformation: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,12 @@ define([
});
expect(mocks['Magento_Checkout/js/model/cart/totals-processor/default'].estimateTotals).toHaveBeenCalled();
});

it('test subscribe when cart data was changed', function () {
mocks['Magento_Customer/js/customer-data'].get('cart')({
dataId: 2
});
expect(mocks['Magento_Checkout/js/model/cart/totals-processor/default'].estimateTotals).toHaveBeenCalled();
});
});
});

0 comments on commit 8648f52

Please sign in to comment.