Naar de inhoud
Script-voorbeelden

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.

Herbouwd
Wat het Script deed

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

Probeer het in je eigen winkel

Plak het in Scripts-redding en kijk wat eruit komt

  1. Kopieer de Ruby met de knop naast elk Script op deze pagina.
  2. Open in je Shopify-beheer Stackable, dan Hulpmiddelen, dan Scripts-redding.
  3. Plak het daar, lees wat het hulpmiddel zegt te gaan bouwen en vergelijk dat met de instellingen op deze pagina.

Scripts-redding zit in het Pro-abonnement. Er wordt niets gepubliceerd totdat je vertelt wat je oude Script gaf en beide bedragen tot op de cent kloppen.

Het Script

Herbouwd

Riskant paar D14. Dit bestand en zijn tegenhanger zien er bijna hetzelfde uit en doen iets anders, dus lees ze allebei voordat je bepaalt welke jij hebt.

De oorspronkelijke Ruby

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
Wat het wordt

Herkend als Percentage off en herbouwd als aanbieding van het type volume. Dit zijn de echte configuratiesleutels waarmee de aanbieding wordt opgeslagen, zodat je je eigen herbouw veld voor veld kunt nalopen.

Elke instelling, uitgeschreven
InstellingWaardeConfiguratiesleutel
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
Er wordt om bevestiging gevraagd
  • 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.
Je krijgt te horen
  • 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.
De winkelwagen die het bewijst

Gebouwd in onze openbare demowinkel, Meridian Goods, zodat elke prijs hier na te rekenen is in plaats van op vertrouwen aangenomen. De korting hieronder is wat dezelfde engine die bij het afrekenen draait, voor precies deze winkelwagen berekent.

De winkelwagen die deze aanbieding activeert, en wat die kost
ArtikelAantalStukprijs
Braided USB-C Cable1$14.00
Subtotaal$14.00
Korting-$2.33
Totaal$11.67

Uitgelogd, of ingelogd als klant zonder tags. Verzending naar US.

Het bedrag waaraan de tool je toetst

Voor het publiceren vraagt de tool wat je oude Script deed met een winkelwagen die je al hebt. Zet die op 1 van Braided USB-C Cable voor $14.00 en het antwoord ligt vast.

De korting is $2.33. Het totaal dat de klant betaalde is $11.67.

De vergelijking is exact, tot op de kleinste eenheid van je valuta. Eén cent ernaast en publiceren blijft dicht, en daar gaat deze stap juist om.

De winkelwagen die niets mag opleveren
  • take the same cart, but ship it to DE
De winkelwagen die deze aanbieding niet mag activeren
ArtikelAantalStukprijs
Braided USB-C Cable1$14.00
Subtotaal$14.00
Totaal$14.00

Uitgelogd, of ingelogd als klant zonder tags. Verzending naar DE.

Twee bestanden die op elkaar lijken

Elk paar hieronder is dezelfde Script-vorm, op twee manieren geschreven. Ze schelen een of twee regels en doen iets anders, dus lees ze allebei voordat je bepaalt welke jij hebt.

Gevaarlijk paar D14

Vat removal by country (D14)

Herbouwd

Opnieuw gebouwd als volume-aanbieding.

Korting in de eigen winkelwagen: $2.33

Regels die verschillen
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)

En nog 5 afwijkende regels, op de eigen pagina.

Remove VAT outside the EU lezen

Flat percentage off all 20 (D14)

Herbouwd

Opnieuw gebouwd als volume-aanbieding.

Korting in de eigen winkelwagen: $2.80

Regels die verschillen
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"
  )
Sitewide percentage off lezen

Veelgestelde vragen

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.

Verwante Script-vormen

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.

Plak je Script en zie het herbouwd worden

De herbouw wordt getoetst aan het bedrag dat je oude Script rekende voordat je hem kunt publiceren.

We gebruiken essentiële cookies om deze site te laten werken en, alleen met uw toestemming, analytische cookies om verkeer te begrijpen. Lees ons Cookiebeleid.