Class: Spree::Admin::ShipmentsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/shipments_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/spree/admin/shipments_controller.rb', line 5

def index
  params[:q] ||= {}
  # params[:q][:completed_at_null] ||= '1'
  # @show_only_incomplete = params[:q][:completed_at_null].present?
  # params[:q][:s] ||= @show_only_incomplete ? 'created_at desc' : 'completed_at desc'

  # As date params are deleted if @show_only_incomplete, store
  # the original date so we can restore them into the params
  # after the search
  created_at_gt = params[:q][:created_at_gt]
  created_at_lt = params[:q][:created_at_lt]

  if !params[:q][:created_at_gt].blank?
    params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue ""
  end

  if !params[:q][:created_at_lt].blank?
    params[:q][:created_at_lt] = Time.zone.parse(params[:q][:created_at_lt]).end_of_day rescue ""
  end

  @search = Spree::Shipment.accessible_by(current_ability, :index).ransack(params[:q])
  @shipments = @search.result.
    page(params[:page]).
    per(params[:per_page] || Spree::Config[:orders_per_page])

  # Restore dates
  params[:q][:created_at_gt] = created_at_gt
  params[:q][:created_at_lt] = created_at_lt
end