Class: Workarea::SavedList

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument
Defined in:
app/models/workarea/saved_list.rb,
app/models/workarea/saved_list/item.rb

Defined Under Namespace

Classes: Item

Instance Method Summary collapse

Instance Method Details

#add_item(item_attributes = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/workarea/saved_list.rb', line 10

def add_item(item_attributes = {})
  item_attributes = item_attributes.with_indifferent_access
  existing = items.where(item_attributes.slice(:sku, :customizations)).first

  if existing.present?
    existing.quantity = existing.quantity + item_attributes[:quantity].to_i
  else
    items.build(item_attributes)
  end

  save
end

#remove_item(id) ⇒ Object



23
24
25
# File 'app/models/workarea/saved_list.rb', line 23

def remove_item(id)
  items.find(id).destroy
end