Class: Effective::OrdersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Effective::OrdersController
- Includes:
- Concerns::Purchase, Providers::Cheque, Providers::Free, Providers::MarkAsPaid, Providers::Moneris, Providers::Paypal, Providers::Pretend, Providers::Refund, Providers::Stripe
- Defined in:
- app/controllers/effective/orders_controller.rb
Instance Method Summary collapse
- #bulk_send_buyer_receipt ⇒ Object
-
#create ⇒ Object
Confirms an order from the cart.
- #declined ⇒ Object
-
#edit ⇒ Object
Always step1.
-
#index ⇒ Object
My Orders History.
-
#new ⇒ Object
If you want to use the Add to Cart -> Checkout flow Add one or more items however you do.
-
#purchased ⇒ Object
Thank you for Purchasing this Order.
- #send_buyer_receipt ⇒ Object
-
#show ⇒ Object
If you want to use the order = Effective::Order.new(@thing); order.save! flow Add one or more items to the order.
-
#update ⇒ Object
Confirms the order from existing order.
Methods included from Providers::Stripe
Methods included from Providers::Refund
Methods included from Providers::Pretend
Methods included from Providers::Paypal
Methods included from Providers::Moneris
Methods included from Providers::MarkAsPaid
#mark_as_paid, #mark_as_paid_params
Methods included from Providers::Free
Methods included from Providers::Cheque
Instance Method Details
#bulk_send_buyer_receipt ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/controllers/effective/orders_controller.rb', line 136 def bulk_send_buyer_receipt @orders = Effective::Order.purchased.where(id: params[:ids]) begin EffectiveOrders.(self, :index, Effective::Order.new(user: current_user)) @orders.each do |order| next unless EffectiveOrders.(self, :show, order) order.send_order_receipt_to_buyer! end render json: { status: 200, message: "Successfully sent #{@orders.length} receipt emails"} rescue => e render json: { status: 500, message: "Bulk send buyer receipt error: #{e.message}" } end end |
#create ⇒ Object
Confirms an order from the cart.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/effective/orders_controller.rb', line 38 def create @order ||= Effective::Order.new(view_context.current_cart) EffectiveOrders.(self, :create, @order) @order.assign_attributes(checkout_params) if (@order.confirm! rescue false) redirect_to(effective_orders.order_path(@order)) else flash.now[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again." render :new end end |
#declined ⇒ Object
110 111 112 113 114 115 |
# File 'app/controllers/effective/orders_controller.rb', line 110 def declined @order = Effective::Order.find(params[:id]) EffectiveOrders.(self, :show, @order) redirect_to(effective_orders.order_path(@order)) unless @order.declined? end |
#edit ⇒ Object
Always step1
65 66 67 68 |
# File 'app/controllers/effective/orders_controller.rb', line 65 def edit @order ||= Effective::Order.find(params[:id]) EffectiveOrders.(self, :edit, @order) end |
#index ⇒ Object
My Orders History
86 87 88 89 90 91 |
# File 'app/controllers/effective/orders_controller.rb', line 86 def index @orders = Effective::Order.deep.purchased.where(user: current_user) @pending_orders = Effective::Order.deep.pending.where(user: current_user) EffectiveOrders.(self, :index, Effective::Order.new(user: current_user)) end |
#new ⇒ Object
If you want to use the Add to Cart -> Checkout flow Add one or more items however you do. redirect_to effective_orders.new_order_path, which is here. This is the entry point for any Checkout button. It displayes an order based on the cart Always step1
25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/effective/orders_controller.rb', line 25 def new @order ||= Effective::Order.new(view_context.current_cart) EffectiveOrders.(self, :new, @order) unless @order.valid? flash[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again." redirect_to(effective_orders.cart_path) return end end |
#purchased ⇒ Object
Thank you for Purchasing this Order. This is where a successfully purchased order ends up
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/controllers/effective/orders_controller.rb', line 94 def purchased # Thank You! @order = if params[:id].present? Effective::Order.find(params[:id]) elsif current_user.present? Effective::Order.sorted.purchased_by(current_user).last end if @order.blank? redirect_to(effective_orders.orders_path) and return end EffectiveOrders.(self, :show, @order) redirect_to(effective_orders.order_path(@order)) unless @order.purchased? end |
#send_buyer_receipt ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/controllers/effective/orders_controller.rb', line 117 def send_buyer_receipt @order = Effective::Order.find(params[:id]) EffectiveOrders.(self, :show, @order) if @order.send_order_receipt_to_buyer! flash[:success] = "A receipt has been sent to #{@order.user.email}" else flash[:danger] = "Unable to send receipt." end if respond_to?(:redirect_back) redirect_back(fallback_location: effective_orders.order_path(@order)) elsif request.referrer.present? redirect_to :back else redirect_to effective_orders.order_path(@order) end end |
#show ⇒ Object
If you want to use the order = Effective::Order.new(@thing); order.save! flow Add one or more items to the order. redirect_to effective_orders.order_path(order), which is here This is the entry point for an existing order. Might render step1 or step2
57 58 59 60 61 62 |
# File 'app/controllers/effective/orders_controller.rb', line 57 def show @order = Effective::Order.find(params[:id]) EffectiveOrders.(self, :show, @order) @page_title ||= ((@order.user == current_user && !@order.purchased?) ? 'Checkout' : @order.to_s) end |
#update ⇒ Object
Confirms the order from existing order
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/effective/orders_controller.rb', line 71 def update @order ||= Effective::Order.find(params[:id]) EffectiveOrders.(self, :update, @order) @order.assign_attributes(checkout_params) if (@order.confirm! rescue false) redirect_to(effective_orders.order_path(@order)) else flash.now[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again." render :edit end end |