Skip to content

Commit c83ac71

Browse files
Merge pull request #111 from Paazl/release/1.17.1
Release/1.17.1
2 parents 368cebf + 77bcfa3 commit c83ac71

File tree

7 files changed

+115
-90
lines changed

7 files changed

+115
-90
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "paazl/magento2-checkout-widget",
33
"description": "Paazl checkoutWidget for Magento 2",
44
"type": "magento2-module",
5-
"version": "1.17.0",
5+
"version": "1.17.1",
66
"keywords": [
77
"Paazl",
88
"Magento 2",

etc/config.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<default>
99
<carriers>
1010
<paazlshipping>
11-
<version>v1.17.0</version>
11+
<version>v1.17.1</version>
1212
<active>0</active>
1313
<sallowspecific>0</sallowspecific>
1414
<price>0</price>

view/frontend/web/js/checkout/action/set-shipping-information-mixin.js

+92-57
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,99 @@
88
* Reason: after shipping option is selected,
99
* JS object of the quote still contains old "method_title"
1010
*/
11-
define(
12-
[
13-
'underscore',
14-
'Magento_Checkout/js/model/quote',
15-
'widgetConfig',
16-
'mage/utils/wrapper',
17-
'Paazl_CheckoutWidget/js/checkout/model/shipping-locations'
18-
],
19-
function (
20-
_,
21-
quote,
22-
widgetConfig,
23-
wrapper,
24-
shippingLocations
25-
) {
26-
return function (target) {
27-
return wrapper.wrap(target, function (originalAction) {
28-
var shippingMethod = quote.shippingMethod();
29-
if (shippingLocations.selectedLocationCode()
30-
&& shippingLocations.locationsList().length
31-
&& shippingMethod
32-
&& widgetConfig.prototype.getCarrierCode() === shippingMethod.carrier_code
33-
&& widgetConfig.prototype.getMethodCode() === shippingMethod.method_code) {
34-
var collectionPointInfo =_.findWhere(shippingLocations.locationsList(), {code: shippingLocations.selectedLocationCode()}),
35-
shippingAddress = quote.shippingAddress();
36-
if (collectionPointInfo && collectionPointInfo.address) {
37-
shippingAddress.countryId = collectionPointInfo.address.country;
38-
shippingAddress.city = collectionPointInfo.address.city;
39-
shippingAddress.postcode = collectionPointInfo.address.postalCode;
40-
shippingAddress.street = [
41-
collectionPointInfo.address.street,
42-
collectionPointInfo.address.streetNumber
43-
];
44-
quote.shippingAddress(shippingAddress);
45-
}
11+
define([
12+
'underscore',
13+
'Magento_Checkout/js/model/quote',
14+
'widgetConfig',
15+
'mage/utils/wrapper',
16+
'Paazl_CheckoutWidget/js/checkout/model/shipping-locations',
17+
'Magento_Customer/js/customer-data'
18+
], function (_, quote, widgetConfig, wrapper, shippingLocations, customerData) {
19+
'use strict';
20+
21+
return function (target) {
22+
return wrapper.wrap(target, function (originalAction) {
23+
let shippingMethod = quote.shippingMethod();
24+
let address = getActiveAddress();
25+
26+
if (shippingLocations.selectedLocationCode()
27+
&& shippingLocations.locationsList().length
28+
&& shippingMethod
29+
&& widgetConfig.prototype.getCarrierCode() === shippingMethod.carrier_code
30+
&& widgetConfig.prototype.getMethodCode() === shippingMethod.method_code)
31+
{
32+
var collectionPointInfo =_.findWhere(shippingLocations.locationsList(), {code: shippingLocations.selectedLocationCode()}),
33+
shippingAddress = quote.shippingAddress();
34+
35+
if (collectionPointInfo && collectionPointInfo.address) {
36+
shippingAddress.countryId = collectionPointInfo.address.country;
37+
shippingAddress.city = collectionPointInfo.address.city;
38+
shippingAddress.postcode = collectionPointInfo.address.postalCode;
39+
shippingAddress.street = [
40+
collectionPointInfo.address.street,
41+
collectionPointInfo.address.streetNumber
42+
];
43+
quote.shippingAddress(shippingAddress);
44+
}
45+
} else {
46+
quote.shippingAddress(address);
47+
}
48+
49+
// Update billing address after updating shipping address
50+
quote.billingAddress(address);
51+
52+
function getActiveAddress() {
53+
const isCustomerLogin = window.checkoutConfig.isCustomerLoggedIn;
54+
const selectedShippingAddress = customerData.get('checkout-data')().selectedShippingAddress;
55+
const shippingAddress = quote.billingAddress();
56+
let currentAddress;
57+
58+
if (isCustomerLogin) {
59+
currentAddress = selectedShippingAddress === 'new-customer-address'
60+
? customerData.get('checkout-data')().shippingAddressFromData
61+
: window.checkoutConfig.customerData.addresses[getAddressId()];
62+
} else {
63+
currentAddress = customerData.get('checkout-data')().shippingAddressFromData;
4664
}
4765

48-
return originalAction().done(function (res) {
49-
var shippingMethod = quote.shippingMethod();
50-
if (widgetConfig.prototype.getCarrierCode() !== shippingMethod.carrier_code
51-
|| widgetConfig.prototype.getMethodCode() !== shippingMethod.method_code) {
52-
return;
53-
}
54-
var methods = [];
55-
if ((typeof res.totals !== 'undefined')
56-
&& (typeof res.totals.extension_attributes !== 'undefined')) {
57-
methods = res.totals.extension_attributes || [];
58-
} else if (typeof res.extension_attributes !== 'undefined') {
59-
methods = res.extension_attributes.shipping_methods || [];
60-
}
61-
var found = _.find(methods, function (m) {
62-
return m.carrier_code === shippingMethod.carrier_code
63-
&& m.method_code === shippingMethod.method_code;
64-
});
66+
shippingAddress.countryId = currentAddress.country_id;
67+
shippingAddress.city = currentAddress.city;
68+
shippingAddress.postcode = currentAddress.postcode;
69+
shippingAddress.street = Object.values(currentAddress.street);
70+
71+
return shippingAddress;
72+
}
73+
74+
function getAddressId() {
75+
const selectedShippingAddress = customerData.get('checkout-data')().selectedShippingAddress;
76+
77+
if (selectedShippingAddress) {
78+
return selectedShippingAddress?.match(/\d+/)[0];
79+
}
80+
81+
return window.checkoutConfig.customerData.default_billing;
82+
}
83+
84+
return originalAction().done(function (res) {
85+
var shippingMethod = quote.shippingMethod();
86+
if (widgetConfig.prototype.getCarrierCode() !== shippingMethod.carrier_code
87+
|| widgetConfig.prototype.getMethodCode() !== shippingMethod.method_code) {
88+
return;
89+
}
90+
var methods = [];
91+
if ((typeof res.totals !== 'undefined')
92+
&& (typeof res.totals.extension_attributes !== 'undefined')) {
93+
methods = res.totals.extension_attributes || [];
94+
} else if (typeof res.extension_attributes !== 'undefined') {
95+
methods = res.extension_attributes.shipping_methods || [];
96+
}
97+
var found = _.find(methods, function (m) {
98+
return m.carrier_code === shippingMethod.carrier_code
99+
&& m.method_code === shippingMethod.method_code;
100+
});
65101

66-
found && quote.shippingMethod(found);
67-
})
68-
});
69-
}
102+
found && quote.shippingMethod(found);
103+
})
104+
});
70105
}
71-
);
106+
});

view/frontend/web/js/checkout/view/shipping-mixin.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ define([
3030
return target.extend({
3131
defaults: {
3232
shippingMethodListTemplate: 'Paazl_CheckoutWidget/checkout/shipping-method-list',
33-
shippingMethodItemTemplate: 'Paazl_CheckoutWidget/checkout/shipping-method-item',
34-
shippingFormTemplate: 'Paazl_CheckoutWidget/shipping-address/form',
33+
shippingMethodItemTemplate: 'Paazl_CheckoutWidget/checkout/shipping-method-item'
3534
},
3635

37-
saveInAddressBook: 0,
3836

3937
/**
4038
* @return {*}

view/frontend/web/js/checkout/view/widget-config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ define([
100100
&& (event.target.status === 200);
101101

102102
if (ready) {
103-
shippingLocations.locationsList([]);
103+
// shippingLocations.locationsList([]);
104104
var locations = JSON.parse(event.target.response);
105105
if (locations && locations.pickupLocations.length) {
106-
shippingLocations.locationsList(locations.pickupLocations);
106+
shippingLocations.locationsList([...shippingLocations.locationsList(), ...locations.pickupLocations]);
107107
}
108108
}
109109
}

view/frontend/web/js/view/shipping-information-ext.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,33 @@ define([
2929

3030
quote.totals.subscribe(() => {
3131
var shippingMethod = quote.shippingMethod(),
32+
shippingMethodTitle = '',
3233
locationName = '',
3334
title;
3435

3536
if (window.checkoutConfig.totalsData.extension_attributes[0]) {
37+
const carrier_title = shippingMethod['carrier_title'] ? `${shippingMethod['carrier_title']}` : '';
38+
const method_title = shippingMethod['method_title'] ? shippingMethod['method_title'] : '';
39+
40+
if (typeof shippingMethod['method_title'] !== 'undefined') {
41+
shippingMethodTitle = carrier_title + ' - ' + method_title;
42+
}
43+
3644
shippingMethod = window.checkoutConfig.totalsData.extension_attributes[0];
37-
this.shippingMethodTitle(shippingMethod['carrier_title'] + ' - ' + shippingMethod['method_title']);
45+
this.shippingMethodTitle(shippingMethodTitle);
3846
} else {
3947
shippingMethod = quote.shippingMethod();
4048

4149
if (!this.isStorePickup()) {
42-
return this._super();
50+
if (!shippingMethod) return '';
51+
52+
shippingMethodTitle = shippingMethod['carrier_title'];
53+
54+
if (typeof shippingMethod['method_title'] !== 'undefined') {
55+
shippingMethodTitle += ' - ' + shippingMethod['method_title'];
56+
}
57+
58+
return shippingMethodTitle;
4359
}
4460

4561
title = shippingMethod['carrier_title'] + ' - ' + shippingMethod['method_title'];

view/frontend/web/template/shipping-address/form.html

-24
This file was deleted.

0 commit comments

Comments
 (0)