Class: Effective::CartsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Effective::CartsController
- Defined in:
- app/controllers/effective/carts_controller.rb
Instance Method Summary collapse
Instance Method Details
#add_to_cart ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/effective/carts_controller.rb', line 29 def add_to_cart @purchasable = (add_to_cart_params[:purchasable_type].constantize.find(add_to_cart_params[:purchasable_id].to_i) rescue nil) EffectiveOrders.(self, :update, current_cart) begin raise "Please select a valid #{add_to_cart_params[:purchasable_type] || 'item' }." unless @purchasable current_cart.add(@purchasable, quantity: [add_to_cart_params[:quantity].to_i, 1].max) flash[:success] = 'Successfully added item to cart.' rescue EffectiveOrders::SoldOutException flash[:warning] = 'This item is sold out.' rescue => e flash[:danger] = 'Unable to add item to cart: ' + e. end redirect_back_or_to_cart end |
#destroy ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/effective/carts_controller.rb', line 15 def destroy @cart = current_cart EffectiveOrders.(self, :destroy, @cart) if @cart.destroy flash[:success] = 'Successfully emptied cart.' else flash[:danger] = 'Unable to destroy cart.' end redirect_back_or_to_cart end |
#remove_from_cart ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/effective/carts_controller.rb', line 48 def remove_from_cart @cart_item = current_cart.cart_items.find(remove_from_cart_params[:id]) EffectiveOrders.(self, :update, current_cart) if @cart_item.destroy flash[:success] = 'Successfully removed item from cart.' else flash[:danger] = 'Unable to remove item from cart.' end redirect_back_or_to_cart end |
#show ⇒ Object
7 8 9 10 11 12 13 |
# File 'app/controllers/effective/carts_controller.rb', line 7 def show @cart = current_cart @pending_orders = Effective::Order.not_purchased.where(user: current_user) if current_user.present? @page_title ||= 'My Cart' EffectiveOrders.(self, :show, @cart) end |