mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Refactor CartHelper endpoint for edge case configurations.
This commit is contained in:
parent
2571d31ad8
commit
72e64ef922
1 changed files with 11 additions and 2 deletions
|
@ -2,10 +2,19 @@ class CartHelper {
|
|||
|
||||
constructor(cartItemKeys = [])
|
||||
{
|
||||
this.endpoint = wc_cart_fragments_params.wc_ajax_url.toString().replace('%%endpoint%%', 'remove_from_cart');
|
||||
this.cartItemKeys = cartItemKeys;
|
||||
}
|
||||
|
||||
getEndpoint() {
|
||||
let ajaxUrl = "/?wc-ajax=%%endpoint%%";
|
||||
|
||||
if ((typeof wc_cart_fragments_params !== 'undefined') && wc_cart_fragments_params.wc_ajax_url) {
|
||||
ajaxUrl = wc_cart_fragments_params.wc_ajax_url;
|
||||
}
|
||||
|
||||
return ajaxUrl.toString().replace('%%endpoint%%', 'remove_from_cart');
|
||||
}
|
||||
|
||||
addFromPurchaseUnits(purchaseUnits) {
|
||||
for (const purchaseUnit of purchaseUnits || []) {
|
||||
for (const item of purchaseUnit.items || []) {
|
||||
|
@ -46,7 +55,7 @@ class CartHelper {
|
|||
continue;
|
||||
}
|
||||
|
||||
fetch(this.endpoint, {
|
||||
fetch(this.getEndpoint(), {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
body: params
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue