Class: Spree::Promotion::Rules::Country

Inherits:
Spree::PromotionRule show all
Defined in:
app/models/spree/promotion/rules/country.rb

Instance Method Summary collapse

Methods inherited from Spree::PromotionRule

#actionable?, #eligibility_errors, for

Methods inherited from Base

belongs_to_required_by_default, page, spree_base_scopes

Methods included from Spree::Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

#applicable?(promotable) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'app/models/spree/promotion/rules/country.rb', line 8

def applicable?(promotable)
  promotable.is_a?(Spree::Order)
end

#eligible?(order, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
# File 'app/models/spree/promotion/rules/country.rb', line 12

def eligible?(order, options = {})
  country_id = options[:country_id] || order.ship_address.try(:country_id)
  unless country_id.eql?(preferred_country_id || Spree::Country.default)
    eligibility_errors.add(:base, eligibility_error_message(:wrong_country))
  end

  eligibility_errors.empty?
end