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.
ReconstruidoIt stripped the tax portion out of tax-inclusive prices when the shipping country was outside the listed tax area.
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 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.
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.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 -> 16.67% off | tiers[0] |
| Target scope | all | target.scope |
| Country rule | exclude | countryTarget.mode |
| Countries | 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 | countryTarget.codes |
| Country read from | shipping | countryTarget.source |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- 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.
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 | 1 | $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.
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.
- take the same cart, but ship it to DE
| 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. 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)
ReconstruidoSe reconstruye como una oferta volume.
Descuento en su propio carrito: $2.33
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.
Flat percentage off all 20 (D14)
ReconstruidoSe reconstruye como una oferta volume.
Descuento en su propio carrito: $2.80
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"
)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
One percentage off the whole catalogue, with no condition attached.
Everything in the clearance line repriced to one round number per unit.
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.