Bundles
Use the Bundle methods to create your own bundle widget, while taking advantage of the Bundle engine from Recharge.
getBundleId v1.0.0 Types
Note: Only fixed-price Bundles may use this method.
This method generates an _rb_id
value.
The _rb_id
value is used in checkout orders for fixed-price Bundles. This value must be added in as the property
of the cart line item that's associated with a Bundle. Recharge will use this value to extract the selected items from
the Bundle.
There should be a single _rb_id
item per Bundle line item. If you need to add multiple Bundle line items to the
cart, you'll need to create a new _rb_id
for each of those.
- ESM
- UMD
import { getBundleId } from '@rechargeapps/storefront-client';
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
},
],
};
const rbId = await getBundleId(bundle);
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
},
],
};
const rbId = await recharge.bundle.getBundleId(bundle);
validateBundle v1.0.0 Types
This method validates that the Bundle configuration that was passed is correct.
It returns a true
boolean value in case the validation is successful. It returns a string
value with the failure reason in case the validation fails.
Note: Please avoid relying on implicit boolean coercion, as it may have strange behavior.
- Do:
if (validateBundle(bundle) === true)
- Don't:
if (validateBundle(bundle))
- ESM
- UMD
import { validateBundle } from '@rechargeapps/storefront-client';
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
},
],
};
const isValid = await validateBundle(bundle);
if (isValid === true) {
// Do on valid Bundle
}
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
},
],
};
const isValid = await recharge.bundle.validateBundle(bundle);
if (isValid === true) {
// Do on valid Bundle
}
getDynamicBundleItems v1.0.0 Types
Note: Only Dynamic Bundles may use this method.
This method turns Bundle selections into an array of objects that can be added to the Shopify Cart.
The payload required for each selection item varies depending on the checkout method used by your store.
You must send the sellingPlan
attribute along with the required
BundleSelectionAppProxy
attributes.
- ESM (Shopify Checkout)
- ESM (Recharge Checkout)
- UMD (Shopify Checkout)
- UMD (Recharge Checkout)
import { getDynamicBundleItems } from '@rechargeapps/storefront-client';
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
sellingPlan: 2761818364, // Child Product Selling Plan ID 1
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
sellingPlan: 2932335088, // Child Product Selling Plan ID 2
},
],
};
const bundleItems = getDynamicBundleItems(bundle, 'shopifyProductHandle');
import { getDynamicBundleItems } from '@rechargeapps/storefront-client';
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
shippingIntervalFrequency: 1,
shippingIntervalUnitType: 'month',
discountedVariantId: 4563120, // Recharge Variant ID
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
shippingIntervalFrequency: 1,
shippingIntervalUnitType: 'month',
discountedVariantId: 5329832, // Recharge Variant ID
},
],
};
const bundleItems = getDynamicBundleItems(bundle, 'shopifyProductHandle');
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
sellingPlan: 2761818364, // Child Product Selling Plan ID 1
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
sellingPlan: 2932335088, // Child Product Selling Plan ID 2
},
],
};
const bundleItems = recharge.bundle.getDynamicBundleItems(bundle, 'shopifyProductHandle');
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
shippingIntervalFrequency: 1,
shippingIntervalUnitType: 'month',
discountedVariantId: 4563120, // Recharge Variant ID
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
shippingIntervalFrequency: 1,
shippingIntervalUnitType: 'month',
discountedVariantId: 5329832, // Recharge Variant ID
},
],
};
const bundleItems = recharge.bundle.getDynamicBundleItems(bundle, 'shopifyProductHandle');
validateDynamicBundle v1.0.0 Types
This method checks that the received configuration is valid and belongs to a Dynamic Bundle.
To be valid, all of its selections must have the same shipping frequencies.
It returns a true
boolean value in case the validation is successful. It returns a string
value with the failure reason in case the validation fails.
Note: Please avoid relying on implicit boolean coercion, as it may have strange behavior.
- Do:
if (validateDynamicBundle(bundle) === true)
- Don't:
if (validateDynamicBundle(bundle))
- ESM
- UMD
import { validateDynamicBundle } from '@rechargeapps/storefront-client';
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
sellingPlan: 2761818364, // Child Product Selling Plan ID 1
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
sellingPlan: 2932335088, // Child Product Selling Plan ID 2
},
],
};
const isValid = validateDynamicBundle(bundle);
if (isValid === true) {
// Do on valid Bundle
}
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
sellingPlan: 2761818364, // Child Product Selling Plan ID 1
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
sellingPlan: 2932335088, // Child Product Selling Plan ID 2
},
],
};
const isValid = recharge.bundle.validateDynamicBundle(bundle);
if (isValid === true) {
// Do on valid Bundle
}
validateBundleSelection v1.22.0 Types
This method checks that the received bundle selection is valid for the bundle product
To be valid, all of its selections must accomplish bundle product rules.
- ESM
- UMD
import { validateBundleSelection } from '@rechargeapps/storefront-client';
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
sellingPlan: 2761818364, // Child Product Selling Plan ID 1
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
sellingPlan: 2932335088, // Child Product Selling Plan ID 2
},
],
};
const { valid, error } = validateBundleSelection(bundle);
if (valid) {
// Do on valid Bundle
}
const bundle = {
externalProductId: '7134322196677', // Bundle's Shopify Product ID
externalVariantId: '41291293425861', // Bundle's Shopify Variant ID
selections: [
{
collectionId: '288157827269', // Shopify Collection 1
externalProductId: '7200061391045', // Shopify Product ID 1
externalVariantId: '41510929465541', // Shopify Variant ID 1
quantity: 2,
sellingPlan: 2761818364, // Child Product Selling Plan ID 1
},
{
collectionId: '285790863557', // Shopify Collection 2
externalProductId: '7200062308549', // Shopify Product ID 2
externalVariantId: '41504991412421', // Shopify Variant ID 2
quantity: 1,
sellingPlan: 2932335088, // Child Product Selling Plan ID 2
},
],
};
const { valid, error } = recharge.bundle.validateBundleSelection(bundle);
if (valid) {
// Do on valid Bundle
}