Class: Spree::PriceRules::MarketRule

Inherits:
Spree::PriceRule show all
Defined in:
app/models/spree/price_rules/market_rule.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spree::PriceRule

human_name, registered_subclasses

Class Method Details

.descriptionObject



29
30
31
# File 'app/models/spree/price_rules/market_rule.rb', line 29

def self.description
  'Apply pricing based on the market'
end

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'app/models/spree/price_rules/market_rule.rb', line 21

def applicable?(context)
  return false unless context.market
  return true if preferred_market_ids.empty?

  # Compare as strings to support both integer and UUID primary keys
  preferred_market_ids.map(&:to_s).include?(context.market.id.to_s)
end

#marketsObject



15
16
17
18
19
# File 'app/models/spree/price_rules/market_rule.rb', line 15

def markets
  return [] if preferred_market_ids.blank?

  Spree::Market.where(id: preferred_market_ids)
end