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
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 74 |
# File 'app/controllers/effective/orders_controller.rb', line 35 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.message}" raise ActiveRecord::Rollback end end render :action => :new end |
#declined ⇒ Object
An error has occurred, please try again
112 113 114 115 |
# File 'app/controllers/effective/orders_controller.rb', line 112 def declined # An error occurred! @order = Order.find(params[:id]) EffectiveOrders.(self, :show, @order) end |
#index ⇒ Object
86 87 88 |
# File 'app/controllers/effective/orders_controller.rb', line 86 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
92 93 94 95 96 |
# File 'app/controllers/effective/orders_controller.rb', line 92 def my_purchases @orders = Order.purchased_by(current_user) EffectiveOrders.(self, :index, Effective::Order) end |
#my_sales ⇒ Object
Sales is a list of what products beign sold by me have been purchased
99 100 101 102 103 |
# File 'app/controllers/effective/orders_controller.rb', line 99 def my_sales @order_items = OrderItem.sold_by(current_user) EffectiveOrders.(self, :index, Effective::Order) end |
#new ⇒ Object
This is the entry point for the "Checkout" buttons
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/effective/orders_controller.rb', line 17 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
130 131 132 133 134 135 136 |
# File 'app/controllers/effective/orders_controller.rb', line 130 def pretend_purchase if (Rails.env.development? || Rails.env.test?) || EffectiveOrders.allow_pretend_purchase_in_production @order = Order.find(params[:id]) EffectiveOrders.(self, :update, @order) 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
106 107 108 109 |
# File 'app/controllers/effective/orders_controller.rb', line 106 def purchased # Thank You! @order = Order.find(params[:id]) EffectiveOrders.(self, :show, @order) end |
#resend_buyer_receipt ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/effective/orders_controller.rb', line 117 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
76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/effective/orders_controller.rb', line 76 def show @order = Order.find(params[:id]) EffectiveOrders.(self, :show, @order) if @order.purchased? == false @page_title = 'Checkout' render(:checkout) and return end end |