[FIX] website_sale: check terms and conditions
Issue:
When we activate the terms and conditions,
the button "Pay Now" is not "disabled"
at the first loading of the page.
Cause:
When we update the carriers
(via `_handleCarrierUpdateResult`),
if all conditions are good,
we activate the "Pay Now" button
(via `_setIsPayable`).
We do not take into account
the checkbox terms and conditions.
Solution:
Use payment's `_enableButton` method
to check all the conditions.
Introduced with 0967efaa24
opw-3323938
closes odoo/odoo#129437
X-original-commit: 4217b923cb2ca06710c2f5ac31c4d609390ce4fe
Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
Signed-off-by: Thomas Lefebvre (thle) <thle@odoo.com>
This commit is contained in:
@@ -29,6 +29,9 @@
|
||||
} else {
|
||||
this._setPaymentFlow(); // Initialize the payment flow to let providers overwrite it
|
||||
}
|
||||
// When a module wants to activate the button,
|
||||
// it must test its conditions and then call this bus.
|
||||
core.bus.on('enableButton', this, this._enableButton);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -148,7 +148,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({
|
||||
}
|
||||
this._updateShippingCost(result.new_amount_delivery);
|
||||
}
|
||||
this._setIsPayable(result.status);
|
||||
this._enableButton(result.status);
|
||||
let currentId = result.carrier_id
|
||||
const showLocations = document.querySelectorAll(".o_show_pickup_locations");
|
||||
|
||||
@@ -232,23 +232,35 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({
|
||||
'carrier_id': carrier_id,
|
||||
},
|
||||
})
|
||||
this._setIsPayable(result.status)
|
||||
this._enableButton(result.status);
|
||||
},
|
||||
/**
|
||||
* Check if the submit button can be enabled.
|
||||
* If it is the case, trigger the `_enableButton` from payment
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_enableButton: function(status){
|
||||
if (!this._isPayable(status)) {
|
||||
return;
|
||||
}
|
||||
core.bus.trigger('enableButton');
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {boolean} status : the status of the rate_shipment request
|
||||
* @return {boolean}
|
||||
*/
|
||||
// FYI we don't cover the case where the payement method is not selected because it already throws an error
|
||||
_setIsPayable: function(status=false){
|
||||
_isPayable: function(status=false){
|
||||
// abort if no paybutton
|
||||
var payButton = document.querySelector('button[name="o_payment_submit_button"]');
|
||||
if (!payButton) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// abort if the rating failed
|
||||
if (!status){
|
||||
payButton.disabled = true;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
const carriers = Array.from(document.querySelectorAll('.o_delivery_carrier_select'))
|
||||
let carrierChecked = null;
|
||||
@@ -259,24 +271,21 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({
|
||||
})
|
||||
//abort if no carrier is selected
|
||||
if (!carrierChecked){
|
||||
payButton.disabled = true;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// if the carrier does not need a pickup point
|
||||
const isPickUpPointNeeded = carrierChecked.querySelector('.o_show_pickup_locations')
|
||||
if (!isPickUpPointNeeded){
|
||||
payButton.disabled = false;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
const address = carrierChecked.querySelector('.o_order_location_address').innerText
|
||||
const isPickUp = carrierChecked.lastChild.previousSibling.children;
|
||||
if (isPickUp.length > 1 && (address == "" || isPickUp[0].classList.contains("d-none"))) {
|
||||
payButton.disabled = true ;
|
||||
return
|
||||
return false;
|
||||
}
|
||||
payButton.disabled = false;
|
||||
return true;
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -393,7 +402,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({
|
||||
'no_reset_access_point_address': true,
|
||||
},
|
||||
})
|
||||
this._setIsPayable(result.status)
|
||||
this._enableButton(result.status);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,7 +44,7 @@ wTourUtils.registerWebsitePreviewTour('add_to_cart_snippet_tour', {
|
||||
...wTourUtils.selectElementInWeSelectWidget('action_picker_opt', 'Buy Now'),
|
||||
...wTourUtils.clickOnSave(),
|
||||
wTourUtils.clickOnElement('add to cart button', 'iframe .s_add_to_cart_btn'),
|
||||
wTourUtils.assertPathName('/shop/payment', 'iframe button[name=o_payment_submit_button]'),
|
||||
wTourUtils.assertPathName('/shop/payment', 'iframe a.btn[href="/shop/cart"]'),
|
||||
|
||||
wsTourUtils.goToCart({quantity: 4, backend: true}),
|
||||
wsTourUtils.assertCartContains({productName: 'Acoustic Bloc Screens', backend: true}),
|
||||
|
||||
Reference in New Issue
Block a user