Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Shopping Cart

Allow to add products to your cart from within 8SELECT widgets

Many widgets allow a product to be added directly to the shopping cart.

Widgets that allow to add products to the cart will call the function _eightselect_shop_plugin.addToCart(). This function can then directly contain the code to add something to the shopping cart or call another function that is already implemented in the shop frontend.

// 8.SDK Web configuration for shop's cart API
<script type="text/javascript">
  window._eightselect_shop_plugin = window._eightselect_shop_plugin || {};
  window._eightselect_shop_plugin.addToCart = function (sku, quantity, Promise) {
    // the function has to return a promise
    // you can use the injected Promise or use your own polyfill
    
    // add your cart logic here
    // this is just an example - shopApi is something you actually have to implement
    return new Promise(function(resolve, reject) {
      var response = shopApi.add2cart(sku);
      if (response === "OK") {        
        return resolve("done");
      }

      return reject(new Error("add2cart failed"));
    }
  }
</script>

// 8.SDK Web
<script type="text/javascript">
    ...
</script>

The script is needed on all pages where widgets are used.

Last updated

Was this helpful?