Migrating a purchase quantity limit script
Not a discount at all, and full of the exact syntax a BOGO uses, so a careless reader turns a purchase limit into a giveaway. The reliable tell is that it deletes cart lines and never changes a price.
另一种 Shopify APIIt split the excess units off a line and deleted them from the cart.
把它粘贴到 Scripts 救援,看看会重建成什么
- 用本页任意 Script 旁边的按钮复制 Ruby 代码。
- 在 Shopify 后台打开 Stackable,依次进入工具、Scripts 救援。
- 粘贴进去,读一读工具说它会创建什么,再和本页的设置逐项对照。
Scripts 救援属于 Pro 套餐。在您填写旧 Script 的折扣金额、且两个数字精确到最小货币单位完全一致之前,不会发布任何内容。
Script 本体
另一种 Shopify API危险配对 D6。这个文件和它的搭档看起来几乎一样,行为却不同,在判断您手上是哪一个之前,请把两份都读一遍。
# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP
class QuantityLimit < Campaign
def initialize(condition, customer_qualifier, cart_qualifier, line_item_selector, limit_by, limit)
super(condition, customer_qualifier, cart_qualifier, line_item_selector)
@limit_by = limit_by
@limit = limit
end
def run(cart)
return unless qualifies?(cart)
to_delete = []
counts = {}
cart.line_items.each_with_index do |item, index|
next unless @line_item_selector.nil? || @line_item_selector.match?(item)
key = @limit_by == :product ? item.variant.product.id : item.variant.id
counts[key] = 0 unless counts[key]
max_amount = @limit - counts[key]
if max_amount <= 0
to_delete << index
elsif item.quantity > max_amount
item.split(take: max_amount)
counts[key] += max_amount
else
counts[key] += item.quantity
end
end
to_delete.reverse.each { |index| cart.line_items.delete_at(index) }
end
end
CAMPAIGNS = [
QuantityLimit.new(:all, nil, nil, ProductTagSelector.new(:does, :match, ["limited"]), :variant, 2),
].freeze
CAMPAIGNS.each do |campaign|
campaign.run(Input.cart)
end
Output.cart = Input.cartThis needs a different kind of Shopify app
Your Script blocked or limited checkout, such as a purchase limit or an age check. Shopify builds that with the Cart and Checkout Validation API, which Stackable does not ship.
Script 的这一部分不是折扣。Shopify 用上面提到的另一种函数类型来实现它,而 Stackable 并不提供那种函数。
阅读 Shopify 官方文档原因键: otherApi.cartCheckoutValidation
这里没有可供验证的购物车,因为什么都不会生成。粘贴它只会得到上面的提示,不会创建任何活动。
两个看起来一样的文件
下面每一对都是同一种 Script 写法的两个版本。它们只差一两行,效果却不同,所以在判断自己手上是哪一个之前,请把两个都读一遍。
危险配对 D6
Quantity limit purchase cap (D6)
另一种 Shopify API不会重建。This needs a different kind of Shopify app
# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP
class QuantityLimit < Campaign
def initialize(condition, customer_qualifier, cart_qualifier, line_item_selector, limit_by, limit)
super(condition, customer_qualifier, cart_qualifier, line_item_selector)
@limit_by = limit_by
@limit = limit另有 26 行差异,在它自己的页面上。
Quantity limit first n discounted (D6)
可重建重建为 bxgy 优惠。
在它自己的购物车中的折扣:$23.70
DISCOUNT_PERCENTAGE = 30
MAX_UNITS = 2
num_to_discount = MAX_UNITS
Input.cart.line_items.each_with_index do |line_item, position|
break if num_to_discount <= 0
next unless line_item.variant.product.tags.include?("limited")另有 9 行差异,在它自己的页面上。
常见问题
- Will Stackable rebuild this script?
- No, and the reason is stated rather than hidden: Your Script blocked or limited checkout, such as a purchase limit or an age check. Shopify builds that with the Cart and Checkout Validation API, which Stackable does not ship.
相关的 Script 类型
The discount applied to the first few units only, with the rest at full price.
Products that could not ship to the shopper’s country, quietly deleted.
A payment option taken off checkout under a condition.