Migrating a buy X get Y script on an inclusive basis
Divide by the paid units alone rather than by paid plus free, and every third unit becomes free instead of every fourth. The two files differ by three characters and by half your giveaway.
RebuiltIt gave one free unit for every group of paid units, counting the free one inside the group.
Paste it into Scripts rescue and watch what it rebuilds
- Copy the Ruby with the button beside any Script on this page.
- In your Shopify admin, open Stackable, then Tools, then Scripts rescue.
- Paste it there, read what the tool says it will build, and compare that with the settings on this page.
Scripts rescue is on the Pro plan. Nothing is published until you tell it what your old Script charged and the two figures match to the cent.
The Script
RebuiltDanger pair D3. This file and its partner look almost identical and behave differently, so read both before you decide which one you have.
BUY = 3
GET = 1
Input.cart.line_items.each do |line_item|
sets = line_item.quantity / BUY
free_count = sets * GET
next if free_count == 0
discounted = line_item.split(take: free_count)
discounted.change_line_price(Money.zero, message: "Buy 3 get 1 free")
Input.cart.line_items << discounted
end
Output.cart = Input.cartRecognised as Buy X, get Y and rebuilt as a bxgy offer. These are the real configuration keys the offer is saved with, so you can check your own rebuild against them field by field.
| Setting | Value | Config key |
|---|---|---|
| Offer type | bxgy | type |
| Counting | per_group | counting |
| Recurrence | repeat | recurrence |
| Tier 1 | min qty 3 -> free item | tiers[0] |
| Buy quantity | 3 | bxgy.buyQty |
| Get quantity | 1 | bxgy.getQty |
| Get selection | same_item | bxgy.getSelection |
| Reward on the get units | 100% off | bxgy.getDiscountPct |
| Free units are additional | false | bxgy.freeUnitsAreAdditional |
| Target scope | all | target.scope |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Confirm which products this applies to. We could not read product targeting from the script.
Built on our public demo store, Meridian Goods, so every price here can be reproduced rather than taken on trust. The discount below is what the same engine that runs at checkout computes for this exact cart.
| Item | Qty | Unit price |
|---|---|---|
| Braided USB-C Cable | 3 | $14.00 |
| Subtotal | $42.00 | |
| Discount | -$14.00 | |
| Total | $28.00 | |
Signed out, or signed in as a customer with no tags.
Before publishing, the tool asks what your old Script did to a cart you already have. Set it to 3 of Braided USB-C Cable at $14.00 and the answer is fixed.
The discount is $14.00. The total the shopper paid is $28.00.
The comparison is exact, down to the smallest unit of your currency. One cent out and publishing stays shut, which is the whole point of the step.
- drop to 1 of the same product, under what the rule needs
| Item | Qty | Unit price |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotal | $14.00 | |
| Total | $14.00 | |
Signed out, or signed in as a customer with no tags.
Two files that look the same
Each pair below is one Script shape written two ways. They differ by a line or two and they do different things, so read both before deciding which one you have.
Danger pair D3
Bogo inclusive basis (D3)
RebuiltRebuilt as a bxgy offer.
Discount on its own cart: $14.00
sets = line_item.quantity / BUYBogo same item free (D3)
RebuiltRebuilt as a bxgy offer.
Discount on its own cart: $14.00
sets = line_item.quantity / (BUY + GET)Common questions
- Will Stackable rebuild this script?
- Yes. Every spelling on this page is rebuilt today as a bxgy offer, and the cart above is the one that proves it.
- What cart proves it works?
- 3 x Braided USB-C Cable at $14.00. The engine takes $14.00 off, and checkout charges $28.00.
- What will I have to check before publishing?
- Confirm which products this applies to. We could not read product targeting from the script.
Related Script shapes
A set of paid units earns an extra unit at no charge.
The discount applied to the first few units only, with the rest at full price.
The least expensive thing in the cart discounted, once.
Paste your Script and see it rebuilt
The rebuild is checked against the money your old Script charged before you can publish it.