Skip to content

Instantly share code, notes, and snippets.

@b1nary
Last active January 29, 2020 22:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save b1nary/a1106485898bb311668a128af1e08cea to your computer and use it in GitHub Desktop.
module Spree
class Promotion
module Rules
class DontStackRule < Spree::PromotionRule
def applicable?(promotable)
promotable.is_a?(Spree::Order)
end
def eligible?(order, options = {})
# return false if order.order_promotions.any? && order.promotions.map{|pr| pr.promotion_rules.pluck(:type).map(&:to_s) }.flatten.count("Spree::Promotion::Rules::NoOtherPromotionRule") >= 3
return true
end
def actionable?(line_item)
end
end
end
end
end

As soon as i apply the rule to a coupon i get the following when i try to apply it:

{
  "success": null,
  "error": "This coupon code could not be applied to the cart at this time.",
  "successful": false,
  "status_code": "coupon_code_unknown_error"
}
Rails.application.config.spree.promotions.rules << Spree::Promotion::Rules::DontStackRule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment