Class: Accountability::OrderGroupsController
- Inherits:
-
AccountabilityController
- Object
- ApplicationController
- AccountabilityController
- Accountability::OrderGroupsController
- Defined in:
- app/controllers/accountability/order_groups_controller.rb
Instance Method Summary collapse
- #add_item ⇒ Object
- #checkout ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#add_item ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/accountability/order_groups_controller.rb', line 47 def add_item product = Product.find(params[:product_id]) source_scope = params.to_unsafe_h[:source_scope]&.symbolize_keys if @order_group.add_item! product, source_scope: source_scope redirect_to accountability_order_group_path(current_order_group), notice: 'Successfully added to cart' else redirect_back fallback_location: accountability_order_groups_path, alert: 'Failed to add to cart' end end |
#checkout ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/accountability/order_groups_controller.rb', line 58 def checkout @order_group.assign_account!(helpers.current_account) if @order_group.unassigned? if @order_group.checkout! redirect_to after_checkout_path(@order_group), notice: 'Checkout complete' else redirect_back fallback_location: accountability_order_group_path(@order_group), alert: 'Failed to check out' end end |
#create ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/accountability/order_groups_controller.rb', line 18 def create @order_group = params[:order_group].present? ? OrderGroup.new(order_group_params) : OrderGroup.new source_scope = params.to_unsafe_h[:source_scope]&.symbolize_keys if @order_group.save @order_group.add_item!(params[:product_id], source_scope: source_scope) if params[:product_id].present? redirect_to accountability_order_group_path(@order_group), notice: 'Successfully created new order_group' else redirect_back fallback_location: root_path, alert: 'Failed to create cart' end end |
#destroy ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/controllers/accountability/order_groups_controller.rb', line 39 def destroy if @order_group.destroy redirect_to accountability_order_groups_path, notice: 'Successfully destroyed order_group' else redirect_to accountability_order_groups_path, alert: 'There was an issue destroying order_group' end end |
#edit ⇒ Object
16 |
# File 'app/controllers/accountability/order_groups_controller.rb', line 16 def edit; end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/accountability/order_groups_controller.rb', line 6 def index @order_groups = OrderGroup.all end |
#new ⇒ Object
10 11 12 |
# File 'app/controllers/accountability/order_groups_controller.rb', line 10 def new redirect_to accountability_order_group_path(current_order_group) end |
#show ⇒ Object
14 |
# File 'app/controllers/accountability/order_groups_controller.rb', line 14 def show; end |
#update ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/controllers/accountability/order_groups_controller.rb', line 31 def update if @order_group.update(order_group_params) redirect_to accountability_order_groups_path, notice: 'Successfully updated order_group' else render :edit end end |