Dynamic Bundle Discounts

As Shopify is depricating Scripts on June 30, 2026, this feature will not be supported anymore.

Introduction

This documentation explains the process of setting up Nosto - Dynamic Bundles for automatic discount, when a bundle is added to the cart on a Shopify store.

Setup

Nosto Dynamic Bundle template

Nosto bundle templates needs the following mandatory variables (name intact) to be configured for proper functioning:

  1. discount type - defines the type of discount offered (percent/dollar)

  2. discount value - defines the amount/percent of discount offered on products

  3. secured - Enable (true)/Disable (false) hash based authentication for bundle discounts.

  4. discount current product - Defines whether the currently displayed product in PDP to be included & discounted when an associated bundle is added to cart. This flag is useful when bundles are displayed along with product details as depicted in image below:

PDP with Dynamic Bundle

A sample bundle template variable configuration is shown below

Dynamic Bundle template variables

In the above sample configuration, all the mandatory fields are highlighted and the "ATC button text" and "subtitle" are custom variables

Variables can be added to the template using the following approach. Please note, this section only outlines the steps for adding variables and not creating the template end-to-end.

  1. Navigate to "Recommendations" > "Templates" and click "Create template" button.

  2. Select the "Variables" tab.

  3. For adding "discount type" variable, populate the name and type field as shown below and click "Add"

"discount type" field
  1. Click the icon next to the "discount type" field and make sure to add the details as given in the screenshot below

  1. For adding "discount value" variable, populate the name and type field as shown below and click "Add"

"discount value" field
  1. Click the icon next to "discount value" field and make sure to add the details as given in the screenshot below

Adding "discount value" variable
  1. For adding "secured" variable, populate the name and type field as shown below and click "Add"

"secured" field
  1. Click the icon next to "secured" field and make sure to add the details as given in the screenshot below

Adding "secured" field
  1. For adding "discount current product" variable, populate the name and type field as shown below and click "Add"

"discount current product" field
  1. Click the icon next to "discount current product" field and make sure to add the details as given in the screenshot below

Adding "discount current product" field

Nosto JavaScript API addBundleToCartWithDiscount can be used to add the selected bundle to the cart with the following parameters:

  1. Products selected in the bundle while adding to cart (items parameter)

  2. Discount (type & value) configuration (discount parameter)

  3. All the product IDs from the bundle (both selected and not selected) (bundleProducts parameter)

  4. A hash value that is provided with the template out of the box (hash parameter). This hash value will later be used in conjunction with the secret key obtained from Nosto in order to authenticate the request for bundle discount.

Expanding items parameter, it should contain the following fields:

  1. productId - Product ID of the variant selected in the bundle

  2. variantId - ID of the selected variant in the bundle

  3. quantity - An optional field indicating product quantity offered in bundle. Defaults to 1. For bundles with only one quantity, this field can be omitted

(a) An example where all the products from a bundle are added to cart.

in the above example, the configured discount value applies to all the products in the bundle.

Assume for example,

Product ID
Variant ID
Price

123456789

4123456098

126$

987654321

4897122347

100$

discount type - percent discount value - 10

the final price customer pays: (126 * 3 * 0.1) + (100 * 1 * 0.1) => 340.2 + 90 => 430.2

Note: Discount is applicable only when a bundle is added to the cart. Not applicable when products of a bundle are added individually.

(b) An example where NOT all the products from a bundle are added to cart.

In the above example, quantity defaults to 1 and no discount is offered and the customer pays the actual price of the selected product

Shopify Line Item script

Please follow the steps below for setting up the line item script for handling the bundle discount request.

  1. Please follow the instructions here for installing and setting up Shopify Script Editor (make sure to select blank template and clear any existing code in the template)

  2. Copy the code from here and add it to the line item script that we created in step (1). This code authenticates bundle discount requests and applies the discount only for genuine requests.

  3. Copy the Nosto bundle discount script from here and add it to the line item script, below the authentication script (added from previous step)

  4. The authentication logic has a GET_FROM_NOSTO variable. Value of this variable should be replaced with Nosto secret key. To get your secret key, please contact Nosto support

  5. Click"Save and Publish" to publish the script

Debugging Line Item Script

Nosto Bundle Script includes a commented testing section as shown below. This can be used to test the functionality of the bundle discount script. For testing, the script need to be unpublished in case if it's already published.

  • Uncomment from Input.cart.line_times till end

  • The hash value marked with (GET_FROM_DEV_CONSOLE) can be retrieved from browser's network tab after adding a bundle to cart

  • Replace "PROD_1", "PROD_2" etc., with the actual product IDs.

  • type can be percent or dollar

  • Make sure to comment the lines after testing and before publishing the script again. This is an important step. Skipping this could cause issues with applying discounts in real-time.

# ================================================================ # Testing block. Uncomment the following lines to test the script #Input.cart.line_items.each do |line_item| # new_properties = { '_nosto_bundle' => { 'discount' => { 'type' => 'percent', 'value' => 10 }, 'bundle_products' => ["PROD_1", "PROD_2"], '_hash' => 'GET_FROM_DEV_CONSOLE' } } # line_item.change_properties(new_properties, { :message => "" }) #end # ================================================================

Important Note

Nosto Dynamic Bundle configuration involves two important keys, hash and secret key. Hash key is used within the bundle template and can be accessed using predefined variable $hash. Please avoid hard-coding this value anywhere inside the template. As dynamic bundle configurations are subjected to change, the hash key will also change accordingly. Hard-coding this key may break the functionality.

Secret key, on the other hand, can be retrieved from "Dynamic Bundle Key" field in Nosto Admin Settings > Platform page. This value replaces GET_FROM_NOSTO placeholder in the Shopify line item script.

Nosto recommendation template sample

Given below is an example of a Nosto recommendation template for Dynamic Bundle discount. It's only for reference purposes and can't be used in production as it is.

Points to consider

  1. $Hash value for bundle discount is generated following a particular order of values. The order goes like this

    1. All the Product Ids returned from the Recommendation

    2. Product ID of the currently viewed product (only if discount current product is true)

    3. Value of discount type variable (percent or dollar)

    4. Value of discount value variable

  2. The ordering above should be maintained while triggering the addBundleToCartWithDiscount API call

  3. No hard coding of Product Ids. If we do, then the $Hash value verification will fail because it uses Product Ids returned from recommendation

  4. The sample below has comments highlighting these points

Dynamic Bundle recommendation template sample

Troubleshooting

Issue #1: Additional content displayed on cart page

Properties Exposed

Cause

Nosto implementation uses a private property field for sharing discount information with Shopify. In newer theme versions, Shopify automatically hides these fields while displaying products in cart page. In older version of themes, these fields gets exposed as shown below.

Solution

In such a case, make the following changes to the template liquid file that displays the cart information (usually cart.liquid or cart-template.liquid).

Issue #2: Discount is not applied

Cause

  1. Nosto provided line item script is customized (No support provided).

  2. SECRET_KEY value is incorrect.

  3. Issue with Bundle script configuration.

  4. Not all the products from a bundle are added to cart.

Solution

Contact Nosto support and share the line item script content for further analysis.

Last updated

Was this helpful?