Class: Corzinus::OrderItemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/corzinus/order_items_controller.rb

Instance Method Summary collapse

Methods included from Flashable

#flash_render

Methods included from Controllable

#authenticate_corzinus_person!, #current_order, #current_person

Instance Method Details

#createObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/corzinus/order_items_controller.rb', line 3

def create
  AddOrderItem.call(current_order, params) do
    on(:valid) do |quantity|
      flash[:notice] = t('corzinus.flash.success.product_add',
                         count: quantity)
    end
    on(:invalid) do |errors|
      flash[:alert] = t('corzinus.flash.failure.product_add',
                        errors: errors)
    end
  end
  redirect_back(fallback_location: root_path)
end

#destroyObject



17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/corzinus/order_items_controller.rb', line 17

def destroy
  order_item = OrderItem.find(params[:id])
  if order_item.destroy && current_order.save
    flash[:notice] = t('corzinus.flash.success.product_destroy',
                       title: order_item.productable.title)
  else
    flash[:alert] = t('corzinus.flash.failure.product_destroy',
                      errors: order_item.decorate.all_errors)
  end
  redirect_back(fallback_location: edit_cart_path)
end