Class: Spree::GiftCard
- Inherits:
-
Object
- Object
- Spree::GiftCard
- Extended by:
- DisplayMoney
- Includes:
- Metafields, Security::GiftCards, SingleStoreResource
- Defined in:
- app/models/spree/gift_card.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#active? ⇒ Boolean
Checks if the gift card is active, i.e.
-
#amount=(amount) ⇒ Object
Sets the amount.
-
#amount_remaining ⇒ Decimal
Calculates the remaining amount.
-
#can_be_deleted? ⇒ Boolean
Checks if the gift card can be deleted.
-
#display_code ⇒ String
Displays the code in uppercase, eg.
-
#display_state ⇒ String
Displays state as expired if the gift card is expired, otherwise displays the state.
-
#editable? ⇒ Boolean
Checks if the gift card is editable.
-
#expired? ⇒ Boolean
Checks if the gift card is expired.
- #to_csv(_store = nil) ⇒ Object
Methods included from DisplayMoney
Class Method Details
.json_api_columns ⇒ Object
92 93 94 |
# File 'app/models/spree/gift_card.rb', line 92 def self.json_api_columns %w[code amount expires_at] end |
Instance Method Details
#active? ⇒ Boolean
Checks if the gift card is active, i.e. not expired and not redeemed
122 123 124 |
# File 'app/models/spree/gift_card.rb', line 122 def active? super && !expired? end |
#amount=(amount) ⇒ Object
Sets the amount
80 81 82 |
# File 'app/models/spree/gift_card.rb', line 80 def amount=(amount) self[:amount] = Spree::LocalizedNumber.parse(amount) end |
#amount_remaining ⇒ Decimal
Calculates the remaining amount
86 87 88 |
# File 'app/models/spree/gift_card.rb', line 86 def amount_remaining amount - amount_used - end |
#can_be_deleted? ⇒ Boolean
Checks if the gift card can be deleted
104 105 106 |
# File 'app/models/spree/gift_card.rb', line 104 def can_be_deleted? !redeemed? && !partially_redeemed? end |
#display_code ⇒ String
Displays the code in uppercase, eg. ABC1234
110 111 112 |
# File 'app/models/spree/gift_card.rb', line 110 def display_code code.upcase end |
#display_state ⇒ String
Displays state as expired if the gift card is expired, otherwise displays the state
128 129 130 131 132 133 134 |
# File 'app/models/spree/gift_card.rb', line 128 def display_state if expired? :expired else state end.to_s end |
#editable? ⇒ Boolean
Checks if the gift card is editable
98 99 100 |
# File 'app/models/spree/gift_card.rb', line 98 def editable? active? end |
#expired? ⇒ Boolean
Checks if the gift card is expired
116 117 118 |
# File 'app/models/spree/gift_card.rb', line 116 def expired? !redeemed? && expires_at.present? && expires_at <= Date.current end |
#to_csv(_store = nil) ⇒ Object
136 137 138 |
# File 'app/models/spree/gift_card.rb', line 136 def to_csv(_store = nil) Spree::CSV::GiftCardPresenter.new(self).call end |