Sha256: 3c76ffeb05884b49efde12680bddb071c495da190d6ac9f36f8a889be8a6519f

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

module Spree
  module Admin
    class CancellationsController < Spree::Admin::BaseController
      before_filter :load_order, only: [:index, :short_ship]

      def index
        @inventory_units = @order.inventory_units.cancelable
      end

      def short_ship
        inventory_unit_ids = params[:inventory_unit_ids] || []
        inventory_units = Spree::InventoryUnit.where(id: inventory_unit_ids)

        if inventory_units.size != inventory_unit_ids.size
          flash[:error] = Spree.t(:unable_to_find_all_inventory_units)
          redirect_to admin_order_cancellations_path(@order)
        elsif inventory_units.empty?
          flash[:error] = Spree.t(:no_inventory_selected)
          redirect_to admin_order_cancellations_path(@order)
        else
          @order.cancellations.short_ship(inventory_units, whodunnit: whodunnit)

          flash[:success] = Spree.t(:inventory_canceled)
          redirect_to edit_admin_order_url(@order)
        end
      end

      private

      def whodunnit
        try_spree_current_user.try(:email)
      end

      def load_order
        @order = Order.find_by_number!(params[:order_id])
        authorize! action, @order
      end

      def model_class
        Spree::OrderCancellations
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
solidus_backend-1.3.2 app/controllers/spree/admin/cancellations_controller.rb
solidus_backend-1.3.1 app/controllers/spree/admin/cancellations_controller.rb
solidus_backend-1.3.0 app/controllers/spree/admin/cancellations_controller.rb
solidus_backend-1.3.0.rc2 app/controllers/spree/admin/cancellations_controller.rb
solidus_backend-1.3.0.rc1 app/controllers/spree/admin/cancellations_controller.rb
solidus_backend-1.3.0.beta1 app/controllers/spree/admin/cancellations_controller.rb