Reload cart using jquery

I´m using an external application how is callen on iframe, i am adding products by url request but i need reload my cart and show how many items is on it, this after add a new.

How could I reload my cart items ?

If you are using a website with an iframe containing the VTEX IO store, executing JavaScript within the iframe is not possible due to security concerns, as explained here.

However, a potential solution could be to change the iframe’s URL, wait for 10 milliseconds, and then revert to the original URL. This would force a refresh of the iframe’s page.

If you have access to the store’s code, an alternative would be to create a messaging system using postMessage. Essentially, this is an API for communication between the page and the iframe. In the VTEX IO store code, you could listen to this channel. The larger site rendering the iframe would send a message, and upon receiving it, the VTEX IO site would perform some of the processes outlined below:

postMessage Documentation

If this isn’t applicable and you are referring to the checkout, you can use one of the methods from vtexjs to force a cart update.

function updateVtexJs() {
    if (globalThis.vtexjs === undefined) return;

If you are dealing with a VTEX IO store shelf, you can perform a GraphQL query to fetch the updated cart. Then, set the new cart value in the OrderFormContext using the setOrderForm method.

Link to the Order Manager on GitHub

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.