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



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

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



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

def destroy
  @order.destroy
  redirect_to(forge_orders_path)
end

#editObject



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

def edit
end

#fulfillObject



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

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
# 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("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("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 {
      @orders = @orders.where("orders.id = ? OR orders.state = ? OR addresses.first_name LIKE ? OR addresses.last_name LIKE ? OR addresses.email like ?", params[:q], params[:q], "%#{params[:q]}%", "%#{params[:q]}%", "%#{params[:q]}%").includes(:shipping_address, :billing_address)
      render :partial => "order", :collection => @orders
    }
  end
end

#mark_fulfillment(opts = {}) ⇒ Object



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

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



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

def new
  @order = Order.new
end

#showObject



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

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

#unfulfillObject



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

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

#updateObject



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

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