Migrating a buy one get one free script
Shopify shipped this as a starter template, so it is everywhere. The line that matters divides the quantity by the paid units PLUS the free one, which is what makes a nine-unit cart earn two free instead of three.
ReconstruidoIt split the free units off each complete set and repriced them to zero.
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.
El Script
ReconstruidoPar peligroso D3. 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.
BUY = 3
GET = 1
Input.cart.line_items.each do |line_item|
sets = line_item.quantity / (BUY + GET)
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.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 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 | true | 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.
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.
| Artículo | Cant. | Precio unit. |
|---|---|---|
| Braided USB-C Cable | 4 | $14.00 |
| Subtotal | $56.00 | |
| Descuento | -$14.00 | |
| Total | $42.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 4 de Braided USB-C Cable a $14.00 y la respuesta queda fijada.
El descuento es $14.00. El total que pagó el comprador es $42.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. |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotal | $14.00 | |
| Total | $14.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 D3
Bogo same item free (D3)
ReconstruidoSe reconstruye como una oferta bxgy.
Descuento en su propio carrito: $14.00
sets = line_item.quantity / (BUY + GET)Bogo inclusive basis (D3)
ReconstruidoSe reconstruye como una oferta bxgy.
Descuento en su propio carrito: $14.00
sets = line_item.quantity / BUYPreguntas 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?
- 4 x Braided USB-C Cable at $14.00. The engine takes $14.00 off, and checkout charges $42.00.
- What will I have to check before publishing?
- Confirm which products this applies to. We could not read product targeting from the script.
Formas de Script relacionadas
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.
The least expensive thing in the cart discounted, once.
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.