Shopify脚本-新的行项目

Shopify脚本-新的行项目,shopify,Shopify,当用户使用折扣代码时,我想通过Shopify脚本添加新产品(商品)。可能吗 if Input.cart.discount_code && Input.cart.discount_code.code == "first10" Input.cart.line_items << LineItem.new(variant: 24665166184512, quantity: 10, source_indices:false,grams: 0, properties_w

当用户使用折扣代码时,我想通过Shopify脚本添加新产品(商品)。可能吗

if Input.cart.discount_code && Input.cart.discount_code.code == "first10"
    Input.cart.line_items << LineItem.new(variant: 24665166184512, quantity: 10, source_indices:false,grams: 0, properties_was:false, properties:false, line_price_was:false, line_price:50, original_line_price:50, discounts:0, adjustments:nil)
end

Output.cart = Input.cart
如果Input.cart.discount\u code&&Input.cart.discount\u code.code==“first10”

Input.cart.line_items不幸的是,您无法使用Shopify购物车脚本将产品添加到购物车

购物车脚本只能查看和处理购物车中已存在的项目

如注释中所述,您可以删除项目,因为它已存在于购物车中

我的建议是使用这两种方法中的任何一种

1) 折扣代码是指当某人购买某种商品时,他们以一定的价格或免费获得另一种商品

2) 创建一个Ajax API脚本,当项目添加到购物车时,它会查找购物车中的项目,如果找到了该项目,则会将免费项目或折扣项目添加到购物车中


3) (付费选项)是到应用程序市场去看看,你可以找到一些不同的应用程序来帮助你。这个看起来对你有帮助

您在文档中的何处看到行项目的新方法?我对此很好奇……我看不出来。我偶然发现的。例如,从第_行项目中删除产品在文档中不存在,但有效<代码>def delete_product(product_id)Input.cart.line_items.reject!{| line_item | line_item.variant.product.id==product_id | | line_item.variant.id==product_id}end
您必须猜测比所需参数更好的结果。。。你猜错了。而且没有文件。。这意味着实验。