Class: Shoppe::OrdersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Shoppe::OrdersController
- Defined in:
- app/controllers/shoppe/orders_controller.rb
Instance Method Summary collapse
- #accept ⇒ Object
- #create ⇒ Object
- #despatch_note ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #reject ⇒ Object
- #search ⇒ Object
- #ship ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#accept ⇒ Object
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. end |
#create ⇒ Object
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_note ⇒ Object
71 72 73 |
# File 'app/controllers/shoppe/orders_controller.rb', line 71 def despatch_note render :layout => 'shoppe/printable' end |
#index ⇒ Object
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 |
#new ⇒ Object
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 |
#reject ⇒ Object
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. end |
#search ⇒ Object
47 48 49 50 |
# File 'app/controllers/shoppe/orders_controller.rb', line 47 def search index render :action => "index" end |
#ship ⇒ Object
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 |
#show ⇒ Object
34 35 36 |
# File 'app/controllers/shoppe/orders_controller.rb', line 34 def show @payments = @order.payments.to_a end |
#update ⇒ Object
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 |