Class: Effective::OrdersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Effective::OrdersController
- Includes:
- Providers::Moneris, Providers::Paypal, Providers::Stripe, Providers::StripeConnect, EffectiveCartsHelper
- Defined in:
- app/controllers/effective/orders_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#declined ⇒ Object
An error has occurred, please try again.
- #index ⇒ Object
-
#my_purchases ⇒ Object
Basically an index page.
-
#my_sales ⇒ Object
Sales is a list of what products beign sold by me have been purchased.
-
#new ⇒ Object
This is the entry point for the “Checkout” buttons.
- #pretend_purchase ⇒ Object
-
#purchased ⇒ Object
Thank you for Purchasing this Order.
- #resend_buyer_receipt ⇒ Object
- #show ⇒ Object
Methods included from Providers::StripeConnect
Methods included from Providers::Stripe
Methods included from Providers::Paypal
Methods included from Providers::Moneris
Methods included from EffectiveCartsHelper
#current_cart, #link_to_add_to_cart, #link_to_checkout, #link_to_current_cart, #link_to_empty_cart, #link_to_remove_from_cart, #render_cart, #render_purchasables
Instance Method Details
#create ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/effective/orders_controller.rb', line 34 def create @order ||= Order.new(current_cart, current_user) @order.attributes = order_params if EffectiveOrders.require_shipping_address if @order.shipping_address_same_as_billing? && @order.billing_address.present? @order.shipping_address = @order.billing_address end end EffectiveOrders.(self, :create, @order) Effective::Order.transaction do begin if @order.save_billing_address? && @order.user.respond_to?(:billing_address) && @order.billing_address.try(:empty?) == false @order.user.billing_address = @order.billing_address end if @order.save_shipping_address? && @order.user.respond_to?(:shipping_address) && @order.shipping_address.try(:empty?) == false @order.user.shipping_address = @order.shipping_address end @order.save! if @order.total == 0 && EffectiveOrders.allow_free_orders order_purchased('zero-dollar order') else redirect_to(effective_orders.order_path(@order)) end return rescue => e Rails.logger.info e. flash.now[:danger] = "An error has ocurred. Please try again. Message: #{e.}" raise ActiveRecord::Rollback end end render :action => :new end |
#declined ⇒ Object
An error has occurred, please try again
109 110 111 112 |
# File 'app/controllers/effective/orders_controller.rb', line 109 def declined # An error occurred! @order = Order.find(params[:id]) EffectiveOrders.(self, :show, @order) end |
#index ⇒ Object
85 86 87 |
# File 'app/controllers/effective/orders_controller.rb', line 85 def index redirect_to effective_orders.my_purchases_path end |
#my_purchases ⇒ Object
Basically an index page. Purchases is an Order History page. List of purchased orders
91 92 93 94 |
# File 'app/controllers/effective/orders_controller.rb', line 91 def my_purchases @orders = Order.purchased_by(current_user) EffectiveOrders.(self, :index, Effective::Order.new(user: current_user)) end |
#my_sales ⇒ Object
Sales is a list of what products beign sold by me have been purchased
97 98 99 100 |
# File 'app/controllers/effective/orders_controller.rb', line 97 def my_sales @order_items = OrderItem.sold_by(current_user) EffectiveOrders.(self, :index, Effective::Order.new(user: current_user)) end |
#new ⇒ Object
This is the entry point for the “Checkout” buttons
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/effective/orders_controller.rb', line 16 def new @order ||= Order.new(current_cart, current_user) EffectiveOrders.(self, :new, @order) # We're only going to check for a subset of errors on this step, # with the idea that we don't want to create an Order object if the Order is totally invalid @order.valid? if @order.errors[:order_items].present? flash[:danger] = @order.errors[:order_items].first redirect_to effective_orders.cart_path elsif @order.errors[:total].present? flash[:danger] = @order.errors[:total].first.gsub(EffectiveOrders.minimum_charge.to_i.to_s, view_context.price_to_currency(EffectiveOrders.minimum_charge.to_i)) redirect_to effective_orders.cart_path end end |
#pretend_purchase ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/controllers/effective/orders_controller.rb', line 127 def pretend_purchase @order = Order.find(params[:id]) EffectiveOrders.(self, :update, @order) if (Rails.env.production? == false && EffectiveOrders.allow_pretend_purchase_in_development) order_purchased('for pretend', params[:purchased_redirect_url], params[:declined_redirect_url]) end if (Rails.env.production? == true && EffectiveOrders.allow_pretend_purchase_in_production) order_purchased('for pretend', params[:purchased_redirect_url], params[:declined_redirect_url]) end end |
#purchased ⇒ Object
Thank you for Purchasing this Order. This is where a successfully purchased order ends up
103 104 105 106 |
# File 'app/controllers/effective/orders_controller.rb', line 103 def purchased # Thank You! @order = Order.find(params[:id]) EffectiveOrders.(self, :show, @order) end |
#resend_buyer_receipt ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/controllers/effective/orders_controller.rb', line 114 def resend_buyer_receipt @order = Effective::Order.find(params[:id]) EffectiveOrders.(self, :show, @order) if @order.send_order_receipt_to_buyer! flash[:success] = "Successfully resent order receipt to #{@order.user.email}" else flash[:danger] = "Unable to send order receipt" end redirect_to(:back) rescue effective_orders.order_path(@order) end |
#show ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/effective/orders_controller.rb', line 75 def show @order = Order.find(params[:id]) EffectiveOrders.(self, :show, @order) if @order.purchased? == false @page_title = 'Checkout' render(:checkout) and return end end |