Class: Spree::PriceRules::ChannelRule

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spree::PriceRule

human_name, registered_subclasses

Class Method Details

.descriptionObject



31
32
33
# File 'app/models/spree/price_rules/channel_rule.rb', line 31

def self.description
  Spree.t('price_rules.channel_rule.description')
end

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


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

def applicable?(context)
  # An empty preference means the rule is unrestricted, so it applies
  # regardless of (and even without) a channel in the context.
  return true if preferred_channel_ids.empty?
  return false unless context.channel

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

#channelsObject



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

def channels
  return [] if preferred_channel_ids.blank?

  store.channels.where(id: preferred_channel_ids)
end