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

Instance Method Details

#can_redeem?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_productObject



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_placeObject

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_placeObject

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_labelObject

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

Returns:

  • (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

#redeemerObject



33
34
35
# File 'app/models/concerns/spree_cm_commissioner/line_item_open_dated_trippable.rb', line 33

def redeemer
  accepter
end