From 1ec86b608c1b605662c7b006c8f76116369f7856 Mon Sep 17 00:00:00 2001 From: RokPopov Date: Wed, 5 Jul 2023 11:05:57 +0200 Subject: [PATCH 1/7] setup correctly updating the quote with the up-to-date shipping information --- view/frontend/web/js/applepay/button.js | 61 +++++++++++++++++++------ 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/view/frontend/web/js/applepay/button.js b/view/frontend/web/js/applepay/button.js index 8316028..00d2533 100644 --- a/view/frontend/web/js/applepay/button.js +++ b/view/frontend/web/js/applepay/button.js @@ -216,6 +216,7 @@ define([ }, amount: { value: this.isProductView + // TODO refactor this part ? formatAmount(totalsModel().getTotal() * 100) : formatAmount(getCartSubtotal() * 100), currency: currency @@ -282,20 +283,37 @@ define([ self.shippingMethod = result[i].method_code; } } + + let address = { + 'countryId': self.shippingAddress.country_id, + 'region': self.shippingAddress.region, + 'regionId': getRegionId(self.shippingAddress.country_id, self.shippingAddress.region), + 'postcode': self.shippingAddress.postcode + }; + + // Create payload to get totals let totalsPayload = { 'addressInformation': { - 'address': { - 'countryId': self.shippingAddress.country_id, - 'region': self.shippingAddress.region, - 'regionId': getRegionId(self.shippingAddress.country_id, self.shippingAddress.region), - 'postcode': self.shippingAddress.postcode - }, + 'address': address, 'shipping_method_code': self.shippingMethods[shippingMethods[0].identifier].method_code, 'shipping_carrier_code': self.shippingMethods[shippingMethods[0].identifier].carrier_code } }; + // Create payload to update quote + let shippingInformationPayload = { + 'addressInformation': { + ...totalsPayload.addressInformation, + 'shipping_address': address, + 'billing_address': address + } + }; + + delete shippingInformationPayload.addressInformation.address; + + setShippingInformation(shippingInformationPayload, this.isProductView); + setTotalsInfo(totalsPayload, this.isProductView) .done((response) => { let applePayShippingContactUpdate = {}; @@ -330,20 +348,35 @@ define([ let self = this; let shippingMethod = event.shippingMethod; - let payload = { + + let address = { + 'countryId': self.shippingAddress.country_id, + 'region': self.shippingAddress.region, + 'regionId': getRegionId(self.shippingAddress.country_id, self.shippingAddress.region), + 'postcode': self.shippingAddress.postcode + } + + let totalsPayload = { 'addressInformation': { - 'address': { - 'countryId': self.shippingAddress.country_id, - 'region': self.shippingAddress.region, - 'regionId': getRegionId(self.shippingAddress.country_id, self.shippingAddress.region), - 'postcode': self.shippingAddress.postcode - }, + 'address': address, 'shipping_method_code': self.shippingMethods[shippingMethod.identifier].method_code, 'shipping_carrier_code': self.shippingMethods[shippingMethod.identifier].carrier_code } }; - setTotalsInfo(payload, this.isProductView) + let shippingInformationPayload = { + 'addressInformation': { + ...totalsPayload.addressInformation, + 'shipping_address': address, + 'billing_address': address + } + }; + + delete shippingInformationPayload.addressInformation.address; + + setShippingInformation(shippingInformationPayload, this.isProductView); + + setTotalsInfo(totalsPayload, this.isProductView) .done((response) => { let applePayShippingMethodUpdate = {}; From d71d4f8b11971ef1a234d8be52c339357dbc1177 Mon Sep 17 00:00:00 2001 From: RokPopov Date: Fri, 7 Jul 2023 13:19:13 +0200 Subject: [PATCH 2/7] set some breakpoints to debug via gitpod --- view/frontend/web/js/applepay/button.js | 56 ++++++++++++++----------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/view/frontend/web/js/applepay/button.js b/view/frontend/web/js/applepay/button.js index 00d2533..d88e2f8 100644 --- a/view/frontend/web/js/applepay/button.js +++ b/view/frontend/web/js/applepay/button.js @@ -238,6 +238,7 @@ define([ onShippingContactSelect: function (resolve, reject, event) { let self = this; + debugger; // Get the address. let address = event.shippingContact, @@ -301,21 +302,23 @@ define([ } }; - // Create payload to update quote - let shippingInformationPayload = { - 'addressInformation': { - ...totalsPayload.addressInformation, - 'shipping_address': address, - 'billing_address': address - } - }; - - delete shippingInformationPayload.addressInformation.address; - - setShippingInformation(shippingInformationPayload, this.isProductView); - + // // Create payload to update quote + // let shippingInformationPayload = { + // 'addressInformation': { + // ...totalsPayload.addressInformation, + // 'shipping_address': address, + // 'billing_address': address + // } + // }; + // + // delete shippingInformationPayload.addressInformation.address; + // + // setShippingInformation(shippingInformationPayload, this.isProductView); + + debugger; setTotalsInfo(totalsPayload, this.isProductView) .done((response) => { + debugger; let applePayShippingContactUpdate = {}; applePayShippingContactUpdate.newShippingMethods = shippingMethods; @@ -346,6 +349,7 @@ define([ onShippingMethodSelect: function (resolve, reject, event) { let self = this; + debugger; let shippingMethod = event.shippingMethod; @@ -364,20 +368,22 @@ define([ } }; - let shippingInformationPayload = { - 'addressInformation': { - ...totalsPayload.addressInformation, - 'shipping_address': address, - 'billing_address': address - } - }; - - delete shippingInformationPayload.addressInformation.address; - - setShippingInformation(shippingInformationPayload, this.isProductView); - + // let shippingInformationPayload = { + // 'addressInformation': { + // ...totalsPayload.addressInformation, + // 'shipping_address': address, + // 'billing_address': address + // } + // }; + // + // delete shippingInformationPayload.addressInformation.address; + // + // setShippingInformation(shippingInformationPayload, this.isProductView); + + debugger; setTotalsInfo(totalsPayload, this.isProductView) .done((response) => { + debugger; let applePayShippingMethodUpdate = {}; applePayShippingMethodUpdate.newTotal = { From bfa1a75a4f073ab504db6b4622229f444728fb0d Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Mon, 17 Jul 2023 14:13:07 +0200 Subject: [PATCH 3/7] [PW-8486] Call shipping-information to set the quote and update the final amount with tax included value --- view/frontend/web/js/applepay/button.js | 68 ++++++++++++++++--------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/view/frontend/web/js/applepay/button.js b/view/frontend/web/js/applepay/button.js index d88e2f8..aba9534 100644 --- a/view/frontend/web/js/applepay/button.js +++ b/view/frontend/web/js/applepay/button.js @@ -302,18 +302,18 @@ define([ } }; - // // Create payload to update quote - // let shippingInformationPayload = { - // 'addressInformation': { - // ...totalsPayload.addressInformation, - // 'shipping_address': address, - // 'billing_address': address - // } - // }; - // - // delete shippingInformationPayload.addressInformation.address; - // - // setShippingInformation(shippingInformationPayload, this.isProductView); + // Create payload to update quote + let shippingInformationPayload = { + 'addressInformation': { + ...totalsPayload.addressInformation, + 'shipping_address': address, + 'billing_address': address + } + }; + + delete shippingInformationPayload.addressInformation.address; + + setShippingInformation(shippingInformationPayload, this.isProductView); debugger; setTotalsInfo(totalsPayload, this.isProductView) @@ -324,7 +324,7 @@ define([ applePayShippingContactUpdate.newShippingMethods = shippingMethods; applePayShippingContactUpdate.newTotal = { label: $t('Grand Total'), - amount: response.grand_total.toString() + amount: (response.grand_total + response.tax_amount).toString() }; applePayShippingContactUpdate.newLineItems = [ { @@ -338,6 +338,15 @@ define([ amount: shippingMethods[0].amount.toString() } ]; + + if (response.tax_amount > 0) { + applePayShippingContactUpdate.newLineItems.push({ + type: 'final', + label: $t('Tax'), + amount: response.tax_amount.toString() + }) + } + resolve(applePayShippingContactUpdate); // Pass shipping methods back }).fail((e) => { @@ -368,17 +377,17 @@ define([ } }; - // let shippingInformationPayload = { - // 'addressInformation': { - // ...totalsPayload.addressInformation, - // 'shipping_address': address, - // 'billing_address': address - // } - // }; - // - // delete shippingInformationPayload.addressInformation.address; - // - // setShippingInformation(shippingInformationPayload, this.isProductView); + let shippingInformationPayload = { + 'addressInformation': { + ...totalsPayload.addressInformation, + 'shipping_address': address, + 'billing_address': address + } + }; + + delete shippingInformationPayload.addressInformation.address; + + setShippingInformation(shippingInformationPayload, this.isProductView); debugger; setTotalsInfo(totalsPayload, this.isProductView) @@ -389,7 +398,7 @@ define([ applePayShippingMethodUpdate.newTotal = { type: 'final', label: $t('Grand Total'), - amount: response.grand_total.toString() + amount: (response.grand_total + response.tax_amount).toString() }; applePayShippingMethodUpdate.newLineItems = [ { @@ -403,6 +412,15 @@ define([ amount: shippingMethod.amount.toString() } ]; + + if (response.tax_amount > 0) { + applePayShippingMethodUpdate.newLineItems.push({ + type: 'final', + label: $t('Tax'), + amount: response.tax_amount.toString() + }) + } + self.shippingMethod = shippingMethod.identifier; resolve(applePayShippingMethodUpdate); }).fail((e) => { From e7566fa916ac25d272ab70e307ff7d8658127ac1 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Fri, 25 Aug 2023 12:22:23 +0200 Subject: [PATCH 4/7] Update view/frontend/web/js/applepay/button.js Co-authored-by: Peter Ojo --- view/frontend/web/js/applepay/button.js | 1 - 1 file changed, 1 deletion(-) diff --git a/view/frontend/web/js/applepay/button.js b/view/frontend/web/js/applepay/button.js index aba9534..ad477ec 100644 --- a/view/frontend/web/js/applepay/button.js +++ b/view/frontend/web/js/applepay/button.js @@ -238,7 +238,6 @@ define([ onShippingContactSelect: function (resolve, reject, event) { let self = this; - debugger; // Get the address. let address = event.shippingContact, From 715c858b8003fa64d4814030d5ac43a410b9e865 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Fri, 25 Aug 2023 12:22:28 +0200 Subject: [PATCH 5/7] Update view/frontend/web/js/applepay/button.js Co-authored-by: Peter Ojo --- view/frontend/web/js/applepay/button.js | 1 - 1 file changed, 1 deletion(-) diff --git a/view/frontend/web/js/applepay/button.js b/view/frontend/web/js/applepay/button.js index ad477ec..e9b1aaa 100644 --- a/view/frontend/web/js/applepay/button.js +++ b/view/frontend/web/js/applepay/button.js @@ -314,7 +314,6 @@ define([ setShippingInformation(shippingInformationPayload, this.isProductView); - debugger; setTotalsInfo(totalsPayload, this.isProductView) .done((response) => { debugger; From d6365d9a902726a13b45fbddf5cda05c18f68eae Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Fri, 25 Aug 2023 12:25:20 +0200 Subject: [PATCH 6/7] [PW-8486] Remove debug statements --- view/frontend/web/js/applepay/button.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/view/frontend/web/js/applepay/button.js b/view/frontend/web/js/applepay/button.js index aba9534..ee3ae45 100644 --- a/view/frontend/web/js/applepay/button.js +++ b/view/frontend/web/js/applepay/button.js @@ -216,7 +216,6 @@ define([ }, amount: { value: this.isProductView - // TODO refactor this part ? formatAmount(totalsModel().getTotal() * 100) : formatAmount(getCartSubtotal() * 100), currency: currency @@ -238,7 +237,6 @@ define([ onShippingContactSelect: function (resolve, reject, event) { let self = this; - debugger; // Get the address. let address = event.shippingContact, @@ -312,13 +310,10 @@ define([ }; delete shippingInformationPayload.addressInformation.address; - setShippingInformation(shippingInformationPayload, this.isProductView); - debugger; setTotalsInfo(totalsPayload, this.isProductView) .done((response) => { - debugger; let applePayShippingContactUpdate = {}; applePayShippingContactUpdate.newShippingMethods = shippingMethods; @@ -358,8 +353,6 @@ define([ onShippingMethodSelect: function (resolve, reject, event) { let self = this; - debugger; - let shippingMethod = event.shippingMethod; let address = { @@ -386,13 +379,10 @@ define([ }; delete shippingInformationPayload.addressInformation.address; - setShippingInformation(shippingInformationPayload, this.isProductView); - debugger; setTotalsInfo(totalsPayload, this.isProductView) .done((response) => { - debugger; let applePayShippingMethodUpdate = {}; applePayShippingMethodUpdate.newTotal = { From 437a14e3c92ced2f56dd028e515fca749ffa8f9c Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Fri, 25 Aug 2023 12:27:48 +0200 Subject: [PATCH 7/7] [PW-8486] Fix formatting --- view/frontend/web/js/applepay/button.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/view/frontend/web/js/applepay/button.js b/view/frontend/web/js/applepay/button.js index ee3ae45..111bc77 100644 --- a/view/frontend/web/js/applepay/button.js +++ b/view/frontend/web/js/applepay/button.js @@ -357,10 +357,10 @@ define([ let address = { 'countryId': self.shippingAddress.country_id, - 'region': self.shippingAddress.region, - 'regionId': getRegionId(self.shippingAddress.country_id, self.shippingAddress.region), - 'postcode': self.shippingAddress.postcode - } + 'region': self.shippingAddress.region, + 'regionId': getRegionId(self.shippingAddress.country_id, self.shippingAddress.region), + 'postcode': self.shippingAddress.postcode + }; let totalsPayload = { 'addressInformation': {