Class: Tienda::OrdersController

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

Instance Method Summary collapse

Instance Method Details

#acceptObject



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

def accept
  @order.accept!(current_user)
  redirect_to @order, notice: t('tienda.orders.accept_notice')
rescue Tienda::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/tienda/orders_controller.rb', line 17

def create
  Tienda::Order.transaction do
    @order = Tienda::Order.new(safe_params)
    @order.status = 'confirming'
    if !request.xhr? && @order.save
      @order.confirm!
      redirect_to @order, notice: t('tienda.orders.create_notice')
    else
      @order.order_items.build(ordered_item_type: 'Tienda::Product')
      render action: "new"
    end
  end
rescue Tienda::Errors::InsufficientStockToFulfil => e
  flash.now[:alert] = t('tienda.orders.insufficient_stock_order', out_of_stock_items: e.out_of_stock_items.map { |t| t.ordered_item.full_name }.to_sentence)
  render action: 'new'
end

#despatch_noteObject



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

def despatch_note
  render layout: 'tienda/printable'
end

#indexObject



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

def index
  @query = Tienda::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/tienda/orders_controller.rb', line 12

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

#rejectObject



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

def reject
  @order.reject!(current_user)
  redirect_to @order, notice: t('tienda.orders.reject_notice')
rescue Tienda::Errors::PaymentDeclined => e
  redirect_to @order, alert: e.message
end

#searchObject



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

def search
  index
  render action: "index"
end

#shipObject



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

def ship
  @order.ship!(params[:consignment_number], current_user)
  redirect_to @order, notice: t('tienda.orders.ship_notice')
end

#showObject



34
35
36
# File 'app/controllers/tienda/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/tienda/orders_controller.rb', line 38

def update
  @order.attributes = safe_params
  if !request.xhr? && @order.update_attributes(safe_params)
    redirect_to @order, notice: t('tienda.orders.update_notice')
  else
    render action: "edit"
  end
end