Add ApplePay reactivity to product quantity

This commit is contained in:
Pedro Silva 2023-10-22 17:32:21 +01:00
parent 6930422188
commit 2eeff9a3bc
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3

View file

@ -24,9 +24,7 @@ class ApplepayButton {
); );
//PRODUCT DETAIL PAGE //PRODUCT DETAIL PAGE
if(this.context === 'product') { this.refreshContextData();
this.productQuantity = document.querySelector('input.qty').value
}
this.updated_contact_info = [] this.updated_contact_info = []
this.selectedShippingMethod = [] this.selectedShippingMethod = []
@ -198,7 +196,8 @@ class ApplepayButton {
try { try {
const formData = new FormData(document.querySelector(checkoutFormSelector)); const formData = new FormData(document.querySelector(checkoutFormSelector));
this.form_saved = Object.fromEntries(formData.entries()); this.form_saved = Object.fromEntries(formData.entries());
this.update_request_data_with_form(paymentDataRequest); // This line should be reviewed, the paypal.Applepay().confirmOrder fails if we add it.
//this.update_request_data_with_form(paymentDataRequest);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
@ -256,6 +255,14 @@ class ApplepayButton {
return paymentDataRequest return paymentDataRequest
} }
refreshContextData() {
switch (this.context) {
case 'product':
// Refresh product data that makes the price change.
this.productQuantity = document.querySelector('input.qty').value;
break;
}
}
//------------------------ //------------------------
// Payment process // Payment process
@ -375,6 +382,8 @@ class ApplepayButton {
getShippingContactData(event) { getShippingContactData(event) {
const product_id = this.buttonConfig.product.id; const product_id = this.buttonConfig.product.id;
this.refreshContextData();
switch (this.context) { switch (this.context) {
case 'product': case 'product':
return { return {
@ -402,6 +411,9 @@ class ApplepayButton {
} }
getShippingMethodData(event) { getShippingMethodData(event) {
const product_id = this.buttonConfig.product.id; const product_id = this.buttonConfig.product.id;
this.refreshContextData();
switch (this.context) { switch (this.context) {
case 'product': return { case 'product': return {
action: 'ppcp_update_shipping_method', action: 'ppcp_update_shipping_method',