Class: Spree::DeliveryMethodRules::ChannelRule

Inherits:
Spree::DeliveryMethodRule show all
Defined in:
app/models/spree/delivery_method_rules/channel_rule.rb

Overview

Offers the method only to carts on the listed channels, so one profile can price the same goods differently per channel (a wholesale rate beside a retail one) without duplicating products or warehouses.

This governs which methods a channel is offered, not which origins serve it — that stays on the channel's stock-location allowlist, where quoting and allocation cannot disagree (docs/plans/6.0-channel-delivery.md).

Instance Method Summary collapse

Methods included from TypeLabels

#human_description, #human_name

Methods included from PreferenceSchema

#serialized_preferences

Instance Method Details

#channels ⇒ Object



19
20
21
22
23
# File 'app/models/spree/delivery_method_rules/channel_rule.rb', line 19

def channels
  return [] if preferred_channel_ids.blank?

  store.channels.where(id: preferred_channel_ids)
end

#eligible?(package) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/spree/delivery_method_rules/channel_rule.rb', line 25

def eligible?(package)
  # An empty preference leaves the method unrestricted, matching the
  # other rules' fail-open convention for half-configured rows.
  return true if preferred_channel_ids.empty?

  channel = package.owner&.channel
  return false if channel.nil?

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