Class: Shoppe::OrdersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/shoppe/orders_controller.rb

Instance Method Summary collapse

Instance Method Details

#acceptObject



52
53
54
55
56
57
# File 'app/controllers/shoppe/orders_controller.rb', line 52

def accept
  @order.accept!(current_user)
  redirect_to @order, :notice => "Order has been accepted successfully"
rescue Shoppe::Errors::PaymentDeclined => e
  redirect_to @order, :alert => e.message
end

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/shoppe/orders_controller.rb', line 17

def create
  Shoppe::Order.transaction do
    @order = Shoppe::Order.new(safe_params)
    @order.status = 'confirming'
    if !request.xhr? && @order.save
      @order.confirm!
      redirect_to @order, :notice => "Order has been created successfully"
    else
      @order.order_items.build(:ordered_item_type => 'Shoppe::Product')
      render :action => "new"
    end
  end
rescue Shoppe::Errors::InsufficientStockToFulfil => e
  flash.now[:alert] = "Insufficient stock to order #{e.out_of_stock_items.map { |t| t.ordered_item.full_name }.to_sentence}. Quantities have been updated to max total stock available."
  render :action => 'new'
end

#despatch_noteObject



71
72
73
# File 'app/controllers/shoppe/orders_controller.rb', line 71

def despatch_note
  render :layout => 'shoppe/printable'
end

#indexObject



7
8
9
10
# File 'app/controllers/shoppe/orders_controller.rb', line 7

def index
  @query = Shoppe::Order.ordered.received.includes(:order_items => :ordered_item).page(params[:page]).search(params[:q])
  @orders = @query.result
end

#newObject



12
13
14
15
# File 'app/controllers/shoppe/orders_controller.rb', line 12

def new
  @order = Shoppe::Order.new
  @order.order_items.build(:ordered_item_type => 'Shoppe::Product')
end

#rejectObject



59
60
61
62
63
64
# File 'app/controllers/shoppe/orders_controller.rb', line 59

def reject
  @order.reject!(current_user)
  redirect_to @order, :notice => "Order has been rejected successfully"
rescue Shoppe::Errors::PaymentDeclined => e
  redirect_to @order, :alert => e.message
end

#searchObject



47
48
49
50
# File 'app/controllers/shoppe/orders_controller.rb', line 47

def search
  index
  render :action => "index"
end

#shipObject



66
67
68
69
# File 'app/controllers/shoppe/orders_controller.rb', line 66

def ship
  @order.ship!(params[:consignment_number], current_user)
  redirect_to @order, :notice => "Order has been shipped successfully"
end

#showObject



34
35
36
# File 'app/controllers/shoppe/orders_controller.rb', line 34

def show
  @payments = @order.payments.to_a
end

#updateObject



38
39
40
41
42
43
44
45
# File 'app/controllers/shoppe/orders_controller.rb', line 38

def update
  @order.attributes = safe_params
  if !request.xhr? && @order.update_attributes(safe_params)
    redirect_to @order, :notice => "Order has been saved successfully"
  else
    render :action => "edit"
  end
end