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.
ReconstruídoIt pooled every eligible unit in the cart, sorted them by price, and discounted a share of them.
Os lojistas escreveram isso de 2 formas diferentes, e nem todas significam a mesma coisa. Cada variação está abaixo com o próprio carrinho e os próprios números.
Cole no Resgate de Scripts e veja o que ele reconstrói
- Copie o Ruby no botão ao lado de qualquer Script desta página.
- No admin da Shopify, abra o Stackable, depois Ferramentas e depois Resgate de Scripts.
- Cole lá, leia o que a ferramenta diz que vai criar e compare com as configurações desta página.
O Resgate de Scripts está no plano Pro. Nada é publicado até você informar quanto o Script antigo descontava e os dois valores baterem no centavo.
Bogo cross line interleaved (D17)
ReconstruídoPar perigoso D17. Este arquivo e o parceiro dele são quase idênticos e se comportam de formas diferentes, então leia os dois antes de decidir qual é o seu.
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.cartReconhecido como Buy X, get Y e reconstruído como uma oferta do tipo bxgy. Estas são as chaves de configuração reais com as quais a oferta é salva, então você pode conferir a sua própria reconstrução campo a campo.
| Configuração | Valor | Chave de configuração |
|---|---|---|
| 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.
Montado na nossa loja de demonstração pública, Meridian Goods, para que cada preço aqui possa ser reproduzido em vez de aceito por confiança. O desconto abaixo é o que o mesmo motor que roda no checkout calcula para este carrinho exato.
- 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.
| Item | Qtd | Preço unit. |
|---|---|---|
| Aria Wireless Earbuds | 3 | $79.00 |
| Subtotal | $237.00 | |
| Desconto | -$79.00 | |
| Total | $158.00 | |
Sem login, ou logado como cliente sem tags.
Antes de publicar, a ferramenta pergunta o que o seu Script antigo fazia com um carrinho que você já tem. Defina como 3 de Aria Wireless Earbuds a $79.00 e a resposta fica fixa.
O desconto é $79.00. O total que o cliente pagou é $158.00.
A comparação é exata, até a menor unidade da sua moeda. Um centavo de diferença e a publicação continua bloqueada, que é justamente o objetivo desta etapa.
- drop to 1 of the same product, under what the rule needs
| Item | Qtd | Preço unit. |
|---|---|---|
| Aria Wireless Earbuds | 1 | $79.00 |
| Subtotal | $79.00 | |
| Total | $79.00 | |
Sem login, ou logado como cliente sem tags.
Bogo cross line low to high (D17)
ReconstruídoPar perigoso D17. Este arquivo e o parceiro dele são quase idênticos e se comportam de formas diferentes, então leia os dois antes de decidir qual é o seu.
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.cartReconhecido como Buy X, get Y e reconstruído como uma oferta do tipo bxgy. Estas são as chaves de configuração reais com as quais a oferta é salva, então você pode conferir a sua própria reconstrução campo a campo.
| Configuração | Valor | Chave de configuração |
|---|---|---|
| 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.
Montado na nossa loja de demonstração pública, Meridian Goods, para que cada preço aqui possa ser reproduzido em vez de aceito por confiança. O desconto abaixo é o que o mesmo motor que roda no checkout calcula para este carrinho exato.
- 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.
| Item | Qtd | Preço unit. |
|---|---|---|
| Impact Phone Case | 2 | $24.00 |
| Aria Wireless Earbuds | 1 | $79.00 |
| Subtotal | $127.00 | |
| Desconto | -$24.00 | |
| Total | $103.00 | |
Sem login, ou logado como cliente sem tags.
Antes de publicar, a ferramenta pergunta o que o seu Script antigo fazia com um carrinho que você já tem. Defina como 3 de Impact Phone Case a $24.00 e a resposta fica fixa.
O desconto é $24.00. O total que o cliente pagou é $48.00.
A comparação é exata, até a menor unidade da sua moeda. Um centavo de diferença e a publicação continua bloqueada, que é justamente o objetivo desta etapa.
- drop to 1 of the same product, under what the rule needs
| Item | Qtd | Preço unit. |
|---|---|---|
| Impact Phone Case | 1 | $24.00 |
| Subtotal | $24.00 | |
| Total | $24.00 | |
Sem login, ou logado como cliente sem tags.
Dois arquivos que parecem iguais
Cada dupla abaixo é a mesma forma de Script escrita de dois jeitos. Elas mudam em uma ou duas linhas e fazem coisas diferentes, então leia as duas antes de decidir qual é a sua.
Dupla perigosa D17
Bogo cross line interleaved (D17)
ReconstruídoReconstruído como oferta bxgy.
Desconto no carrinho dele: $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_countE mais 11 linhas diferentes, na página dela.
Bogo cross line low to high (D17)
ReconstruídoReconstruído como oferta bxgy.
Desconto no carrinho dele: $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].minE mais 3 linhas diferentes, na página dela.
Perguntas frequentes
- 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.
Formatos de Script relacionados
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.
Cole o seu Script e veja a reconstrução
A reconstrução é comparada com o valor que o seu Script antigo cobrava antes de você poder publicá-la.