Class: Cart::AddItemWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/gemgento/cart/add_item_worker.rb

Instance Method Summary collapse

Instance Method Details

#destroy_line_item(line_item) ⇒ Object



16
17
18
19
20
# File 'app/workers/gemgento/cart/add_item_worker.rb', line 16

def destroy_line_item(line_item)
  Gemgento::LineItem.skip_callback(:destroy, :before, :destroy_magento_quote_item)
  line_item.destroy
  Gemgento::LineItem.set_callback(:destroy, :before, :destroy_magento_quote_item)
end

#perform(line_item_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'app/workers/gemgento/cart/add_item_worker.rb', line 5

def perform(line_item_id)
  line_item = Gemgento::LineItem.find(line_item_id)

  begin
    response = API::SOAP::Checkout::Product.add(line_item.itemizable, [line_item])
    destroy_line_item(line_item) unless response.success?
  rescue
    destroy_line_item(line_item)
  end
end