Class: Corzinus::OrderItemsController
Instance Method Summary
collapse
Methods included from Flashable
#flash_render
#authenticate_corzinus_person!, #current_order, #current_person
Instance Method Details
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|