Module: SolidusVirtualGiftCard::Spree::OrderDecorator
- Defined in:
- app/decorators/models/solidus_virtual_gift_card/spree/order_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.prepended(base) ⇒ Object
4 5 6 7 8 9 10 |
# File 'app/decorators/models/solidus_virtual_gift_card/spree/order_decorator.rb', line 4 def self.prepended(base) base.class_eval do state_machine.after_transition to: :complete, do: :send_gift_card_emails has_many :gift_cards, through: :line_items end end |
Instance Method Details
#finalize! ⇒ Object
22 23 24 25 26 27 28 |
# File 'app/decorators/models/solidus_virtual_gift_card/spree/order_decorator.rb', line 22 def finalize! super inventory_units = self.inventory_units gift_cards.each_with_index do |gift_card, index| gift_card.make_redeemable!(purchaser: user, inventory_unit: inventory_units[index]) end end |
#gift_card_match(line_item, options) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'app/decorators/models/solidus_virtual_gift_card/spree/order_decorator.rb', line 12 def gift_card_match(line_item, ) return true unless line_item.gift_card? return true unless ['gift_card_details'] line_item.gift_cards.any? do |gift_card| gc_detail_set = gift_card.details.stringify_keys.except('send_email_at').to_set = ['gift_card_details'].except('send_email_at').to_set gc_detail_set.superset?() end end |
#send_gift_card_emails ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/decorators/models/solidus_virtual_gift_card/spree/order_decorator.rb', line 30 def send_gift_card_emails gift_cards.each do |gift_card| if gift_card.send_email_at.nil? || gift_card.send_email_at <= DateTime.now gift_card.send_email end end end |