#Checkout not Refreshing when addtoCheckout or updatecheckout called
1 messages · Page 1 of 1 (latest)
Hi, sorry to hear this.
Could you share any relevant code to this matter including stating what is on the frontend and backend
Hi,
Code is below. It is adding to checkout/cart fine, issue is just doesnt show up unless refresh the page.
export const testAddCheckoutFunction = webMethod(Permissions.Anyone, async (checkoutId, opts) => {
const elevatedCheckoutFuntion = auth.elevate(checkout.addToCheckout);
try {
const checkout = await elevatedCheckoutFuntion(checkoutId, opts);
return checkout;
} catch (error) {
console.error(error)
logError(error?.stack || error?.message || error, "addCustomLineItems", `Checkout ID: ${checkoutId}`);
}
})
export async function addCustomLineItems(checkoutId, lineItems = []) {
try {
const res = await testAddCheckoutFunction(checkoutId, { customLineItems: lineItems });
return res
} catch (error) {
console.error('Failed to addCustomLineItems:', error);
console.error('Error details:', JSON.stringify(error, null, 2));
logError(error?.stack, "addCustomLineItems", `Checkout ID: ${checkoutId}`);
throw new Error(error?.stack);
}
}
frontend
const updatedCheckout = await addCustomLineItems(CHECKOUT._id, newCustomLineItems);
// Refresh checkout
CHECKOUT = await getCheckout(CHECKOUT._id);
console.log("Updated Checkout?", CHECKOUT);
// Refresh the cart after adding item
await wixEcomFrontend.refreshCart();
@mossy veldt Refer to the code example on the following doc - https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/site-plugins/supported-wix-app-pages/wix-e-commerce/wix-e-commerce-checkout-page
hope that helps 🙂
The following slots and APIs are available when building a site plugin for the Checkout Page. The following image shows slots in the checkout page, into which users can add plugins.
Works, Thank you!!