diff --git a/composer.json b/composer.json index d18618c..91799ec 100755 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/etc/config.xml b/etc/config.xml index 1da38ad..dc5a394 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -8,7 +8,7 @@ - v1.17.0 + v1.17.1 0 0 0 diff --git a/view/frontend/web/js/checkout/action/set-shipping-information-mixin.js b/view/frontend/web/js/checkout/action/set-shipping-information-mixin.js index 94c7b95..53ce257 100755 --- a/view/frontend/web/js/checkout/action/set-shipping-information-mixin.js +++ b/view/frontend/web/js/checkout/action/set-shipping-information-mixin.js @@ -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); + }) + }); } -); +}); diff --git a/view/frontend/web/js/checkout/view/shipping-mixin.js b/view/frontend/web/js/checkout/view/shipping-mixin.js index 68163f0..d4a24ae 100755 --- a/view/frontend/web/js/checkout/view/shipping-mixin.js +++ b/view/frontend/web/js/checkout/view/shipping-mixin.js @@ -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 {*} diff --git a/view/frontend/web/js/checkout/view/widget-config.js b/view/frontend/web/js/checkout/view/widget-config.js index 0debfb7..bcdc1bf 100755 --- a/view/frontend/web/js/checkout/view/widget-config.js +++ b/view/frontend/web/js/checkout/view/widget-config.js @@ -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]); } } } diff --git a/view/frontend/web/js/view/shipping-information-ext.js b/view/frontend/web/js/view/shipping-information-ext.js index ad8370a..bd03175 100755 --- a/view/frontend/web/js/view/shipping-information-ext.js +++ b/view/frontend/web/js/view/shipping-information-ext.js @@ -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']; diff --git a/view/frontend/web/template/shipping-address/form.html b/view/frontend/web/template/shipping-address/form.html deleted file mode 100755 index 4d5300a..0000000 --- a/view/frontend/web/template/shipping-address/form.html +++ /dev/null @@ -1,24 +0,0 @@ - -
- - - -
- - - - -
- - -
- -
-