Skip to content

Commit

Permalink
Merge pull request #111 from Paazl/release/1.17.1
Browse files Browse the repository at this point in the history
Release/1.17.1
  • Loading branch information
Marvin-Magmodules authored Aug 19, 2024
2 parents 368cebf + 77bcfa3 commit c83ac71
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 90 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "paazl/magento2-checkout-widget",
"description": "Paazl checkoutWidget for Magento 2",
"type": "magento2-module",
"version": "1.17.0",
"version": "1.17.1",
"keywords": [
"Paazl",
"Magento 2",
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<default>
<carriers>
<paazlshipping>
<version>v1.17.0</version>
<version>v1.17.1</version>
<active>0</active>
<sallowspecific>0</sallowspecific>
<price>0</price>
Expand Down
149 changes: 92 additions & 57 deletions view/frontend/web/js/checkout/action/set-shipping-information-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,99 @@
* Reason: after shipping option is selected,
* JS object of the quote still contains old "method_title"
*/
define(
[
'underscore',
'Magento_Checkout/js/model/quote',
'widgetConfig',
'mage/utils/wrapper',
'Paazl_CheckoutWidget/js/checkout/model/shipping-locations'
],
function (
_,
quote,
widgetConfig,
wrapper,
shippingLocations
) {
return function (target) {
return wrapper.wrap(target, function (originalAction) {
var shippingMethod = quote.shippingMethod();
if (shippingLocations.selectedLocationCode()
&& shippingLocations.locationsList().length
&& shippingMethod
&& widgetConfig.prototype.getCarrierCode() === shippingMethod.carrier_code
&& widgetConfig.prototype.getMethodCode() === shippingMethod.method_code) {
var collectionPointInfo =_.findWhere(shippingLocations.locationsList(), {code: shippingLocations.selectedLocationCode()}),
shippingAddress = quote.shippingAddress();
if (collectionPointInfo && collectionPointInfo.address) {
shippingAddress.countryId = collectionPointInfo.address.country;
shippingAddress.city = collectionPointInfo.address.city;
shippingAddress.postcode = collectionPointInfo.address.postalCode;
shippingAddress.street = [
collectionPointInfo.address.street,
collectionPointInfo.address.streetNumber
];
quote.shippingAddress(shippingAddress);
}
define([
'underscore',
'Magento_Checkout/js/model/quote',
'widgetConfig',
'mage/utils/wrapper',
'Paazl_CheckoutWidget/js/checkout/model/shipping-locations',
'Magento_Customer/js/customer-data'
], function (_, quote, widgetConfig, wrapper, shippingLocations, customerData) {
'use strict';

return function (target) {
return wrapper.wrap(target, function (originalAction) {
let shippingMethod = quote.shippingMethod();
let address = getActiveAddress();

if (shippingLocations.selectedLocationCode()
&& shippingLocations.locationsList().length
&& shippingMethod
&& widgetConfig.prototype.getCarrierCode() === shippingMethod.carrier_code
&& widgetConfig.prototype.getMethodCode() === shippingMethod.method_code)
{
var collectionPointInfo =_.findWhere(shippingLocations.locationsList(), {code: shippingLocations.selectedLocationCode()}),
shippingAddress = quote.shippingAddress();

if (collectionPointInfo && collectionPointInfo.address) {
shippingAddress.countryId = collectionPointInfo.address.country;
shippingAddress.city = collectionPointInfo.address.city;
shippingAddress.postcode = collectionPointInfo.address.postalCode;
shippingAddress.street = [
collectionPointInfo.address.street,
collectionPointInfo.address.streetNumber
];
quote.shippingAddress(shippingAddress);
}
} else {
quote.shippingAddress(address);
}

// Update billing address after updating shipping address
quote.billingAddress(address);

function getActiveAddress() {
const isCustomerLogin = window.checkoutConfig.isCustomerLoggedIn;
const selectedShippingAddress = customerData.get('checkout-data')().selectedShippingAddress;
const shippingAddress = quote.billingAddress();
let currentAddress;

if (isCustomerLogin) {
currentAddress = selectedShippingAddress === 'new-customer-address'
? customerData.get('checkout-data')().shippingAddressFromData
: window.checkoutConfig.customerData.addresses[getAddressId()];
} else {
currentAddress = customerData.get('checkout-data')().shippingAddressFromData;
}

return originalAction().done(function (res) {
var shippingMethod = quote.shippingMethod();
if (widgetConfig.prototype.getCarrierCode() !== shippingMethod.carrier_code
|| widgetConfig.prototype.getMethodCode() !== shippingMethod.method_code) {
return;
}
var methods = [];
if ((typeof res.totals !== 'undefined')
&& (typeof res.totals.extension_attributes !== 'undefined')) {
methods = res.totals.extension_attributes || [];
} else if (typeof res.extension_attributes !== 'undefined') {
methods = res.extension_attributes.shipping_methods || [];
}
var found = _.find(methods, function (m) {
return m.carrier_code === shippingMethod.carrier_code
&& m.method_code === shippingMethod.method_code;
});
shippingAddress.countryId = currentAddress.country_id;
shippingAddress.city = currentAddress.city;
shippingAddress.postcode = currentAddress.postcode;
shippingAddress.street = Object.values(currentAddress.street);

return shippingAddress;
}

function getAddressId() {
const selectedShippingAddress = customerData.get('checkout-data')().selectedShippingAddress;

if (selectedShippingAddress) {
return selectedShippingAddress?.match(/\d+/)[0];
}

return window.checkoutConfig.customerData.default_billing;
}

return originalAction().done(function (res) {
var shippingMethod = quote.shippingMethod();
if (widgetConfig.prototype.getCarrierCode() !== shippingMethod.carrier_code
|| widgetConfig.prototype.getMethodCode() !== shippingMethod.method_code) {
return;
}
var methods = [];
if ((typeof res.totals !== 'undefined')
&& (typeof res.totals.extension_attributes !== 'undefined')) {
methods = res.totals.extension_attributes || [];
} else if (typeof res.extension_attributes !== 'undefined') {
methods = res.extension_attributes.shipping_methods || [];
}
var found = _.find(methods, function (m) {
return m.carrier_code === shippingMethod.carrier_code
&& m.method_code === shippingMethod.method_code;
});

found && quote.shippingMethod(found);
})
});
}
found && quote.shippingMethod(found);
})
});
}
);
});
4 changes: 1 addition & 3 deletions view/frontend/web/js/checkout/view/shipping-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ define([
return target.extend({
defaults: {
shippingMethodListTemplate: 'Paazl_CheckoutWidget/checkout/shipping-method-list',
shippingMethodItemTemplate: 'Paazl_CheckoutWidget/checkout/shipping-method-item',
shippingFormTemplate: 'Paazl_CheckoutWidget/shipping-address/form',
shippingMethodItemTemplate: 'Paazl_CheckoutWidget/checkout/shipping-method-item'
},

saveInAddressBook: 0,

/**
* @return {*}
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/web/js/checkout/view/widget-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ define([
&& (event.target.status === 200);

if (ready) {
shippingLocations.locationsList([]);
// shippingLocations.locationsList([]);
var locations = JSON.parse(event.target.response);
if (locations && locations.pickupLocations.length) {
shippingLocations.locationsList(locations.pickupLocations);
shippingLocations.locationsList([...shippingLocations.locationsList(), ...locations.pickupLocations]);
}
}
}
Expand Down
20 changes: 18 additions & 2 deletions view/frontend/web/js/view/shipping-information-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,33 @@ define([

quote.totals.subscribe(() => {
var shippingMethod = quote.shippingMethod(),
shippingMethodTitle = '',
locationName = '',
title;

if (window.checkoutConfig.totalsData.extension_attributes[0]) {
const carrier_title = shippingMethod['carrier_title'] ? `${shippingMethod['carrier_title']}` : '';
const method_title = shippingMethod['method_title'] ? shippingMethod['method_title'] : '';

if (typeof shippingMethod['method_title'] !== 'undefined') {
shippingMethodTitle = carrier_title + ' - ' + method_title;
}

shippingMethod = window.checkoutConfig.totalsData.extension_attributes[0];
this.shippingMethodTitle(shippingMethod['carrier_title'] + ' - ' + shippingMethod['method_title']);
this.shippingMethodTitle(shippingMethodTitle);
} else {
shippingMethod = quote.shippingMethod();

if (!this.isStorePickup()) {
return this._super();
if (!shippingMethod) return '';

shippingMethodTitle = shippingMethod['carrier_title'];

if (typeof shippingMethod['method_title'] !== 'undefined') {
shippingMethodTitle += ' - ' + shippingMethod['method_title'];
}

return shippingMethodTitle;
}

title = shippingMethod['carrier_title'] + ' - ' + shippingMethod['method_title'];
Expand Down
24 changes: 0 additions & 24 deletions view/frontend/web/template/shipping-address/form.html

This file was deleted.

0 comments on commit c83ac71

Please sign in to comment.