Sha256: 21bf8ede72329b6fa0de62b6520a801e54fcaceff669e585b0589d4579944963

Contents?: true

Size: 925 Bytes

Versions: 1

Compression:

Stored size: 925 Bytes

Contents

module Workarea
  module Storefront
    class CartBulkItemsController < ApplicationController
      include CheckInventory

      skip_before_action :verify_authenticity_token

      def create
        add_to_cart = AddMultipleCartItems.new(
          current_order,
          params[:items].map(&:to_unsafe_h).select { |p| p[:quantity].to_i.positive? }
        )

        if add_to_cart.perform!
          check_inventory
          Pricing.perform(current_order, current_shippings)

          @cart = CartViewModel.new(current_order, view_model_options)
          @items = add_to_cart.items.map do |cart_item|
            OrderItemViewModel.wrap(cart_item.item.reload, view_model_options)
          end
        else
          flash[:error] =
            t('workarea.storefront.flash_messages.cart_bulk_items_error')
          redirect_to product_path(add_to_cart.items.first.product)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-variant_list-1.0.3 app/controllers/workarea/storefront/cart_bulk_items_controller.rb