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.
ReconstruidoIt pooled every eligible unit in the cart, sorted them by price, and discounted a share of them.
Los comerciantes escribieron esto de 2 formas distintas, y no todas significan lo mismo. Cada variante aparece abajo con su propio carrito y sus propias cifras.
Pégalo en Rescate de scripts y mira qué reconstruye
- Copia el Ruby con el botón que hay junto a cualquier Script de esta página.
- En tu panel de Shopify, abre Stackable, luego Herramientas y luego Rescate de scripts.
- Pégalo ahí, lee lo que la herramienta dice que va a crear y compáralo con los ajustes de esta página.
Rescate de scripts está en el plan Pro. No se publica nada hasta que le digas cuánto descontaba tu Script antiguo y las dos cifras coincidan al céntimo.
Bogo cross line interleaved (D17)
ReconstruidoPar peligroso D17. Este archivo y su pareja parecen casi idénticos y se comportan de forma distinta, así que lee los dos antes de decidir cuál tienes.
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.cartReconocido como Buy X, get Y y reconstruido como una oferta de tipo bxgy. Estas son las claves de configuración reales con las que se guarda la oferta, así que puedes comparar tu propia reconstrucción campo por campo.
| Ajuste | Valor | Clave de configuración |
|---|---|---|
| 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.
Creado en nuestra tienda de demostración pública, Meridian Goods, para que cada precio de aquí se pueda reproducir en lugar de darlo por bueno. El descuento de abajo es lo que calcula para este carrito exacto el mismo motor que se ejecuta en el pago.
- 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.
| Artículo | Cant. | Precio unit. |
|---|---|---|
| Aria Wireless Earbuds | 3 | $79.00 |
| Subtotal | $237.00 | |
| Descuento | -$79.00 | |
| Total | $158.00 | |
Sin sesión iniciada, o con sesión de un cliente sin etiquetas.
Antes de publicar, la herramienta pregunta qué hacía tu Script antiguo con un carrito que ya tienes. Ponlo en 3 de Aria Wireless Earbuds a $79.00 y la respuesta queda fijada.
El descuento es $79.00. El total que pagó el comprador es $158.00.
La comparación es exacta, hasta la unidad más pequeña de tu moneda. Un céntimo de diferencia y la publicación sigue bloqueada, que es todo el sentido de este paso.
- drop to 1 of the same product, under what the rule needs
| Artículo | Cant. | Precio unit. |
|---|---|---|
| Aria Wireless Earbuds | 1 | $79.00 |
| Subtotal | $79.00 | |
| Total | $79.00 | |
Sin sesión iniciada, o con sesión de un cliente sin etiquetas.
Bogo cross line low to high (D17)
ReconstruidoPar peligroso D17. Este archivo y su pareja parecen casi idénticos y se comportan de forma distinta, así que lee los dos antes de decidir cuál tienes.
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.cartReconocido como Buy X, get Y y reconstruido como una oferta de tipo bxgy. Estas son las claves de configuración reales con las que se guarda la oferta, así que puedes comparar tu propia reconstrucción campo por campo.
| Ajuste | Valor | Clave de configuración |
|---|---|---|
| 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.
Creado en nuestra tienda de demostración pública, Meridian Goods, para que cada precio de aquí se pueda reproducir en lugar de darlo por bueno. El descuento de abajo es lo que calcula para este carrito exacto el mismo motor que se ejecuta en el pago.
- 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.
| Artículo | Cant. | Precio unit. |
|---|---|---|
| Impact Phone Case | 2 | $24.00 |
| Aria Wireless Earbuds | 1 | $79.00 |
| Subtotal | $127.00 | |
| Descuento | -$24.00 | |
| Total | $103.00 | |
Sin sesión iniciada, o con sesión de un cliente sin etiquetas.
Antes de publicar, la herramienta pregunta qué hacía tu Script antiguo con un carrito que ya tienes. Ponlo en 3 de Impact Phone Case a $24.00 y la respuesta queda fijada.
El descuento es $24.00. El total que pagó el comprador es $48.00.
La comparación es exacta, hasta la unidad más pequeña de tu moneda. Un céntimo de diferencia y la publicación sigue bloqueada, que es todo el sentido de este paso.
- drop to 1 of the same product, under what the rule needs
| Artículo | Cant. | Precio unit. |
|---|---|---|
| Impact Phone Case | 1 | $24.00 |
| Subtotal | $24.00 | |
| Total | $24.00 | |
Sin sesión iniciada, o con sesión de un cliente sin etiquetas.
Dos archivos que parecen iguales
Cada pareja de abajo es una misma forma de Script escrita de dos maneras. Se diferencian en una o dos líneas y hacen cosas distintas, así que lee las dos antes de decidir cuál tienes.
Pareja peligrosa D17
Bogo cross line interleaved (D17)
ReconstruidoSe reconstruye como una oferta bxgy.
Descuento en su propio carrito: $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_countY 11 líneas distintas más, en su propia página.
Bogo cross line low to high (D17)
ReconstruidoSe reconstruye como una oferta bxgy.
Descuento en su propio carrito: $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].minY 3 líneas distintas más, en su propia página.
Preguntas frecuentes
- 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.
Formas de Script relacionadas
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.
Pega tu Script y mira cómo se reconstruye
La reconstrucción se compara con el dinero que cobraba tu Script antiguo antes de que puedas publicarla.