[英]Shopify limit product order quantity
I am new to Shopify and would like to know how I can set the max order quantity of a product to a specific number.我是 Shopify 的新手,想知道如何将产品的最大订购数量设置为特定数量。
So product A max order qty 6所以产品 A 最大订单数量 6
I am using the Symmetry theme.我正在使用对称主题。
I am comfortable editing code, just need to know where to find it.我很喜欢编辑代码,只需要知道在哪里可以找到它。 Also will a code change survive Shopify updates?代码更改还会在 Shopify 更新后继续存在吗? Sorry I am switching over from Wordpress so getting familiar with this new system.抱歉,我要从 Wordpress 切换过来,所以要熟悉这个新系统。
Many Thanks!非常感谢!
There are at least three ways you can achieve that:至少有三种方法可以实现:
class LimitProduct
def initialize(variantId, quantity)
@variant = variantId
@max_qty = quantity
end
def run(cart)
line_items = cart.line_items.select { |line_item| line_item.variant.id == @variant }
return if line_items.empty?
loop_items(cart, line_items)
end
def loop_items(cart, line_items)
if @max_qty==0
cart.line_items.delete_if {|item| item.variant.id == @variant }
else
line_items.each_with_index do |item,index|
if item.quantity > @max_qty && @max_qty != 0
reduceBy = item.quantity - @max_qty
item.split(take: reduceBy)
end
end
end
end
end
CAMPAIGNS = [
LimitProduct.new(1234567890, 0), #first arg is variant id, second is max quantity
LimitProduct.new(1111111111, 2)
]
CAMPAIGNS.each do |campaign|
campaign.run(Input.cart)
end
Output.cart = Input.cart
Note that Script Editor is for Shopify Plus users请注意,脚本编辑器适用于 Shopify Plus 用户
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.