Class: Spree::Admin::PosController
- Inherits:
-
BaseController
- Object
- BaseController
- Spree::Admin::PosController
- Defined in:
- app/controllers/spree/admin/pos_controller.rb
Instance Method Summary collapse
- #add ⇒ Object
- #apply_discount ⇒ Object
- #associate_user ⇒ Object
- #clean_order ⇒ Object
- #find ⇒ Object
- #new ⇒ Object
- #remove ⇒ Object
- #update_line_item_quantity ⇒ Object
- #update_payment ⇒ Object
- #update_stock_location ⇒ Object
Instance Method Details
#add ⇒ Object
25 26 27 28 29 30 |
# File 'app/controllers/spree/admin/pos_controller.rb', line 25 def add @item = add_variant(@variant) if @variant.present? flash[:notice] = Spree.t('product_added') if @item.errors.blank? flash[:error] = @item.errors..to_sentence if @item.errors.present? redirect_to admin_pos_show_order_path(:number => @order.number) end |
#apply_discount ⇒ Object
48 49 50 51 52 53 |
# File 'app/controllers/spree/admin/pos_controller.rb', line 48 def apply_discount @item.price = @item.variant.price * ( 1.0 - @discount/100.0 ) @item.save flash[:error] = @item.errors..to_sentence if @item.errors.present? redirect_to admin_pos_show_order_path(:number => @order.number) end |
#associate_user ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/spree/admin/pos_controller.rb', line 60 def associate_user @user = @order.associate_user_for_pos(params[:email].present? ? params[:email] : params[:new_email]) if @user.errors.present? add_error "Could not add the user:#{@user.errors..to_sentence}" else @order.save! flash[:notice] = 'Successfully Associated User' end redirect_to admin_pos_show_order_path(:number => @order.number) end |
#clean_order ⇒ Object
55 56 57 58 |
# File 'app/controllers/spree/admin/pos_controller.rb', line 55 def clean_order @order.clean! redirect_to admin_pos_show_order_path(:number => @order.number), :notice => "Removed all items" end |
#find ⇒ Object
18 19 20 21 22 23 |
# File 'app/controllers/spree/admin/pos_controller.rb', line 18 def find init_search stock_location = @order.pos_shipment.stock_location @search = Spree::Variant.includes([:product]).available_at_stock_location(stock_location.id).ransack(params[:q]) @variants = @search.result(:distinct => true).page(params[:page]).per(PRODUCTS_PER_SEARCH_PAGE) end |
#new ⇒ Object
13 14 15 16 |
# File 'app/controllers/spree/admin/pos_controller.rb', line 13 def new init_pos redirect_to admin_pos_show_order_path(:number => @order.number) end |
#remove ⇒ Object
32 33 34 35 36 37 |
# File 'app/controllers/spree/admin/pos_controller.rb', line 32 def remove line_item = @order.contents.remove(@variant, 1, @order.pos_shipment) @order.assign_shipment_for_pos if @order.reload.pos_shipment.blank? flash.notice = line_item.quantity.zero? ? Spree.t('product_removed') : 'Quantity Updated' redirect_to admin_pos_show_order_path(:number => @order.number) end |
#update_line_item_quantity ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/controllers/spree/admin/pos_controller.rb', line 39 def update_line_item_quantity @item.quantity = params[:quantity] @item.save flash[:notice] = 'Quantity Updated' if @item.errors.blank? flash[:error] = @item.errors..to_sentence if @item.errors.present? redirect_to admin_pos_show_order_path(:number => @order.number) end |
#update_payment ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/spree/admin/pos_controller.rb', line 72 def update_payment @payment_method_id = params[:payment_method_id] @payment = @order.save_payment_for_pos(params[:payment_method_id], params[:card_name]) if @payment.errors.blank? print else add_error @payment.errors..to_sentence redirect_to admin_pos_show_order_path(:number => @order.number) end end |
#update_stock_location ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/spree/admin/pos_controller.rb', line 83 def update_stock_location @shipment = @order.pos_shipment @shipment.stock_location = user_stock_locations(spree_current_user).where(:id => params[:stock_location_id]).first if @shipment.save flash[:notice] = "Updated Successfully" else flash[:error] = @shipment.errors..to_sentence end redirect_to admin_pos_show_order_path(:number => @order.number) end |