Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save denysonique/885463 to your computer and use it in GitHub Desktop.
Save denysonique/885463 to your computer and use it in GitHub Desktop.
def add_line_item_to_cart
#Get current_cart object
current_cart
quantity = params[:quantity].to_i
id = params[:id].to_i
line_item = LineItem.find(:first, :conditions => {:cartridge_id => id, :cart_id => current_cart.id})
if line_item
line_item.cart_id = current_cart.id
line_item.quantity += quantity
else
line_item = LineItem.new
line_item.cartridge_id = id
line_item.cart_id = current_cart.id
line_item.quantity = quantity
end
line_item.save
render :text => current_cart.line_items.count.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment