GuidesTheme App ExtensionsVolume Pricing Function

Quantity Price Breaks Function

This is a Shopify Function, not a theme app extension. It runs server-side at checkout and applies a product discount. The grouping here is alongside the storefront blocks so all of PromoSync’s storefront-facing extensions live in one place.

The Quantity Price Breaks Function is the server-side half of PromoSync’s volume pricing. It reads each variant’s tier-price array from the psrestful.part_price_array metafield, decides which tier the line qualifies for based on cart quantity, and applies a product discount that brings the line’s effective unit price down to that tier.

Without this Function, the Volume Pricing Theme Extension on the product page would show price tiers that the cart never actually honors. The Function is what makes the discount real.

Overview

PropertyValue
Extension typeShopify Function (product discount)
Extension name in ShopifyQuantity Price Breaks
Discount name in AdminQuantity Price Breaks (automatic discount)
Data sourcepsrestful.part_price_array metafield on each variant
Mode sourcevolume_pricing_mode shop setting (passed as Function configuration)
Activated byEnable Volume Pricing checkbox in Volume Pricing settings
Discount targetIndividual cart lines (variants), as fixed-amount per-unit reduction

How It Calculates the Discount

For each cart line:

  1. The Function reads the variant’s psrestful.part_price_array (a JSON array of { quantityMin, price } objects, with prices in cents).
  2. It determines the effective quantity based on the configured mode (see below).
  3. It picks the tier whose quantityMin is the highest value still less than or equal to the effective quantity.
  4. It computes the per-unit discount: (currentUnitPrice - tierPrice).
  5. If the discount is positive, it applies a fixed amount product discount of that size, targeting just that variant.

If the variant has no psrestful.part_price_array, or if the currently listed price is already at or below the matching tier price, the line is left alone.

Per-Variant vs Combined-by-Product

The Function reads its mode from the shop’s volume_pricing_mode setting, configured under Volume Pricing settings.

Per-variant mode (default)

Each cart line’s effective quantity is just its own line quantity. Two lines of the same product are treated as two independent purchases when deciding tiers.

Cart:
  Red Polo  × 4   →  effective qty 4  → 1+ tier  → $20/unit
  Blue Polo × 4   →  effective qty 4  → 1+ tier  → $20/unit

Combined-by-product mode

Before deciding tiers, the Function pre-computes a total quantity per parent product ID across every cart line. Each line then uses the parent product’s combined total as its effective quantity.

Cart (combined-by-product mode):
  Red Polo  × 4   ┐
  Blue Polo × 4   ├─→  combined qty 12 for the polo  → 12+ tier  → $15/unit per line
  Green Polo × 4  ┘

This is the common pattern for apparel and other products where customers mix colors and sizes of the same item but expect quantity discounts to apply across the mix.

⚠️

Screenshot needed: Checkout breakdown for combined-by-product mode showing three variant lines of the same product all getting the higher-quantity tier price. Save to /public/images/volume-pricing-combined-by-product.png.

Where the Discount Appears

When Enable Volume Pricing is on, the Function is wired up as an automatic discount in your store’s Discounts section, named Quantity Price Breaks.

⚠️

Screenshot needed: Shopify Admin Discounts page showing the active Quantity Price Breaks automatic discount row. Save to /public/images/volume-pricing-discount-in-admin.png.

At checkout, qualifying lines show the discount as a line-level price reduction.

⚠️

Screenshot needed: Checkout breakdown showing the Quantity Price Breaks discount applied to a single cart line in per-variant mode. Save to /public/images/volume-pricing-checkout-discount.png.

Activating and Deactivating

You don’t install the Function or manage the discount by hand. The lifecycle is driven entirely by the Enable Volume Pricing checkbox in Volume Pricing settings:

Action in PromoSyncWhat happens in your Shopify store
Turn Enable Volume Pricing ONPromoSync calls the Discounts API to create an automatic discount linked to the Function. The discount appears in Discounts and starts firing immediately.
Switch the ModePromoSync updates the discount’s configuration metafield in place. The same discount keeps running with the new grouping behavior.
Turn Enable Volume Pricing OFFPromoSync removes the automatic discount via the Discounts API. The Function is still deployed but no longer wired into checkout.
⚠️

Don’t edit the Quantity Price Breaks automatic discount directly in Shopify Admin. PromoSync owns it; manual edits can desync the discount from the toggle and leave it in a half-configured state. To pause discounting, untick Enable Volume Pricing in PromoSync settings.

Relationship With the Display Block

The Volume Pricing Theme Extension and this Function are two halves of the same feature:

Display blockThis Function
Where it runsBrowser, on the product pageShopify’s server, at checkout
What it doesRenders the tier-price table for the visible variantApplies the actual per-unit discount on cart lines
Reads frompsrestful.part_price_arraypsrestful.part_price_array
Required for the feature?No, optional UXYes, to actually deliver the tier price

Because both halves read the same metafield, the table the shopper sees on the product page matches the discount applied at checkout, as long as the metafield is current. After editing pricing rules, run Update Metafields on the affected products to refresh both halves together.

Why a Variant Might Not Be Discounted

ReasonWhat’s happeningWhat to do
Variant has no psrestful.part_price_arrayThe supplier didn’t publish PPC tiers and no Tier Pricing Rule matches the product.Either run Update Metafields after adding a Tier Pricing Rule, or accept the line will be sold at its listed price.
Current Shopify price is already at or below the tier priceThere’s nothing to discount; the Function only goes down, never up.This is the expected behavior.
Enable Volume Pricing is off in settingsThe discount isn’t installed; no Function is consulted at checkout.Tick the box in Volume Pricing settings.
Cart contains only one variant of a product in combined-by-product modeCombined quantity equals line quantity, so it behaves like per-variant mode.This is the expected behavior.
Variant’s tier array is malformedThe Function defensively skips any line whose tier data it can’t parse.Re-import the product or run Update Metafields to rebuild the array from current data.