从折扣中排除产品变体?

时间:2021-05-20 14:48:12

标签: ruby shopify shopify-app shopify-api

有没有办法(甚至通过 JS 或 Line Item Ruby 脚本使用 API)从折扣中排除产品变体?

我们正在使用 compare_at_price 来销售商品,并希望它们免于所有进一步的折扣。

我们可以使用 API 检查 compare_at_price 以查看该商品是否在打折,但有什么方法可以触发折扣豁免吗?

.

更新: 好的,所以我使用下面的脚本进行了这项工作,我们遍历购物车项目并检查变体 compare_at_price 是否不为零,尽管这将整个购物车排除在折扣之外:

# Runs through a loop of items in your cart
Input.cart.line_items.each do |line_item|
  product = line_item.variant.product
  puts line_item.variant.compare_at_price
  next if product.gift_card?
  # Check if product has allows discounts on sale item
  next if line_item.variant.product.tags.include? 'allow-discount'
  # Check if variant has compare at price (on sale)
  next if line_item.variant.compare_at_price.nil? 
  case Input.cart.discount_code
  when CartDiscount::Percentage, CartDiscount::FixedAmount, CartDiscount::Shipping
    Input.cart.discount_code.reject({message: "Discount codes cannot be used with sale items "})
  end
end

Output.cart = Input.cart

是否可以只从折扣中排除 compare_at_price 不为零的变体而不是整个购物车?

0 个答案:

没有答案