Class: Spree::Admin::CancellationsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/admin/cancellations_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



6
7
8
# File 'app/controllers/spree/admin/cancellations_controller.rb', line 6

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

#short_shipObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/spree/admin/cancellations_controller.rb', line 10

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