Shopify Ruby 脚本错误 - 未满足折扣代码要求(空购物车)

问题描述 投票:0回答:1

我正在编写一个脚本,该脚本将阻止使用带有“促销”标签的产品的促销代码 - 我在脚本的第 1 行看到一条错误消息,但我不知道如何解决它。该脚本在其他方面运行良好并按预期工作。

关于如何解决此错误有什么建议吗?

# ================================ Customizable Settings ================================
# ================================================================
# Define the tag for products where discounts are not allowed.
# ================================================================
SALE_TAGS = ['sale', 'Sale'] # Tags used to identify sale products
REJECTION_MESSAGE = "Discount codes can't be used with Sale products"

# ================================ Script Code (do not edit) ================================
# ================================================================
# ProductSelector
# Finds matching products by the entered criteria.
# ================================================================
class ProductSelector
  def initialize(tags)
    @tags = tags.map(&:downcase)
  end

  def match?(line_item)
    product_tags = line_item.variant.product.tags.map(&:downcase)
    (@tags & product_tags).any?
  end
end

# ================================================================
# DisableDiscountCodesForProductsCampaign
# If any matching items are in the cart, the discount code is rejected.
# ================================================================
class DisableDiscountCodesForProductsCampaign
  def initialize(tags, message)
    @product_selector = ProductSelector.new(tags)
    @rejection_message = message
  end

  def run(cart)
    return if cart.discount_code.nil?

    if cart.line_items.any? { |line_item| @product_selector.match?(line_item) }
      cart.discount_code.reject(message: @rejection_message)
    end
  end
end

# ================================================================
# Campaign Execution
# ================================================================
campaign = DisableDiscountCodesForProductsCampaign.new(SALE_TAGS, REJECTION_MESSAGE)
campaign.run(Input.cart)
Output.cart = Input.cart

ruby shopify
1个回答
0
投票

也遇到这个问题了。我通过从购物车输入中删除我正在测试的代码解决了这个问题。

删除折扣代码后,请在代码编辑器中进行一些小更改(例如添加额外的空格)以再次触发错误检查器。现在应该已经解决了。

© www.soinside.com 2019 - 2024. All rights reserved.