Migrating a spend threshold percentage script
The cleanest script in the whole library, and the one worth doing first on camera: one threshold, one percentage, one money literal, nothing ambiguous anywhere in the file.
ReconstruidoIt compared the cart subtotal to a threshold and took a percentage off once it was reached.
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 D2. 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.
THRESHOLD = Money.new(cents: 10000)
if Input.cart.subtotal_price >= THRESHOLD
Input.cart.line_items.each do |line_item|
line_item.change_line_price(line_item.line_price * (1.0 - (15 / 100.0)), message: "Spend $100, save 15%")
end
end
Output.cart = Input.cartReconocido como Spend threshold discount y reconstruido como una oferta de tipo spend_goal. 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 | spend_goal | type |
| Counting | per_cart | counting |
| Recurrence | once | recurrence |
| Tier 1 | min spend $100.00 -> 15% off | tiers[0] |
| 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. |
|---|---|---|
| Felt Laptop Sleeve | 2 | $38.00 |
| Impact Phone Case | 1 | $24.00 |
| Subtotal | $100.00 | |
| Descuento | -$15.00 | |
| Total | $85.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 Walnut Desk Organizer a $26.00 y la respuesta queda fijada.
El descuento es $15.60. El total que pagó el comprador es $88.40.
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. |
|---|---|---|
| Felt Laptop Sleeve | 1 | $38.00 |
| Subtotal | $38.00 | |
| Total | $38.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 D2
Spend threshold percentage (D2)
ReconstruidoSe reconstruye como una oferta spend_goal.
Descuento en su propio carrito: $15.00
line_item.change_line_price(line_item.line_price * (1.0 - (15 / 100.0)), message: "Spend $100, save 15%")Spend threshold fixed amount (D2)
ReconstruidoSe reconstruye como una oferta spend_goal.
Descuento en su propio carrito: $15.00
REWARD = Money.new(cents: 1500)
remaining = REWARD
break if remaining <= Money.zero
share = [line_item.line_price, remaining].min
line_item.change_line_price(line_item.line_price - share, message: "Spend $100, get $15 off")
remaining = remaining - sharePreguntas frecuentes
- Will Stackable rebuild this script?
- Yes. Every spelling on this page is rebuilt today as a spend_goal offer, and the cart above is the one that proves it.
- What cart proves it works?
- 2 x Felt Laptop Sleeve at $38.00 plus 1 x Impact Phone Case at $24.00. The engine takes $15.00 off, and checkout charges $85.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
A flat sum off the order once the cart crosses a value.
A threshold read from what was left after a code had already come off.
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.