Saltar al contenido
Ejemplos de Scripts

Migrating a remove-VAT-outside-the-EU script

The arithmetic is the trap. Taking 20% VAT out of a VAT-inclusive price is a 16.67% reduction, because the tax is a fifth of the pre-tax price and a sixth of the shelf price. The literal 20 sits right next to a divide by 100 in every one of these files.

Reconstruido
Qué hacía el Script

It stripped the tax portion out of tax-inclusive prices when the shipping country was outside the listed tax area.

Pruébalo en tu propia tienda

Pégalo en Rescate de scripts y mira qué reconstruye

  1. Copia el Ruby con el botón que hay junto a cualquier Script de esta página.
  2. En tu panel de Shopify, abre Stackable, luego Herramientas y luego Rescate de scripts.
  3. 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

Reconstruido

Par peligroso D14. 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.

El Ruby original

VAT = 20
VAT_REMOVAL_MESSAGE = "VAT removed"
COUNTRY_CODES_EU = %w[AT BE BG CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE GB]

country_code = Input.cart.shipping_address&.country_code

unless country_code.nil? || COUNTRY_CODES_EU.include?(country_code)
  vat_only_fraction = VAT / (100.0 + VAT)
  Input.cart.line_items.each do |line_item|
    next if line_item.variant.product.gift_card?
    ex_vat_price = line_item.line_price - (line_item.line_price * vat_only_fraction)
    line_item.change_line_price(ex_vat_price, message: VAT_REMOVAL_MESSAGE)
  end
end

Output.cart = Input.cart
En qué se convierte

Reconocido 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.

Cada ajuste, detallado
AjusteValorClave de configuración
Offer typevolumetype
Countingper_productcounting
Recurrenceoncerecurrence
Tier 1min qty 1 -> 16.67% offtiers[0]
Target scopealltarget.scope
Country ruleexcludecountryTarget.mode
CountriesAT,BE,BG,CY,CZ,DK,EE,FI,FR,DE,GR,HU,IE,IT,LV,LT,LU,MT,NL,PL,PT,RO,SK,SI,ES,SE,GBcountryTarget.codes
Country read fromshippingcountryTarget.source
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
Se te pedirá que confirmes
  • Your Script skipped gift cards. We cannot detect gift cards yet, so exclude them by hand in targeting before publishing.
  • Confirm which products this applies to. We could not read product targeting from the script.
Se te avisará
  • Your Script worked from a tax-inclusive figure. We apply the percentage to the item price, so single-cent differences are possible.
  • Your Script skipped gift cards and we cannot detect them, so gift cards are discounted unless you exclude them in targeting.
El carrito que lo demuestra

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.

El carrito que activa esta oferta, y lo que cuesta
ArtículoCant.Precio unit.
Braided USB-C Cable1$14.00
Subtotal$14.00
Descuento-$2.33
Total$11.67

Sin sesión iniciada, o con sesión de un cliente sin etiquetas. Envío a US.

La cifra con la que la herramienta te compara

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 $2.33. El total que pagó el comprador es $11.67.

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.

El carrito que no debe producir nada
  • take the same cart, but ship it to DE
El carrito que no debe activar esta oferta
ArtículoCant.Precio unit.
Braided USB-C Cable1$14.00
Subtotal$14.00
Total$14.00

Sin sesión iniciada, o con sesión de un cliente sin etiquetas. Envío a DE.

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 D14

Vat removal by country (D14)

Reconstruido

Se reconstruye como una oferta volume.

Descuento en su propio carrito: $2.33

Líneas que cambian
VAT = 20
VAT_REMOVAL_MESSAGE = "VAT removed"
COUNTRY_CODES_EU = %w[AT BE BG CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE GB]
country_code = Input.cart.shipping_address&.country_code
unless country_code.nil? || COUNTRY_CODES_EU.include?(country_code)
  vat_only_fraction = VAT / (100.0 + VAT)

Y 5 líneas distintas más, en su propia página.

Leer Remove VAT outside the EU

Flat percentage off all 20 (D14)

Reconstruido

Se reconstruye como una oferta volume.

Descuento en su propio carrito: $2.80

Líneas que cambian
DISCOUNT_PERCENTAGE = 20
Input.cart.line_items.each do |line_item|
  line_item.change_line_price(
    line_item.line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0)),
    message: "20% off"
  )
Leer Sitewide percentage off

Preguntas frecuentes

Will Stackable rebuild this script?
Yes. Every spelling on this page is rebuilt today as a volume offer, and the cart above is the one that proves it.
What cart proves it works?
1 x Braided USB-C Cable at $14.00. The engine takes $2.33 off, and checkout charges $11.67.
What will I have to check before publishing?
Your Script skipped gift cards. We cannot detect gift cards yet, so exclude them by hand in targeting before publishing. Confirm which products this applies to. We could not read product targeting from the script. Your Script worked from a tax-inclusive figure. We apply the percentage to the item price, so single-cent differences are possible. Your Script skipped gift cards and we cannot detect them, so gift cards are discounted unless you exclude them in targeting.

Formas de Script relacionadas

Sitewide percentage off

One percentage off the whole catalogue, with no condition attached.

Fixed price per item

Everything in the clearance line repriced to one round number per unit.

Amount off each item

A flat sum taken off every unit, however many the shopper bought.

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.

Usamos cookies esenciales para el funcionamiento de este sitio y, solo con tu permiso, cookies analíticas para entender el tráfico. Lee nuestra Política de cookies.