Class: Spree::Admin::CancellationsController

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

Instance Method Summary collapse

Methods included from SetsUserLanguageLocaleKey

#set_user_language_locale_key

Instance Method Details

#indexObject



8
9
10
# File 'app/controllers/spree/admin/cancellations_controller.rb', line 8

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

#short_shipObject



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

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] = t('spree.unable_to_find_all_inventory_units')
    redirect_to admin_order_cancellations_path(@order)
  elsif inventory_units.empty?
    flash[:error] = t('spree.no_inventory_selected')
    redirect_to admin_order_cancellations_path(@order)
  else
    @order.cancellations.short_ship(inventory_units, created_by:)

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