Migrating a BOGO that ran across the whole cart
How most agency-written BOGOs worked: pool every eligible unit, sort it, then peel off the discounted ones. Sort ascending and the cheapest units are free. Sort descending and they are not. The class names differ by one word.
再構築可It pooled every eligible unit in the cart, sorted them by price, and discounted a share of them.
この処理はマーチャントによって 2 通りの書き方がされており、すべてが同じ意味とは限りません。それぞれの書き方を、専用のカートと数値とともに以下に示します。
スクリプトレスキューに貼り付けて、何が再現されるか確認する
- このページの各スクリプトの横にあるボタンで Ruby をコピーします。
- Shopify 管理画面で Stackable を開き、ツール、スクリプトレスキューの順に進みます。
- そこに貼り付け、ツールが作成すると示した内容を読み、このページの設定と見比べます。
スクリプトレスキューは Pro プランの機能です。以前のスクリプトの割引額を入力し、両方の金額が最小通貨単位まで一致するまで、何も公開されません。
Bogo cross line interleaved (D17)
再構築可危険なペア D17。このファイルと対になるファイルは見た目がほぼ同じで、動作が異なります。どちらを使っているか判断する前に両方を読んでください。
class InterleavedPartitioner
def initialize(paid_item_count, discounted_item_count)
@paid_item_count = paid_item_count
@discounted_item_count = discounted_item_count
end
def partition(cart, applicable_line_items)
sorted_items = applicable_line_items.sort_by { |line_item| line_item.variant.price }.reverse
discounted_items = []
paid_items_seen = 0
discounted_items_seen = 0
sorted_items.each do |line_item|
line_item.quantity.times do
if paid_items_seen < @paid_item_count
paid_items_seen += 1
else
discounted_items_seen += 1
discounted_items.push(line_item.split(take: 1))
if discounted_items_seen == @discounted_item_count
paid_items_seen = 0
discounted_items_seen = 0
end
end
end
end
discounted_items
end
end
CAMPAIGNS = [
BogoCampaign.new(
ProductTagSelector.new("bogo"),
PercentageDiscount.new(100, "Buy 2 get 1 free"),
InterleavedPartitioner.new(2, 1)
),
]
CAMPAIGNS.each do |campaign|
campaign.run(Input.cart)
end
Output.cart = Input.cartBuy X, get Y として認識され、bxgy タイプのオファーとして再構築されます。以下はオファーが実際に保存される設定キーそのものなので、ご自身の再構築結果を項目ごとに照合できます。
| 設定項目 | 値 | 設定キー |
|---|---|---|
| Offer type | bxgy | type |
| Counting | per_group | counting |
| Recurrence | repeat | recurrence |
| Tier 1 | min qty 2 -> free item | tiers[0] |
| Buy quantity | 2 | 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 | true | bxgy.freeUnitsAreAdditional |
| Target scope | tags | target.scope |
| Target includes | bogo | target.includeIds |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Your Script limited this to a tag, vendor, or product type. We carried that filter over, so confirm it selects the products you expect.
- Your Script used Shopify's own item ordering to choose what to discount. We use the campaign's allocation order, which can pick a different item in a mixed cart.
公開デモストア Meridian Goods で作成しているため、ここに載せた価格はすべて、信じるのではなく再現して確かめられます。以下の割引額は、決済時に動くのと同じエンジンがこのカートに対して算出した金額です。
- No Meridian Goods product carries the tag bogo. Set it on Aria Wireless Earbuds in Shopify before you build the cart, and on nothing else.
| 商品 | 数量 | 単価 |
|---|---|---|
| Aria Wireless Earbuds | 3 | $79.00 |
| 小計 | $237.00 | |
| 割引 | -$79.00 | |
| 合計 | $158.00 | |
未ログイン、またはタグのない顧客としてログインしています。
公開前に、ツールは手元のカートに対して以前の Script が何をしていたかを尋ねます。カートを Aria Wireless Earbuds 3、単価 $79.00 に設定すれば、答えは一つに定まります。
割引額は $79.00 です。購入者が支払った合計は $158.00 です。
照合は通貨の最小単位まで完全一致で行われます。1 単位でもずれれば公開はできません。それがこの手順の目的です。
- drop to 1 of the same product, under what the rule needs
| 商品 | 数量 | 単価 |
|---|---|---|
| Aria Wireless Earbuds | 1 | $79.00 |
| 小計 | $79.00 | |
| 合計 | $79.00 | |
未ログイン、またはタグのない顧客としてログインしています。
Bogo cross line low to high (D17)
再構築可危険なペア D17。このファイルと対になるファイルは見た目がほぼ同じで、動作が異なります。どちらを使っているか判断する前に両方を読んでください。
class LowToHighPartitioner
def initialize(paid_item_count, discounted_item_count)
@paid_item_count = paid_item_count
@discounted_item_count = discounted_item_count
end
def partition(cart, applicable_line_items)
sorted_items = applicable_line_items.sort_by { |line_item| line_item.variant.price }
total_applicable_items = sorted_items.map(&:quantity).reduce(0, :+)
discounted_items_to_find = (total_applicable_items / (@paid_item_count + @discounted_item_count)) * @discounted_item_count
discounted_items = []
sorted_items.each do |line_item|
break if discounted_items_to_find <= 0
take = [line_item.quantity, discounted_items_to_find].min
discounted_items.push(line_item.split(take: take))
discounted_items_to_find -= take
end
discounted_items
end
end
CAMPAIGNS = [
BogoCampaign.new(
ProductTagSelector.new("bogo"),
PercentageDiscount.new(100, "Buy 2 get 1 free"),
LowToHighPartitioner.new(2, 1)
),
]
CAMPAIGNS.each do |campaign|
campaign.run(Input.cart)
end
Output.cart = Input.cartBuy X, get Y として認識され、bxgy タイプのオファーとして再構築されます。以下はオファーが実際に保存される設定キーそのものなので、ご自身の再構築結果を項目ごとに照合できます。
| 設定項目 | 値 | 設定キー |
|---|---|---|
| Offer type | bxgy | type |
| Counting | per_group | counting |
| Recurrence | repeat | recurrence |
| Tier 1 | min qty 2 -> free item | tiers[0] |
| Buy quantity | 2 | bxgy.buyQty |
| Get quantity | 1 | bxgy.getQty |
| Get selection | cheapest_eligible | bxgy.getSelection |
| Reward on the get units | 100% off | bxgy.getDiscountPct |
| Free units are additional | true | bxgy.freeUnitsAreAdditional |
| Target scope | tags | target.scope |
| Target includes | bogo | target.includeIds |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Your Script limited this to a tag, vendor, or product type. We carried that filter over, so confirm it selects the products you expect.
公開デモストア Meridian Goods で作成しているため、ここに載せた価格はすべて、信じるのではなく再現して確かめられます。以下の割引額は、決済時に動くのと同じエンジンがこのカートに対して算出した金額です。
- No Meridian Goods product carries the tag bogo. Set it on Aria Wireless Earbuds and Impact Phone Case in Shopify before you build the cart, and on nothing else.
| 商品 | 数量 | 単価 |
|---|---|---|
| Impact Phone Case | 2 | $24.00 |
| Aria Wireless Earbuds | 1 | $79.00 |
| 小計 | $127.00 | |
| 割引 | -$24.00 | |
| 合計 | $103.00 | |
未ログイン、またはタグのない顧客としてログインしています。
公開前に、ツールは手元のカートに対して以前の Script が何をしていたかを尋ねます。カートを Impact Phone Case 3、単価 $24.00 に設定すれば、答えは一つに定まります。
割引額は $24.00 です。購入者が支払った合計は $48.00 です。
照合は通貨の最小単位まで完全一致で行われます。1 単位でもずれれば公開はできません。それがこの手順の目的です。
- drop to 1 of the same product, under what the rule needs
| 商品 | 数量 | 単価 |
|---|---|---|
| Impact Phone Case | 1 | $24.00 |
| 小計 | $24.00 | |
| 合計 | $24.00 | |
未ログイン、またはタグのない顧客としてログインしています。
見た目がそっくりな 2 つのファイル
以下の各ペアは、同じ形のスクリプトを 2 通りに書いたものです。違いは 1 行か 2 行ですが、動作は異なります。どちらが手元のものか決める前に、両方を読んでください。
紛らわしいペア D17
Bogo cross line interleaved (D17)
再構築可bxgy オファーとして再現されます。
このカートでの割引: $79.00
class InterleavedPartitioner
sorted_items = applicable_line_items.sort_by { |line_item| line_item.variant.price }.reverse
paid_items_seen = 0
discounted_items_seen = 0
line_item.quantity.times do
if paid_items_seen < @paid_item_countさらに 11 行の違いが、それぞれのページにあります。
Bogo cross line low to high (D17)
再構築可bxgy オファーとして再現されます。
このカートでの割引: $24.00
class LowToHighPartitioner
sorted_items = applicable_line_items.sort_by { |line_item| line_item.variant.price }
total_applicable_items = sorted_items.map(&:quantity).reduce(0, :+)
discounted_items_to_find = (total_applicable_items / (@paid_item_count + @discounted_item_count)) * @discounted_item_count
break if discounted_items_to_find <= 0
take = [line_item.quantity, discounted_items_to_find].minさらに 3 行の違いが、それぞれのページにあります。
よくある質問
- 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 Aria Wireless Earbuds at $79.00. The engine takes $79.00 off, and checkout charges $158.00.
- What will I have to check before publishing?
- Your Script limited this to a tag, vendor, or product type. We carried that filter over, so confirm it selects the products you expect. Your Script used Shopify's own item ordering to choose what to discount. We use the campaign's allocation order, which can pick a different item in a mixed cart.
関連する Script の型
A set of paid units earns an extra unit at no charge.
The same buy-and-get offer, counted so the reward sits inside each set rather than beside it.
The discount applied to the first few units only, with the rest at full price.