Skip to content

Instantly share code, notes, and snippets.

@Mehonoshin
Forked from servzin/test.rb
Created October 24, 2016 12:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 24 You must be signed in to fork a gist
  • Save Mehonoshin/4c239ea364fe458ef844e3984b757cf6 to your computer and use it in GitHub Desktop.
Save Mehonoshin/4c239ea364fe458ef844e3984b757cf6 to your computer and use it in GitHub Desktop.
class BasketController
def add_to_basket
item = Item.find_by_title(params[:item_title])
basket = $basket
basket.add_item(item)
if basket.count_items > 10
basket.error_messages.add("Слишком много товаров в корзине")
end
total = 0
basket.items.each do |basket_item|
total += basket_item.price
end
session[:basket_total] = total
query = "INSERT INTO basket_items (basket_id, item_title, basket_type) VALUES '" +
(:basket=>basket_id.to_s) +
"', '" + params[:item_title] + "', 3)"
results = ActiveRecord::Base.connection.execute(query)
Basket.add_free_delivery(basket)
return "<h1>Добавлен товар в корзину: #{@item.title}</h1>"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment