Block Client API
Block Callback FuncAddProductToCart1
Add the given product variant to the current cart.
| Kind | Block Callback |
|---|---|
| Default transport | postMessage |
| Message Data | { "bubblehouseBlockClientCall": "AddProductToCart1", ... } |
In case your store uses vendibles (products redeemed for points) or free samples (products added to orders as a free bonus), this call is used to add those products to cart for custom and headless stores.
You don't always need to implement this call. We automatically handle supported online stores that provide a first-party Cart API, a prime example being non-headless Shopify (i.e. non-Hydrogen). In those cases, do not implement this call unless the Bubblehouse team tells you to.
Input
-
instancestring requiredBlock instance identifier passed to the Blocks API.
Empty string if an instance identifier has not been provided.
-
variantIdstring requiredOnline store ID of the product variant to be added.
This is the primary identifier of what is to be added to the cart.
In case of Shopify, this is an integer and does not include the
gid://shopify/ProductVariant/prefix.In case of online shop systems without a notion of product variants, this is set to the product ID (i.e. is equal to the value of
productId). -
quantityinteger requiredThe quantity of the product to add.
-
productIdstring optionalOnline store ID of the product containing the variant.
-
optionsobject or null optionalProduct or variant options needed by the cart action.
-
discountCodestring optionalCoupon code to apply with the product.
-
ignoreIfAlreadyAddedboolean optionalSkip product insertion when the variant is already present.
Serialize overlapping calls for the same variant and check the cart again after the previous insertion finishes. Preserve each supplied coupon. Wait for pending cart work before navigating or reloading; keep errors visible if a request fails.
When discountCode is supplied, still apply that coupon and perform normal success handling and cart navigation. Without a coupon, an existing variant completes without a success message, refresh, or cart navigation.
-
successMessagestring optionalMessage to show after a successful cart action.
-
cartUrlstring or null optionalCart destination to use after success when there is no success message.
-
refreshOnAddboolean optionalReload the rewards view after showing a success message.