Sha256: d2a10ef5063637c637bb1061524069389f770a90537e8911fa61f63cc0501fff

Contents?: true

Size: 918 Bytes

Versions: 1

Compression:

Stored size: 918 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, 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.2 app/controllers/workarea/storefront/cart_bulk_items_controller.rb