Module: SpreeCmCommissioner::LineItemOpenDatedTrippable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/spree_cm_commissioner/line_item_open_dated_trippable.rb
Overview
Makes an open-return entitlement line item redeemable.
New design: the open return is no longer a fake open-dated trip line item. It is a plain ecommerce add-on (a Spree::Product linked to the outbound trip’s product via an ‘open_dated_pair` ProductRelation) sold as a regular ecommerce line item at checkout.
Redemption swaps that ecommerce line item in place into a concrete transit ticket on a chosen return trip (see SpreeCmCommissioner::OpenDatedTrips::Redeem). Once swapped, the line item is a ‘transit` item.
Instance Method Summary collapse
- #can_redeem? ⇒ Boolean
- #expired? ⇒ Boolean
- #open_dated? ⇒ Boolean
- #open_dated_product ⇒ Object
-
#open_dated_return_destination_place ⇒ Object
Destination place the return trip must arrive at (= outbound origin).
-
#open_dated_return_origin_place ⇒ Object
Origin place the return trip must depart from (= outbound destination).
-
#open_dated_route_label ⇒ Object
Human-readable return journey, e.g.
- #redeemed? ⇒ Boolean
- #redeemer ⇒ Object
Instance Method Details
#can_redeem? ⇒ Boolean
76 77 78 |
# File 'app/models/concerns/spree_cm_commissioner/line_item_open_dated_trippable.rb', line 76 def can_redeem? open_dated? && !redeemed? && !expired? end |
#expired? ⇒ Boolean
72 73 74 |
# File 'app/models/concerns/spree_cm_commissioner/line_item_open_dated_trippable.rb', line 72 def expired? valid_until.present? && valid_until.to_date < Date.current end |
#open_dated? ⇒ Boolean
37 38 39 |
# File 'app/models/concerns/spree_cm_commissioner/line_item_open_dated_trippable.rb', line 37 def open_dated? open_dated_return_origin_place_id.present? && open_dated_return_destination_place_id.present? end |
#open_dated_product ⇒ Object
41 42 43 44 45 |
# File 'app/models/concerns/spree_cm_commissioner/line_item_open_dated_trippable.rb', line 41 def open_dated_product return nil if open_dated_product_id.blank? @open_dated_product ||= Spree::Product.find_by(id: open_dated_product_id) end |
#open_dated_return_destination_place ⇒ Object
Destination place the return trip must arrive at (= outbound origin).
55 56 57 58 59 |
# File 'app/models/concerns/spree_cm_commissioner/line_item_open_dated_trippable.rb', line 55 def open_dated_return_destination_place return nil if open_dated_return_destination_place_id.blank? @open_dated_return_destination_place ||= SpreeCmCommissioner::Place.find_by(id: open_dated_return_destination_place_id) end |
#open_dated_return_origin_place ⇒ Object
Origin place the return trip must depart from (= outbound destination).
48 49 50 51 52 |
# File 'app/models/concerns/spree_cm_commissioner/line_item_open_dated_trippable.rb', line 48 def open_dated_return_origin_place return nil if open_dated_return_origin_place_id.blank? @open_dated_return_origin_place ||= SpreeCmCommissioner::Place.find_by(id: open_dated_return_origin_place_id) end |
#open_dated_route_label ⇒ Object
Human-readable return journey, e.g. “Siem Reap → Phnom Penh”. Nil when endpoints are missing.
62 63 64 65 66 |
# File 'app/models/concerns/spree_cm_commissioner/line_item_open_dated_trippable.rb', line 62 def open_dated_route_label return nil if open_dated_return_origin_place.blank? || open_dated_return_destination_place.blank? "#{open_dated_return_origin_place.full_path_name} → #{open_dated_return_destination_place.full_path_name}" end |
#redeemed? ⇒ Boolean
68 69 70 |
# File 'app/models/concerns/spree_cm_commissioner/line_item_open_dated_trippable.rb', line 68 def redeemed? redeemed_at.present? end |
#redeemer ⇒ Object
33 34 35 |
# File 'app/models/concerns/spree_cm_commissioner/line_item_open_dated_trippable.rb', line 33 def redeemer accepter end |