Last updated

addEnrollmentPack()

Adds an enrollment pack to the cart, optionally with bundle selections for products in the pack that are dynamic bundles.

Signature

await window.FairShareSDK.addEnrollmentPack(enrollmentPackId, options);

Parameters

ParameterTypeRequiredDescription
enrollmentPackIdnumberYesThe enrollment pack ID
options.eventEventTypeNoCustom event type to dispatch (default: ADD_TO_CART)
options.bundleSelectionsBundleSelection[]NoBundle selections for dynamic bundle products in the pack

BundleSelection Object:

PropertyTypeRequiredDescription
variant_idnumberYesVariant ID of the enrollment pack product to attach bundle selections to
bundled_itemsBundledItem[]NoBundle group item selections for this product

BundledItem Object:

PropertyTypeRequiredDescription
variant_idnumberYesVariant ID of the bundled item
quantitynumberYesQuantity of the bundled item (min: 0)
display_to_customerbooleanNoWhether to display bundled item to customer
subscriptionbooleanNoWhether bundled item is a subscription
subscription_plan_idnumber | nullNoSubscription plan ID for the bundled item

Returns

Promise<Cart | undefined>

Examples

Simple Enrollment Pack

await window.FairShareSDK.addEnrollmentPack(539);

Enrollment Pack with Bundle Selections

await window.FairShareSDK.addEnrollmentPack(539, {
  bundleSelections: [
    {
      variant_id: 278318,
      bundled_items: [
        { variant_id: 39325, quantity: 1 },
        { variant_id: 35376, quantity: 1 },
        { variant_id: 11311, quantity: 1 },
      ]
    }
  ]
});

HTML Alternative

Use data attributes without JavaScript:

<!-- Basic enrollment pack -->
<button data-fluid-add-enrollment-pack="539">
  Add Enrollment Pack
</button>

<!-- Enrollment pack with bundle selections -->
<button
  data-fluid-add-enrollment-pack="539"
  data-fluid-bundle-selections='[{"variant_id":278318,"bundled_items":[{"variant_id":39325,"quantity":1},{"variant_id":35376,"quantity":1},{"variant_id":11311,"quantity":1}]}]'
>
  Add Enrollment Pack
</button>

<!-- Open cart after adding -->
<button
  data-fluid-add-enrollment-pack="42"
  data-fluid-open-cart-after-add="true"
>
  Add Enrollment Pack and View
</button>

<!-- Combined: Enrollment Pack + Items. -->
<!-- data-fluid-add-combined="enrollment pack id + variant id 1, variant id 2" Expected: 'enrollmentPackId+variantId1,variantId2" -->
<button data-fluid-add-combined="42+123456,789012">
  Add Pack + Items
</button>

Data Attributes

AttributeTypeDescription
data-fluid-add-enrollment-packstringEnrollment pack ID
data-fluid-bundle-selectionsJSON stringArray of { variant_id, bundled_items } for enrollment pack bundles
data-fluid-open-cart-after-addstringSet to "false" to prevent cart from opening