Sha256: b10ad1322825a6c78f0c5e60c43ac3fccb520d1f9a5fc2bc7e3252969d334e9a

Contents?: true

Size: 1.52 KB

Versions: 24

Compression:

Stored size: 1.52 KB

Contents

module Spree
  module Admin
    class StockItemsController < Spree::Admin::BaseController
      before_action :determine_backorderable, only: :update

      def update
        stock_item.save
        respond_to do |format|
          format.js { head :ok }
        end
      end

      def create
        variant = Variant.find(params[:variant_id])
        stock_location = StockLocation.find(params[:stock_location_id])
        stock_movement = stock_location.stock_movements.build(stock_movement_params)
        stock_movement.stock_item = stock_location.set_up_stock_item(variant)

        if stock_movement.save
          flash[:success] = flash_message_for(stock_movement, :successfully_created)
        else
          flash[:error] = Spree.t(:could_not_create_stock_movement)
        end

        redirect_back fallback_location: spree.stock_admin_product_url(variant.product)
      end

      def destroy
        stock_item.destroy

        respond_with(@stock_item) do |format|
          format.html { redirect_back fallback_location: spree.stock_admin_product_url(stock_item.product) }
          format.js
        end
      end

      private
        def stock_movement_params
          params.require(:stock_movement).permit(permitted_stock_movement_attributes)
        end

        def stock_item
          @stock_item ||= StockItem.find(params[:id])
        end

        def determine_backorderable
          stock_item.backorderable = params[:stock_item].present? && params[:stock_item][:backorderable].present?
        end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
spree_backend-3.2.9 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.3.6 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.2.8 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.3.5 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.3.4 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.2.7 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.3.3 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.2.6 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.3.2 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.2.5 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.3.1 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.2.4 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.3.0 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.3.0.rc4 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.3.0.rc3 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.2.3 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.2.2 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.3.0.rc2 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.3.0.rc1 app/controllers/spree/admin/stock_items_controller.rb
spree_backend-3.2.1 app/controllers/spree/admin/stock_items_controller.rb