Last active
August 30, 2019 10:05
-
-
Save servzin/cdf48f9ccf8fba9c75303a8635a7bc6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("Too many items in the basket") | |
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 is added to the basket: #{@item.title}</h1>" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment