You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
567 B
Lua
25 lines
567 B
Lua
local item = require'./models/item'
|
|
|
|
local lineitem = {}
|
|
|
|
lineitem.setdb = function(db)
|
|
lineitem.db = db
|
|
end
|
|
|
|
lineitem.new = function(t)
|
|
local li = {}
|
|
li.type = 'lineitem'
|
|
li.cart_id = t.cart.id
|
|
li.item_id = t.item.id
|
|
li.quantity = t.quantity or 1
|
|
local item_record = t.item
|
|
local cart_record = t.cart
|
|
local user_record = lineitem.db:getrecord(cart_record.user_id)
|
|
li.price = item.priceof(item_record, user_record)
|
|
lineitem.db:insertrecord(li)
|
|
table.insert(cart_record.lineitem_ids, li.id)
|
|
cart_record:save()
|
|
return li
|
|
end
|
|
|
|
return lineitem |