Module: SolidusVirtualGiftCard::Spree::OrderContentsDecorator

Defined in:
app/decorators/models/solidus_virtual_gift_card/spree/order_contents_decorator.rb

Instance Method Summary collapse

Instance Method Details

#add(variant, quantity = 1, options = {}) ⇒ Object



4
5
6
7
8
# File 'app/decorators/models/solidus_virtual_gift_card/spree/order_contents_decorator.rb', line 4

def add(variant, quantity = 1, options = {})
  line_item = super
  create_gift_cards(line_item, quantity, options['gift_card_details'] || {})
  line_item
end

#remove(variant, quantity = 1, options = {}) ⇒ Object



10
11
12
13
14
# File 'app/decorators/models/solidus_virtual_gift_card/spree/order_contents_decorator.rb', line 10

def remove(variant, quantity = 1, options = {})
  line_item = super
  remove_gift_cards(line_item, quantity)
  line_item
end

#update_cart(params) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'app/decorators/models/solidus_virtual_gift_card/spree/order_contents_decorator.rb', line 16

def update_cart(params)
  update_success = super(params)

  if update_success && params[:line_items_attributes]
    line_item = ::Spree::LineItem.find_by(id: params[:line_items_attributes][:id])
    new_quantity = params[:line_items_attributes][:quantity].to_i
    update_gift_cards(line_item, new_quantity)
  end

  update_success
end