Created
June 20, 2014 00:47
-
-
Save braidn/f3e197536ba01ce30051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Spree | |
class Promotion | |
module Rules | |
class LimitOnePerUserPromotionRule < PromotionRule | |
def eligible?(order) | |
@email = order.email | |
return completed_orders_using_promotion < 1 | |
end | |
private | |
attr_reader :email | |
def completed_orders | |
::Spree::Order.where(email: email).complete | |
end | |
def promotions | |
completed_orders.map{|o| o.adjustments.promotion}.flatten | |
end | |
def completed_orders_using_promotion | |
promotions.select{|p| ::Spree::PromotionAction.find(p.originator_id). | |
activator_id == self.activator_id}.size | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment