Module: Spree::Purchase::DigitalItems
Overview
Digitality predicates over line items, shared by Spree::Cart and Spree::Order (fulfillment-side digital delivery stays order-only in Spree::Order::Digital).
Instance Method Summary collapse
-
#delivery_step_required? ⇒ Boolean
Whether the customer must choose a delivery option in checkout — shipping and both pickup kinds are chosen; digital fulfillments are created by their provider without a selection.
-
#digital? ⇒ Boolean
True when every line item is digital.
- #digital_line_items ⇒ ActiveRecord::Relation<Spree::LineItem>
-
#digital_links ⇒ ActiveRecord::Relation<Spree::DigitalLink>
One query rather than one per line item — this is read for every digital order's email.
-
#some_digital? ⇒ Boolean
True when any line item is digital.
-
#with_digital_assets? ⇒ Boolean
True when any line item has digital assets.
Instance Method Details
#delivery_step_required? ⇒ Boolean
Whether the customer must choose a delivery option in checkout — shipping and both pickup kinds are chosen; digital fulfillments are created by their provider without a selection. Delivery itself happens for all of them.
55 56 57 |
# File 'app/models/concerns/spree/purchase/digital_items.rb', line 55 def delivery_step_required? line_items.any? && !digital? end |
#digital? ⇒ Boolean
Returns true when every line item is digital.
8 9 10 11 12 13 14 |
# File 'app/models/concerns/spree/purchase/digital_items.rb', line 8 def digital? if total_quantity.zero? || line_items.empty? false else line_items_with_variants(variant: :product).all?(&:digital?) end end |
#digital_line_items ⇒ ActiveRecord::Relation<Spree::LineItem>
35 36 37 |
# File 'app/models/concerns/spree/purchase/digital_items.rb', line 35 def digital_line_items line_items.joins(:variant).with_digital_assets.distinct end |
#digital_links ⇒ ActiveRecord::Relation<Spree::DigitalLink>
One query rather than one per line item — this is read for every
digital order's email. reorder(nil) drops the line-item default order:
PostgreSQL rejects SELECT DISTINCT ordered by a column that is not in
the select list, and ordering a subquery buys nothing anyway.
45 46 47 |
# File 'app/models/concerns/spree/purchase/digital_items.rb', line 45 def digital_links Spree::DigitalLink.where(line_item_id: digital_line_items.reorder(nil).select(:id)) end |
#some_digital? ⇒ Boolean
Returns true when any line item is digital.
17 18 19 20 21 22 23 |
# File 'app/models/concerns/spree/purchase/digital_items.rb', line 17 def some_digital? if total_quantity.zero? || line_items.empty? false else line_items_with_variants(variant: :product).any?(&:digital?) end end |
#with_digital_assets? ⇒ Boolean
Returns true when any line item has digital assets.
26 27 28 29 30 31 32 |
# File 'app/models/concerns/spree/purchase/digital_items.rb', line 26 def with_digital_assets? if total_quantity.zero? || line_items.empty? false else line_items_with_variants(variant: :digital_assets).any?(&:with_digital_assets?) end end |