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.
To identify a product variant that should be added to the cart we currently only have the sku available. For sku, the same value as in the product export is used.
1
// 8.SDK Web configuration for Shop's Cart API
2
<script type="text/javascript">
3
window._eightselect_shop_plugin = window._eightselect_shop_plugin || {};
4
window._eightselect_shop_plugin.addToCart = function (sku, quantity, Promise) {
5
// the function has to return a promise
6
// you can use the injected Promise or use your own polyfill
7
8
// add your cart logic here, for example
9
return new Promise(function(resolve, reject) {
10
var response = shopApi.add2cart(sku);
11
if (response === "OK") {
12
return resolve("done");
13
}
14
15
return reject(new Error("add2cart failed"));
16
}
17
}
18
</script>
19
20
// 8.SDK Web
21
<script type="text/javascript">
22
...
23
</script>
Copied!
The script is needed on all pages where widgets are used.
A Promise object is injected into the function. A polyfill is provided for older browsers. This means that this does not have to be covered by the shop.
Copy link