Class: Spree::DeliveryOriginGroup
- Inherits:
-
Object
- Object
- Spree::DeliveryOriginGroup
- Includes:
- HasListPosition
- Defined in:
- app/models/spree/delivery_origin_group.rb
Overview
Partitions a delivery profile's fulfillment origins: every zone and method belongs to a group, so the same products can quote different rates depending on which warehouse fulfills them. A profile always has at least one group; the auto-created default is nameless with no location members, which means every store location — simple stores never see the layer.
Instance Method Summary collapse
-
#can_be_deleted? ⇒ Boolean
Only one rule survives: a profile needs somewhere for delivery to live, so its last group stays.
-
#covers_location?(stock_location) ⇒ Boolean
Whether packages originating from this stock location are served by the group's zones and methods.
-
#fulfillable_stock_locations ⇒ ActiveRecord::Relation<Spree::StockLocation>
The locations this group fulfills from.
-
#member_stock_location_ids ⇒ Array<Integer>
Ids of the locations this group is limited to.
Instance Method Details
#can_be_deleted? ⇒ Boolean
Only one rule survives: a profile needs somewhere for delivery to live, so its last group stays. Anything hanging off a group goes with it.
34 35 36 |
# File 'app/models/spree/delivery_origin_group.rb', line 34 def can_be_deleted? delivery_profile.delivery_origin_groups.where.not(id: id).exists? end |
#covers_location?(stock_location) ⇒ Boolean
Whether packages originating from this stock location are served by the group's zones and methods. No linked locations means every store location.
Allocation asks this once per location per unit, so the membership is read through the loaded association rather than re-queried each call.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/spree/delivery_origin_group.rb', line 47 def covers_location?(stock_location) return false if stock_location.nil? return true if member_stock_location_ids.empty? # A narrowed group names which of the *operator's* warehouses ship this # kind of goods ("pallets go out of Warehouse B"), and says nothing # about where a seller keeps stock. Reading it as a store-wide allowlist # would make every seller's inventory unallocatable # (docs/plans/6.0-multi-vendor-marketplace.md, Decision 13). return true if stock_location.seller_id.present? member_stock_location_ids.include?(stock_location.id) end |
#fulfillable_stock_locations ⇒ ActiveRecord::Relation<Spree::StockLocation>
The locations this group fulfills from.
68 69 70 71 72 |
# File 'app/models/spree/delivery_origin_group.rb', line 68 def fulfillable_stock_locations return store.stock_locations if member_stock_location_ids.empty? store.stock_locations.where(id: stock_locations.select(:id)) end |
#member_stock_location_ids ⇒ Array<Integer>
Returns ids of the locations this group is limited to.
61 62 63 |
# File 'app/models/spree/delivery_origin_group.rb', line 61 def member_stock_location_ids @member_stock_location_ids ||= delivery_origin_group_locations.map(&:stock_location_id) end |