Deal Easy volume discounts
Shows the volume discount of the Shopify app Deal Easy in the designer's bulk order module. The module then shows the order total after the discount, the discount itself and how many pieces are missing for the next tier. Deal Easy still applies the discount in the cart; the module only shows it.
The snippet below hands Deal Easy's tiers to the module through FPD.bulkOrder.discountTiers.
Setup
- Deal Easy's app embed is active in the theme, with a volume discount.
- Paste the snippet into the theme inside a
<script>tag (Custom Liquid or a theme snippet), before the FPD bundle loads. It keeps anyFPD.bulkOrdersettings the theme already has. - Open the designer on a product with a discount and set quantities in the bulk order module.
/*
* Deal Easy → FPD bulk order discount tiers.
*
* Paste into the theme (Custom Liquid or a theme snippet, inside <script>),
* before the FPD bundle loads. It hands the bulk order module the volume
* discount tiers Deal Easy grants the product, so the module can show what
* the order comes to after the discount. Deal Easy still takes the discount
* in the cart - the module only shows it.
*
* Reads `window.lbDealeasy.getSetup()`, which is not a documented Deal Easy
* API: if Deal Easy changes it, this returns no tiers and the module shows
* the order at full price.
*/
(function () {
// The more specific a discount's target, the more it is meant for this product.
var SPECIFICITY = { PRODUCTS: 3, COLLECTIONS: 2, ALL: 1 }
function isCurrent(discount, now) {
var starts = discount.startsAt ? Date.parse(discount.startsAt) : -Infinity
var ends = discount.endsAt ? Date.parse(discount.endsAt) : Infinity
return starts <= now && now < ends
}
function isExcluded(discount, product) {
return Boolean(discount.enableExclusion)
&& (discount.excludedProductIds || []).indexOf(product.id) !== -1
}
function appliesTo(discount, product) {
if (isExcluded(discount, product)) return false
switch (discount.appliesTo) {
case 'ALL':
return true
case 'PRODUCTS':
return (discount.selectedProductIds || []).indexOf(product.id) !== -1
case 'COLLECTIONS':
return (discount.selectedCollectionIds || []).some(function (id) {
return (product.collections || []).indexOf(id) !== -1
})
default:
// VARIANTS: the tiers would differ per variant, the module takes one set per product
return false
}
}
function readSetup() {
try {
return window.lbDealeasy && window.lbDealeasy.getSetup ? window.lbDealeasy.getSetup() : null
} catch (error) {
return null
}
}
function discountTiers(shopifyProduct) {
var setup = readSetup()
if (!setup || !setup.product || !Array.isArray(setup.discounts)) return null
// Deal Easy describes the page's product; a different one is not ours to price.
if (setup.product.id !== 'gid://shopify/Product/' + shopifyProduct.id) return null
var now = Date.now()
var candidates = setup.discounts.filter(function (discount) {
return discount.discountCategory === 'VOLUME_DISCOUNT'
&& discount.status === 'ACTIVE'
&& discount.customerSelectionType === 'ALL'
&& discount.type === 'PERCENTAGE'
&& isCurrent(discount, now)
&& appliesTo(discount, setup.product)
})
if (candidates.length === 0) return null
var best = candidates.reduce(function (chosen, discount) {
return SPECIFICITY[discount.appliesTo] > SPECIFICITY[chosen.appliesTo] ? discount : chosen
})
var tied = candidates.filter(function (discount) {
return SPECIFICITY[discount.appliesTo] === SPECIFICITY[best.appliesTo]
})
if (tied.length > 1) {
console.debug('[FPD] Deal Easy: ' + tied.length + ' volume discounts match this product equally - showing "' + best.title + '".')
}
return (best.tiers || []).map(function (tier) {
return { quantity: tier.quantity, type: 'percentage', value: tier.value }
})
}
window.FPD = window.FPD || {}
window.FPD.bulkOrder = window.FPD.bulkOrder || {}
window.FPD.bulkOrder.discountTiers = discountTiers
})()
Which discount it shows
The snippet reads Deal Easy's discounts from window.lbDealeasy.getSetup() and keeps only those that:
- are volume discounts (
VOLUME_DISCOUNT) that areACTIVEand running now (startsAt/endsAt), - apply to every customer (
customerSelectionType: ALL): the snippet does not know who is logged in, - are percentages (
PERCENTAGE), - target the product:
ALL,PRODUCTSorCOLLECTIONS, minusexcludedProductIdswhen exclusions are on. Discounts onVARIANTSare left out, because the module takes one set of tiers per product.
When several match, the most specific one wins: product before collection before all products. Of two equally specific ones the first is shown, and the snippet logs that with console.debug.
Limitations
- Only with Deal Easy active. With Deal Easy's app embed switched off there is no
window.lbDealeasy, and the order is shown at full price. - Undocumented source.
getSetup()is internal to Deal Easy. If an update changes it, the snippet returns no tiers and the order is shown at full price. - Late loading. Deal Easy loads its discounts after the page. Until then the order is shown at full price; the tiers appear with the next quantity change.
- Product copies. A bulk order with a design surcharge puts a copy of the product with a new product ID into the cart. A Deal Easy discount that targets products by ID does not apply to that copy, while one on all products that excludes the original does. Target such discounts by a tag the copy carries as well (the copy keeps the original's tags, and
FPD.callbacks.extraTagscan add more), otherwise the module shows a different discount than the cart. - Counting. The module counts every piece of the bulk order toward the tier. Pieces already in the cart are not counted.