Cart Balancing/Normalization
A Stylux bundle generally consists of the "base" product, as well as associated "upsell" products, which are used to control personalization pricing within the Stylux API. When adding a Stylux bundle to cart, it's important to add both the base product and upsell products (if they exist) with matching quantities.
This not only includes when the product is initially added to cart, but afterwards as well; e.g., if the end-consumer updates quantities or removes products from cart we need to ensure the associated upsell/base product is also updated to match. In other words, A Stylux personalized product as part of an order is only valid if both the base/upsell products have matching quantities (identified by a unique bundle ID).
Shopify SDK Automated Cart Balancing/Normalization
If you're using the Shopify plugin within the JavaScript SDK for regular/non-headless Shopify integrations, this is handled automatically for you out of the box by default.
To explicitly enable or disable this functionality you can initialize the JavaScript SDK as follows:
(async function () {
if (!self.Stylux) {
return;
}
await Stylux.setup({
apiKey: 'STLX_key-for-unsigned-requests',
merchantId: 'merchant-id',
plugins: {
shopify: {
normalizeCart: true,
},
},
});
})();Custom Cart Balancing/Normalization
For any integration where the out-of-the-box Shopify plugin can't be used (e.g., headless integrations) we'll need to implement custom normalization code that follows the aforementioned logic.
The objective in this implementation is to ensure quantities are kept in sync between the "base" product and associated "upsell" products as identified via a unique bundle ID.
A feature complete cart balancing implementation will include the following:
- When the quantity of any item is incremented or decremented (base or any associated upsell product), update the remaining products to match the changed quantity (e.g., if the base product is updated to a quantity of 3, update the other associated products to also have a quantity of 3)
- If either the base or any associated upsell product is removed, remove the remaining products referenced by the same bundle ID as well
Updated 11 days ago
