Docs

Log in to read the version of docs relevant to your site, or use the dropdown versions

How to setup Chargebee checkout with BigCommerce store?

Scope

How to set up Chargebee Checkout with BigCommerce Store?

Summary

You can extract the zip file provided and use the sample code by following the instructions below to set up Chargebee checkout with the Bigcommerce store.

Solution

Setting basic Chargebee checkout in BigCommerce Theme

  • Download the custom theme from this link

  • Extract it and then change the site name intemplates/layout/base.html

  • Replacedata-cb-site="cb-ashik-test" to data-cb-site="example-test"

  • Zip it and upload it to BigCommerce by navigating to Storefront > Theme > Upload theme (If you have an existing theme, delete it and upload)

  • Our theme does not get updated automatically, seems like some cache. To get the latest update just edit any file and save it. Refer to Cache clearing using Edit Theme Files video instructions on how to do that.

Refer to this link for video instructions

Cache clearing using Edit Theme Files

Go to Themes > Edit theme files then leave space and Save and Apply file.

Refer to this link for video instructions.

What we've done

Assumptions

For this example, we'll be using the Cornerstone-5.1.0 theme (light) however the same thing can be done for other themes also. We just need to do these configs in their equivalent files

Configure Drop-in Script

Get the drop-in script from the Chargebee Admin console and include it intemplates/base.htmlthe file of the theme file

https://www.chargebee.com/checkout-portal-docs/drop-in-tutorial.html#implementation

The sample code will look something like this:

Create custom fields in your product

Create custom fields in your BigCommerce product that we can use to map the associated Chargebee product id.

In our example, we'll be using chargebee_plan_id (we can name it whatever we want, but make sure to make necessary changes in code also

Product details page

Add this intemplates/components/products/add-to-cart.html page. It'll check if we've chargebee_plan_id custom field for that particular product if so it'll use Chargebee checkout if not then the BigCommerce cart will kick in.

The following details are sent from the product details page.

  • plan Id

  • plan quantity (reactive)

inject 'product' product

Listing

card.html

Pass custom_fields property of product to the card from where ever it's called

Like this:

// top.html >components/products/card settings=../settings theme_settings=../theme_settings customer=../customer event="list" position=(add @index 1) custom_fields=this.custom_fields // do the same in featured.html, grid.html, related.html, carousel.html as well

top.html

Refer to this link for video instructions

Similarly, do it for

  • components/products/featured.html

  • components/products/grid.html

  • components/products/related.html

  • components/products/carousel.html

Card.html

In card.html, replace the #if add_to_cart_url block with the following sample code.

Product Catalog 1.0

#each custom_fields #if this.name '===' 'chargebee_plan_id' assignVar "chargebeePlanId" this.value Subscribe else #if add_to_cart_url lang 'products.add_to_cart' lang 'category.add_cart_announcement' /if /if /each #unless custom_fields #if add_to_cart_url lang 'products.add_to_cart' lang 'category.add_cart_announcement' /if /unless

Product Catalog 2.0

The only change here we're replacing data-cb-plan-id with data-cb-item-0

#each custom_fields #if this.name '===' 'chargebee_plan_id' assignVar "chargebeePlanId" this.value Subscribe else #if add_to_cart_url lang 'products.add_to_cart' lang 'category.add_cart_announcement' /if /if /each #unless custom_fields #if add_to_cart_url lang 'products.add_to_cart' lang 'category.add_cart_announcement' /if /unless

Refer to this link for video instructions

Applying theme

And make sure to apply the uploaded theme. Alternatively, if you're using Stencil based theme then you can use CLI to easily upload the theme and the development work locally

https://developer.bigcommerce.com/docs/storefront/stencil

Limitations

  • We do not support Multi subscription support yet hence the end user will be able to subscribe to only one product (subscription) at a time.

  • This customization is not straightforward and needs a developer to make these changes.

References

https://developer.bigcommerce.com/docs/storefront/stencil/themes/context/handlebars-reference#contains

Was this article helpful?