Class: Forge::OrdersController

Inherits:
ForgeController show all
Defined in:
lib/forge/app/controllers/forge/orders_controller.rb

Instance Method Summary collapse

Methods inherited from ForgeController

#get_menu_items, #load_help, #set_crumbs, #set_title, #uses_ckeditor

Methods inherited from ApplicationController

#app_init

Instance Method Details

#createObject



32
33
34
35
36
37
38
39
40
# File 'lib/forge/app/controllers/forge/orders_controller.rb', line 32

def create
  @order = Order.new(params[:order])
  if @order.save
    flash[:notice] = 'Order was successfully created.'
    redirect_to(forge_orders_path)
  else
    render :action => "new"
  end
end

#destroyObject



72
73
74
75
# File 'lib/forge/app/controllers/forge/orders_controller.rb', line 72

def destroy
  @order.destroy
  redirect_to(forge_orders_path)
end

#editObject



29
30
# File 'lib/forge/app/controllers/forge/orders_controller.rb', line 29

def edit
end

#fulfillObject



51
52
53
# File 'lib/forge/app/controllers/forge/orders_controller.rb', line 51

def fulfill
  mark_fulfillment(:action => "fulfill!", :success => "Order marked as fulfilled", :failure => "Error marking as fulfilled")
end

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/forge/app/controllers/forge/orders_controller.rb', line 4

def index
  conditions = {"fulfill" => '=', "unfulfill" => '<>'}
  unless params[:show].nil?
    @orders = Order.not_pending.where("state #{conditions[params[:show]]} 'fulfilled'").order("orders.created_at DESC") #note that this safe from injection, any params[:show] that isn't "fulfill" or nil will just return false
  else
    @orders = Order.not_pending.order("orders.created_at DESC")
  end
  respond_to do |format|
    format.html { @orders = @orders.paginate(:per_page => 10, :page => params[:page]).includes(:shipping_address, :billing_address) }
    format.js {
      params[:q] ||= ''
      @orders = @orders.where("orders.id = ? OR orders.state = ? OR LOWER(addresses.first_name) LIKE ? OR LOWER(addresses.last_name) LIKE ? OR LOWER(addresses.email) LIKE ?", params[:q].to_i, params[:q], "%#{params[:q].downcase}%", "%#{params[:q].downcase}%", "%#{params[:q].downcase}%").includes(:shipping_address, :billing_address)
      render :partial => "order", :collection => @orders
    }
  end
end

#mark_fulfillment(opts = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/forge/app/controllers/forge/orders_controller.rb', line 59

def mark_fulfillment(opts = {})
  order = Order.find(params[:id])
  respond_to do |format|
    if order.send(opts[:action])
      format.js { render :nothing => true }
      format.html { flash[:notice] = opts[:success] and redirect_to forge_orders_path }
    else
      format.js { render :status => 500 }
      format.html { flash[:warning] = opts[:failure] and redirect_to forge_orders_path }
    end
  end
end

#newObject



21
22
23
# File 'lib/forge/app/controllers/forge/orders_controller.rb', line 21

def new
  @order = Order.new
end

#showObject



25
26
27
# File 'lib/forge/app/controllers/forge/orders_controller.rb', line 25

def show
  @order = Order.find(params[:id])
end

#unfulfillObject



55
56
57
# File 'lib/forge/app/controllers/forge/orders_controller.rb', line 55

def unfulfill
  mark_fulfillment(:action => "unfulfill!", :success => "Order no longer marked as fulfilled.", :failure => "Error marking as unfulfilled")
end

#updateObject



42
43
44
45
46
47
48
49
# File 'lib/forge/app/controllers/forge/orders_controller.rb', line 42

def update
  if @order.update_attributes(params[:order])
    flash[:notice] = 'Order was successfully updated.'
    redirect_to(forge_orders_path)
  else
    render :action => "edit"
  end
end