#Checkout not Refreshing when addtoCheckout or updatecheckout called

1 messages · Page 1 of 1 (latest)

mossy veldt
#

Hi I'm using ecom addtoCheckout to add custom line items.
It's working but doesnt show until I refresh the page.

Tried with updateCheckout too and same issue.

Any reason why this may be and any way to make it refresh without requiring a page refresh?

Thanks!

feral stream
#

Hi, sorry to hear this.

Could you share any relevant code to this matter including stating what is on the frontend and backend

mossy veldt
#

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();
feral stream