跳转到主要内容
Script 示例

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.

可重建
这个 Script 做了什么

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

在您自己的店铺里试一试

把它粘贴到 Scripts 救援,看看会重建成什么

  1. 用本页任意 Script 旁边的按钮复制 Ruby 代码。
  2. 在 Shopify 后台打开 Stackable,依次进入工具、Scripts 救援。
  3. 粘贴进去,读一读工具说它会创建什么,再和本页的设置逐项对照。

Scripts 救援属于 Pro 套餐。在您填写旧 Script 的折扣金额、且两个数字精确到最小货币单位完全一致之前,不会发布任何内容。

Script 本体

可重建

危险配对 D14。这个文件和它的搭档看起来几乎一样,行为却不同,在判断您手上是哪一个之前,请把两份都读一遍。

原始 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
它会变成什么

识别为 Percentage off,重建为 volume 类型的优惠。下面是优惠实际保存时使用的配置键,您可以逐项核对自己的重建结果。

逐项列出的设置
设置项配置键
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
系统会请您确认
  • 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.
用于验证的购物车

基于我们的公开演示店铺 Meridian Goods 搭建,因此这里的每个价格都可以复现,而不必凭信任接受。下方的折扣金额,是结账时运行的同一个引擎针对这个购物车算出的结果。

触发这个优惠的购物车,以及它的花费
商品数量单价
Braided USB-C Cable1$14.00
小计$14.00
折扣-$2.33
总额$11.67

未登录,或以没有标签的客户身份登录。 配送至 US。

工具用来核对您的金额

发布之前,工具会询问您原来的 Script 对一个现有购物车做了什么。把它设为 1 件 Braided USB-C Cable,单价 $14.00,答案就是固定的。

折扣金额为 $2.33。顾客实际支付的总额为 $11.67。

比对精确到您所用货币的最小单位。差一分钱,发布就仍然被拦住,这正是这一步的意义。

必须没有任何结果的购物车
  • take the same cart, but ship it to DE
不应触发这个优惠的购物车
商品数量单价
Braided USB-C Cable1$14.00
小计$14.00
总额$14.00

未登录,或以没有标签的客户身份登录。 配送至 DE。

两个看起来一样的文件

下面每一对都是同一种 Script 写法的两个版本。它们只差一两行,效果却不同,所以在判断自己手上是哪一个之前,请把两个都读一遍。

危险配对 D14

Vat removal by country (D14)

可重建

重建为 volume 优惠。

在它自己的购物车中的折扣:$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)

另有 5 行差异,在它自己的页面上。

阅读Remove VAT outside the EU

Flat percentage off all 20 (D14)

可重建

重建为 volume 优惠。

在它自己的购物车中的折扣:$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"
  )
阅读Sitewide percentage off

常见问题

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.

相关的 Script 类型

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.

粘贴您的 Script,看看它如何被重建

在您发布之前,重建结果会与原来的 Script 收取的金额进行核对。

我们使用必要 Cookie 来运行本网站,并仅在获得你许可的情况下,使用分析 Cookie 来了解访问情况。详见我们的 Cookie 政策.