Class: Admin::OrdersController
- Inherits:
-
BaseController
- Object
- BaseController
- Admin::OrdersController
- Includes:
- Ruleby
- Defined in:
- app/controllers/admin/orders_controller.rb
Instance Method Summary collapse
- #accept ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #get_product ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #pay ⇒ Object
- #sent ⇒ Object
- #show ⇒ Object
- #total ⇒ Object
- #update ⇒ Object
Instance Method Details
#accept ⇒ Object
95 96 97 |
# File 'app/controllers/admin/orders_controller.rb', line 95 def accept flash[:notice] = t('order.accept.success').capitalize if @order.accept! == true end |
#create ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/admin/orders_controller.rb', line 53 def create if @order.save flash[:notice] = t('order.create.success').capitalize redirect_to([forgeos_commerce, :edit, :admin, @order]) else flash[:error] = t('order.create.failed').capitalize render(:action => 'edit') end end |
#destroy ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/admin/orders_controller.rb', line 77 def destroy if @order.destroy flash[:notice] = t('order.destroy.success').capitalize else flash[:error] = t('order.destroy.failed').capitalize end respond_to do |wants| wants.html do redirect_to([forgeos_commerce, :admin, :orders]) end wants.js end end |
#edit ⇒ Object
63 64 |
# File 'app/controllers/admin/orders_controller.rb', line 63 def edit end |
#get_product ⇒ Object
103 104 105 106 107 108 109 |
# File 'app/controllers/admin/orders_controller.rb', line 103 def get_product product = Product.find_by_id(params[:product_id]) @products = Product.all render(:partial => 'form_details', :locals => { :order_detail => OrdersDetail.new( { :name => product.name, :description => product.description, :price => product.price, :rate_tax => product.rate_tax } ), :products => @products }) end |
#index ⇒ Object
11 12 13 14 15 16 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 |
# File 'app/controllers/admin/orders_controller.rb', line 11 def index respond_to do |format| format.html format.json do sort render(:layout => false) end format.csv do params[:iDisplayLength] = 1000000 sort csv_string = FasterCSV.generate({:force_quotes => true}) do |csv| titles = ['user'] titles << 'user mail' titles << 'total' @orders.first.attributes.keys.collect{ |key| titles << key } csv << titles @orders.each do |record| values = [record.user.fullname] values << record.user.email values << record.total() record.attributes.values.collect{ |val| values << val } csv << values end end send_data csv_string, :type => 'text/csv; charset=utf-8; header=present', :disposition => "attachment; filename=#{controller_name}.csv" end end end |
#new ⇒ Object
49 50 51 |
# File 'app/controllers/admin/orders_controller.rb', line 49 def new render(:action => 'create') end |
#pay ⇒ Object
91 92 93 |
# File 'app/controllers/admin/orders_controller.rb', line 91 def pay flash[:notice] = t('order.pay.success').capitalize if @order.pay! == true end |
#sent ⇒ Object
99 100 101 |
# File 'app/controllers/admin/orders_controller.rb', line 99 def sent flash[:notice] = t('order.send.success').capitalize if @order.start_shipping! == true end |
#show ⇒ Object
46 47 |
# File 'app/controllers/admin/orders_controller.rb', line 46 def show end |
#total ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/controllers/admin/orders_controller.rb', line 111 def total if @order.nil? @order = Order.new @order.order_shipping = OrderShipping.new end # clone order and order_shipping editing_order = @order.clone editing_order.order_shipping = @order.order_shipping.clone # get order_details ids if order_details = params[:order][:order_details_attributes] detail_ids = order_details.values.collect{ |detail| detail['id'].to_i if detail['id'] && detail['_destroy'].to_i != 1 }.uniq.compact editing_order.order_detail_ids = detail_ids end # update attributes for order and order_shipping editing_order.attributes = params[:order] editing_order.order_shipping.attributes = params[:order][:order_shipping_attributes] @transporter_ids = [] if params[:transporter][:rebuild].to_i == 1 # get new available transporters @order = editing_order engine :transporter_engine do |e| rule_builder = Transporter.new(e) rule_builder.transporter_ids = @transporter_ids rule_builder.order = @order rule_builder.rules @order.order_details.each do |order_detail| e.assert order_detail.product end e.assert @order e.match end end @available_transporters = TransporterRule.find_all_by_id(@transporter_ids.uniq) #total(with_tax=false, with_currency=true,with_shipping=true,with_special_offer=false) # calculate total, subtotal and taxes total = editing_order.total subtotal = editing_order.total(false,true,false,false,false) #taxes = editing_order.taxes return render(:json => { :result => 'success', :id => @order.id, :total => total, :subtotal => subtotal, :available_transporters => @available_transporters, :rebuild_transporter => params[:transporter][:rebuild].to_i}) #, :taxes => taxes} end |
#update ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/admin/orders_controller.rb', line 66 def update if @order.update_attributes(params[:order]) flash[:notice] = t('order.update.success').capitalize return render(:text => true) if request.xhr? else flash[:error] = t('order.update.failed').capitalize return render(:text => false) if request.xhr? end render(:action => 'edit') end |