Class: Workarea::Storefront::CartItemsController

Inherits:
ApplicationController show all
Includes:
CheckInventory, CheckPricingOverride
Defined in:
app/controllers/workarea/storefront/cart_items_controller.rb

Instance Method Summary collapse

Methods included from CheckPricingOverride

#check_pricing_override

Methods included from CheckInventory

#check_inventory

Methods inherited from ApplicationController

#current_layout, #current_user_info, #health_check, #layout_content

Methods included from OrderLookup

#lookup_order, #lookup_order=

Methods included from CurrentCheckout

#clear_current_order, #completed_order, #completed_order=, #current_checkout, #current_order, #current_order=, #current_shipping, #current_shippings, #logout

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/workarea/storefront/cart_items_controller.rb', line 13

def create
  # TODO: for v4, use AddItemToCart for this.
  if current_order.add_item(item_params.to_h.merge(item_details.to_h))
    check_inventory

    Pricing.perform(current_order, current_shippings)

    @cart = CartViewModel.new(current_order, view_model_options)
    @item = OrderItemViewModel.wrap(
      current_order.items.find_existing(
        item_params[:sku],
        item_params[:customizations].to_h
      ),
      view_model_options
    )
  end
end

#destroyObject



40
41
42
43
44
# File 'app/controllers/workarea/storefront/cart_items_controller.rb', line 40

def destroy
  current_order.remove_item(params[:id])
  flash[:success] = t('workarea.storefront.flash_messages.cart_item_removed')
  redirect_to cart_path
end

#updateObject



31
32
33
34
35
36
37
38
# File 'app/controllers/workarea/storefront/cart_items_controller.rb', line 31

def update
  update_params = params.permit(:sku, :quantity).to_h
  update_params.merge!(item_details.to_h) if params[:sku].present?

  current_order.update_item(params[:id], update_params)
  flash[:success] = t('workarea.storefront.flash_messages.cart_item_updated')
  redirect_to cart_path
end