Migrating an exclude sale items script
The same intent, often the same comment in the merchant’s own file, and two completely different answers depending on how the markdown was detected. Getting the pair backwards either refuses something we support or leaks margin on every clearance line.
ReconstruidoIt skipped any line whose product was already marked down.
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.
Exclude sale items tag proxy (D8)
ReconstruidoPar peligroso D8. 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.
DISCOUNT_PERCENTAGE = 10
Input.cart.line_items.each do |line_item|
next if line_item.variant.product.tags.include?("sale")
new_price = line_item.original_line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0))
line_item.change_line_price(new_price, message: "10% off full-price items")
end
Output.cart = Input.cartReconocido como Percentage off y reconstruido como una oferta de tipo volume. 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 | volume | type |
| Counting | per_product | counting |
| Recurrence | once | recurrence |
| Tier 1 | min qty 1 -> 10% off | tiers[0] |
| Target scope | all | target.scope |
| Target excludes | sale | target.excludeIds |
| 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.
- Targeting excludes sale. No Meridian Goods product carries those, so every product stays eligible and the exclusion is proved by the campaign settings, not by the cart.
| Artículo | Cant. | Precio unit. |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotal | $14.00 | |
| Descuento | -$1.40 | |
| Total | $12.60 | |
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 1 de Braided USB-C Cable a $14.00 y la respuesta queda fijada.
El descuento es $1.40. El total que pagó el comprador es $12.60.
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.
- swap the cart for a single Ceramic Travel Mug
| Artículo | Cant. | Precio unit. |
|---|---|---|
| Ceramic Travel Mug | 1 | $22.00 |
| Subtotal | $22.00 | |
| Total | $22.00 | |
Sin sesión iniciada, o con sesión de un cliente sin etiquetas.
Exclude sale items compare at (D8)
Aún no admitidoPar peligroso D8. 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.
DISCOUNT_PERCENTAGE = 10
Input.cart.line_items.each do |line_item|
next if line_item.variant.compare_at_price && line_item.variant.compare_at_price > line_item.variant.price
new_price = line_item.original_line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0))
line_item.change_line_price(new_price, message: "10% off full-price items")
end
Output.cart = Input.cartWe have not built this yet
Your Script skipped items that were already marked down. Shopify does give us the sale price, but our checkout query is already at Shopify's cost limit, so we cannot ask for it today. Exclude those products by hand and we can rebuild the rest.
Es una carencia nuestra, no de Shopify. Shopify lo permite y nosotros no lo hemos construido, así que aquí no hay nada que enlazar ni nada que echarle a la plataforma.
Clave del motivo: unsupported.compareAtExclusion
Aquí no hay carrito que probar, porque no se construye nada. Pegar esto produce el mensaje de arriba y ninguna campaña.
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 D8
Exclude sale items tag proxy (D8)
ReconstruidoSe reconstruye como una oferta volume.
Descuento en su propio carrito: $1.40
next if line_item.variant.product.tags.include?("sale")Exclude sale items compare at (D8)
Aún no admitidoNo se reconstruye. We have not built this yet
next if line_item.variant.compare_at_price && line_item.variant.compare_at_price > line_item.variant.pricePreguntas frecuentes
- Will Stackable rebuild this script?
- It depends on how yours is written. 1 of the 2 spellings on this page are rebuilt today; the rest are refused with a reason. Compare your file against the Ruby above.
- What cart proves it works?
- 1 x Braided USB-C Cable at $14.00. The engine takes $1.40 off, and checkout charges $12.60.
- 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.
- What happens to the part you cannot rebuild?
- We have not built this yet. Your Script skipped items that were already marked down. Shopify does give us the sale price, but our checkout query is already at Shopify's cost limit, so we cannot ask for it today. Exclude those products by hand and we can rebuild the rest.
Formas de Script relacionadas
A discount limited to products carrying one tag, vendor or type.
Gift cards left out of a discount that would otherwise have hit them.
A discount keyed on a property attached to one cart line.
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.