Module: Comable::CartOwner

Included in:
User
Defined in:
app/models/concerns/comable/cart_owner.rb

Defined Under Namespace

Classes: Cart

Instance Method Summary collapse

Instance Method Details

#add_cart_item(obj, quantity: 1) ⇒ Object


3
4
5
6
7
# File 'app/models/concerns/comable/cart_owner.rb', line 3

def add_cart_item(obj, quantity: 1)
  process_cart_item(obj) do |stock|
    add_stock_to_cart(stock, quantity)
  end
end

#cartObject


27
28
29
# File 'app/models/concerns/comable/cart_owner.rb', line 27

def cart
  Cart.new(cart_items)
end

#cart_itemsObject


23
24
25
# File 'app/models/concerns/comable/cart_owner.rb', line 23

def cart_items
  fail 'You should implement cart_items method.'
end

#move_cart_item(cart_item) ⇒ Object


19
20
21
# File 'app/models/concerns/comable/cart_owner.rb', line 19

def move_cart_item(cart_item)
  add_cart_item(cart_item.stock, quantity: cart_item.quantity) && cart_item.destroy
end

#remove_cart_item(obj, quantity: -1)) ⇒ Object


9
10
11
# File 'app/models/concerns/comable/cart_owner.rb', line 9

def remove_cart_item(obj, quantity: -1)
  add_cart_item(obj, quantity: quantity)
end

#reset_cart_item(obj, quantity: 0) ⇒ Object


13
14
15
16
17
# File 'app/models/concerns/comable/cart_owner.rb', line 13

def reset_cart_item(obj, quantity: 0)
  process_cart_item(obj) do |stock|
    reset_stock_from_cart(stock, quantity)
  end
end