Trying to add correctly updated cart data - Shark Theme

Topic summary

A developer is implementing a custom product page using the Shark theme v1.3.3 that includes an embedded iframe for image customization and a custom add-to-cart button.

The core issue: variant data doesn’t update correctly after customers customize their image and select product variants. Current variant data only appears after a hard page refresh, preventing proper cart updates.

Desired behavior: When users select products, variants, and customize images, all data should immediately update in the cart with the drawer contents and counter reflecting changes.

The developer has already modified the cart drawer UI and cart item counter liquid files, and shared their custom add-to-cart handler code that uses postMessage events from the iframe and Shopify’s /cart/add.js API.

A community helper confirmed the default add-to-cart button works correctly and suggested creating two theme copies—one with custom code and one with default behavior—to compare differences. They offered to provide hands-on assistance with collaborator access to diagnose the variant data synchronization issue.

Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

Hi,

I’m currently trying to set up the product details page of my shop, using the Shark theme v1.3.3

I have an embedded iframe on the page that allows a customer to create a custom image, which they add to their cart as a custom attribute along with the selected product and the product variants. I’ve also set up a custom add to cart button that I’m using instead of the default add to cart provided by the theme.

My issue is that once the image has been customized via the embedded iframe app, and the customer selects their product variants, it seems that the variant data is not being updated correctly. I’m not getting the current variant data. I only get the current variant data once I’ve done a hard refresh of the page prior to selecting product variants.

Is there any way to correct this behaviour? The ideal behaviour is that once the user selects their product, variants and customizes their image, all current and correct data should be updated in the cart immediately with an update to the cart drawer contents and the counter.

In addition to this, the cart drawer ui content and the cart item counter doesn’t update right away, unless you do a hard refresh of the page after adding product to the cart.

I’ve done some code edits in the product-details.liquid file in order to get to this point, but I’m wondering what additional code I should be adding to fix the custom add to cart behaviour that I’m trying to build.

Snippet of my add to cart handler (sections/product-details.liquid)

window.addEventListener("message", async function (event) {
if (event.data.message === "add-to-cart") {
console.log("Received data from iframe:", event.data.payload);
const { variantId, quantity, customAttributes = {} } = event.data.payload;

// ? Ensure cart is fresh before adding the product
await refreshCartState();

fetch("/cart/add.js", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
items: [
{
id: variantId,
quantity: quantity,
properties: customAttributes,
},
],
}),
})
.then((response) => response.json())
.then((data) => {
console.log("Updated Shopify cart:", data);
waitForCartUpdate(data);
})
.catch((error) => console.error("Error adding to cart:", error));
}
});

Was the cart drawer like this before you added your custom code and that iframe??

So the default cart behaviour works as expected. When I use the default add to cart button, there is no issue. I’m wondering how I can work around that default behaviour to build a more custom solution.

Great on doing it this far. Definitely be looking forward to this. Will need collaborator access to your store though to see the code.

Actually it would be best if you kind of duplicate the theme once and remove all your code. So kind of make two copies on with your custom code and one with the Shopify default behaviour, it will help compare the two and see the difference.

Please reach out via personal links below for a convenient conversation and collaboration.

Best

Shadab