From c33b305ae09a639f61c4f0282fccdd0aad6306f9 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Wed, 16 Oct 2024 15:35:05 -0500 Subject: [PATCH] [ECP-9491] Handle single card payments for multishipping orders --- .../method-renderer/adyen-cc-method.js | 4 ++ .../multishipping/adyen-cc-method.js | 55 ++++++++++++++++++- .../payment/multishipping/cc-form.html | 4 +- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/adyen-cc-method.js b/view/frontend/web/js/view/payment/method-renderer/adyen-cc-method.js index 3174354d3..6986f4f42 100755 --- a/view/frontend/web/js/view/payment/method-renderer/adyen-cc-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/adyen-cc-method.js @@ -51,6 +51,7 @@ define( quote.billingAddress() != null), comboCardOption: ko.observable('credit'), checkoutComponent: null, + cardComponent: null, defaults: { template: 'Adyen_Payment/payment/cc-form', @@ -545,6 +546,9 @@ define( } return quote.totals().grand_total; }, + getPaymentMethodComponent: function () { + return this.cardComponent; + } }); } ); diff --git a/view/frontend/web/js/view/payment/method-renderer/multishipping/adyen-cc-method.js b/view/frontend/web/js/view/payment/method-renderer/multishipping/adyen-cc-method.js index 81cb89ef2..635a91aed 100644 --- a/view/frontend/web/js/view/payment/method-renderer/multishipping/adyen-cc-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/multishipping/adyen-cc-method.js @@ -12,15 +12,18 @@ define([ 'jquery', 'ko', - 'Adyen_Payment/js/view/payment/method-renderer/adyen-cc-method' + 'Adyen_Payment/js/view/payment/method-renderer/adyen-cc-method', + 'Magento_Checkout/js/model/full-screen-loader' ], function ( $, ko, - Component + Component, + fullScreenLoader ) { 'use strict'; return Component.extend({ paymentMethodReady: ko.observable(false), + isTemplateRendered: ko.observable(false), defaults: { template: 'Adyen_Payment/payment/multishipping/cc-form' }, @@ -29,6 +32,47 @@ define([ this.paymentMethodReady(paymentMethodsResponse); }, + selectPaymentMethod: function () { + fullScreenLoader.startLoader(); + let self = this; + + this.isTemplateRendered.subscribe(function (response) { + self.initializeMultishippingPaymentMethod(); + }) + if (this.isTemplateRendered()) { + this.initializeMultishippingPaymentMethod(); + } + + return true; + }, + + // This will return a promise once the payment component is created and mounted. + createMultishippingCheckoutComponent: async function () { + await this.createCheckoutComponent(); + return true; + }, + + initializeMultishippingPaymentMethod: function () { + let self = this; + + this.createMultishippingCheckoutComponent().then(function (status) { + if (status) { + let paymentComponent = self.getPaymentMethodComponent(); + + // Remove previously assigned event listeners + $("#payment-continue").off(); + // Assign event listener for component validation + $("#payment-continue").on("click", function () { + paymentComponent.showValidation(); + }); + } else { + console.warn('Payment component could not be generated!'); + } + + fullScreenLoader.stopLoader(); + }); + }, + buildComponentConfiguration: function () { let self = this; let baseComponentConfiguration = this._super(); @@ -39,7 +83,12 @@ define([ self.storeCc = !!state.data.storePaymentMethod; }; - return baseComponentConfiguration + return baseComponentConfiguration; + }, + + // Observable is set to true after div element in `cc-form.html` template is rendered + setIsTemplateRendered: function () { + this.isTemplateRendered(true); } }); }); diff --git a/view/frontend/web/template/payment/multishipping/cc-form.html b/view/frontend/web/template/payment/multishipping/cc-form.html index 40f025067..8672e2d7b 100644 --- a/view/frontend/web/template/payment/multishipping/cc-form.html +++ b/view/frontend/web/template/payment/multishipping/cc-form.html @@ -1,4 +1,6 @@
-
+