Class: Admin::OrdersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::OrdersController
- Includes:
- Effective::CrudController
- Defined in:
- app/controllers/admin/orders_controller.rb
Instance Method Summary collapse
- #bulk_send_payment_request ⇒ Object
-
#checkout ⇒ Object
The show page posts to this action See Effective::OrdersController checkout.
- #create ⇒ Object
- #destroy ⇒ Object
- #send_payment_request ⇒ Object
Instance Method Details
#bulk_send_payment_request ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/admin/orders_controller.rb', line 111 def bulk_send_payment_request @orders = Effective::Order.not_purchased.where(id: params[:ids]) begin @orders.each { |order| order.send_payment_request_to_buyer! } render json: { status: 200, message: "Successfully sent #{@orders.length} payment request emails"} rescue => e render json: { status: 500, message: "Bulk send payment request error: #{e.}" } end end |
#checkout ⇒ Object
The show page posts to this action See Effective::OrdersController checkout
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/admin/orders_controller.rb', line 52 def checkout @order = Effective::Order.not_purchased.find(params[:id]) @page_title ||= 'Checkout' if request.get? @order.assign_confirmed_if_valid! render :checkout and return end Effective::Order.transaction do begin @order.assign_attributes(checkout_params) @order.confirm! redirect_to(effective_orders.checkout_admin_order_path(@order)) and return rescue => e raise ActiveRecord::Rollback end end flash.now[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again." render :checkout end |
#create ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/admin/orders_controller.rb', line 17 def create @user = current_user.class.find_by_id(order_params[:user_id]) @order = Effective::Order.new(user: @user) error = nil Effective::Order.transaction do begin (order_params[:order_items_attributes] || {}).each do |_, item_attrs| purchasable = Effective::Product.new(item_attrs[:purchasable_attributes]) @order.add(purchasable, quantity: item_attrs[:quantity]) end @order.attributes = order_params.except(:order_items_attributes, :user_id) @order.pending! = 'Successfully created order' << ". A request for payment has been sent to #{@order.emails_send_to}" if @order.send_payment_request_to_buyer? flash[:success] = redirect_to(admin_redirect_path) and return rescue => e error = e. raise ActiveRecord::Rollback end end @page_title = 'New Order' flash.now[:danger] = flash_danger(@order) + error.to_s render :new end |
#destroy ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/admin/orders_controller.rb', line 78 def destroy @order = Effective::Order.all.not_purchased.find(params[:id]) if @order.destroy flash[:success] = 'Successfully deleted order' else flash[:danger] = "Unable to delete order: #{@order.errors..to_sentence}" end redirect_to(effective_orders.admin_orders_path) end |
#send_payment_request ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/admin/orders_controller.rb', line 92 def send_payment_request @order = Effective::Order.not_purchased.find(params[:id]) if @order.send_payment_request_to_buyer! flash[:success] = "A request for payment has been sent to #{@order.emails_send_to}" else flash[:danger] = 'Unable to send payment request' end if respond_to?(:redirect_back) redirect_back(fallback_location: effective_orders.admin_order_path(@order)) elsif request.referrer.present? redirect_to :back else redirect_to effective_orders.admin_order_path(@order) end end |