Block Client API

Block Callback Func

AddProductToCart1

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

  • instance string required

    Block instance identifier passed to the Blocks API.

    Empty string if an instance identifier has not been provided.

  • variantId string required

    Online 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).

  • quantity integer required

    The quantity of the product to add.

  • productId string optional

    Online store ID of the product containing the variant.

  • options object or null optional

    Product or variant options needed by the cart action.

  • discountCode string optional

    Coupon code to apply with the product.

  • ignoreIfAlreadyAdded boolean optional

    Skip the cart action when the variant is already present.

    A skipped action completes without a success message, refresh, or cart navigation.

  • successMessage string optional

    Message to show after a successful cart action.

  • cartUrl string or null optional

    Cart destination to use after success when there is no success message.

  • refreshOnAdd boolean optional

    Reload the rewards view after showing a success message.

Previous
Overview