Class: Effective::CartsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Effective::CartsController
- Includes:
- CrudController
- Defined in:
- app/controllers/effective/carts_controller.rb
Instance Method Summary collapse
Instance Method Details
#add_to_cart ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/effective/carts_controller.rb', line 33 def add_to_cart @purchasable = (add_to_cart_params[:purchasable_type].constantize.find(add_to_cart_params[:purchasable_id].to_i) rescue nil) EffectiveResources.(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
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/effective/carts_controller.rb', line 19 def destroy @cart = current_cart EffectiveResources.(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
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/effective/carts_controller.rb', line 52 def remove_from_cart @cart_item = current_cart.cart_items.find(remove_from_cart_params[:id]) EffectiveResources.(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 |