Migrating a skip already discounted items script
This looks like the easiest guard in the whole library and it is the hardest. The question it asks is about the other discounts running alongside it, not about the product, and that is a different kind of question entirely.
Shopify 平台限制It skipped any line that had already been reduced by something else.
把它粘贴到 Scripts 救援,看看会重建成什么
- 用本页任意 Script 旁边的按钮复制 Ruby 代码。
- 在 Shopify 后台打开 Stackable,依次进入工具、Scripts 救援。
- 粘贴进去,读一读工具说它会创建什么,再和本页的设置逐项对照。
Scripts 救援属于 Pro 套餐。在您填写旧 Script 的折扣金额、且两个数字精确到最小货币单位完全一致之前,不会发布任何内容。
Script 本体
Shopify 平台限制# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP
# Version 0.12.0
class Campaign
def initialize(condition, *qualifiers)
@condition = (condition.to_s + '?').to_sym
@qualifiers = PostCartAmountQualifier ? [] : [] rescue qualifiers.compact
@post_amount_qualifiers = []
@line_item_selector = qualifiers.last unless @line_item_selector
qualifiers.compact.each do |qualifier|
is_multi_select = qualifier.instance_variable_get(:@conditions).is_a?(Array)
if is_multi_select
qualifier.instance_variable_get(:@conditions).each do |nested_q|
@post_amount_qualifiers << nested_q if nested_q.is_a?(PostCartAmountQualifier)
@qualifiers << qualifier
end
else
@post_amount_qualifiers << qualifier if qualifier.is_a?(PostCartAmountQualifier)
@qualifiers << qualifier
end
end if @qualifiers.empty?
end
end
class Selector
end
class ReducedItemSelector < Selector
def initialize(match_type)
@invert = match_type == :not
end
def match?(line_item)
@invert ^ line_item.discounted?
end
end
class PercentageDiscount
def initialize(percent, message)
@discount = (100 - percent) / 100.0
@message = message
end
def apply(line_item)
line_item.change_line_price(line_item.line_price * @discount, message: @message)
end
end
class ConditionalDiscount < Campaign
def initialize(condition, customer_qualifier, cart_qualifier, line_item_selector, discount, max_discounts)
super(condition, customer_qualifier, cart_qualifier)
@line_item_selector = line_item_selector
@discount = discount
@items_to_discount = max_discounts == 0 ? nil : max_discounts
end
def run(cart)
raise "Campaign requires a discount" unless @discount
return unless qualifies?(cart)
applicable_items = cart.line_items.select { |item| @line_item_selector.nil? || @line_item_selector.match?(item) }
applicable_items.each do |item|
@discount.apply(item)
end
end
end
CAMPAIGNS = [
ConditionalDiscount.new(
:all,
nil,
nil,
ReducedItemSelector.new(:not),
PercentageDiscount.new(10, "10% off full price items"),
0
),
].freeze
CAMPAIGNS.each do |campaign|
campaign.run(Input.cart)
end
Output.cart = Input.cartShopify cannot do this at checkout
Your Script checked whether an item had already been discounted by something else. Discounts at checkout all run at the same moment and cannot see each other's work, so that test could only ever be half right.
这是 Shopify 的限制,不是 Stackable 的缺失。目前没有任何折扣应用能重建它,所以下面的链接指向 Shopify 自己的文档,而不是我们的。
阅读 Shopify 官方文档原因键: platform.perLineAlreadyDiscounted
这里没有可供验证的购物车,因为什么都不会生成。粘贴它只会得到上面的提示,不会创建任何活动。
常见问题
- Will Stackable rebuild this script?
- No, and the reason is stated rather than hidden: Your Script checked whether an item had already been discounted by something else. Discounts at checkout all run at the same moment and cannot see each other's work, so that test could only ever be half right.
相关的 Script 类型
A discount limited to products carrying one tag, vendor or type.
Already-marked-down products protected from a second discount.
Gift cards left out of a discount that would otherwise have hit them.