Class: Spree::Admin::PosController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/admin/pos_controller.rb

Instance Method Summary collapse

Instance Method Details

#addObject



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.full_messages.to_sentence if @item.errors.present?
  redirect_to admin_pos_show_order_path(:number => @order.number) 
end

#apply_discountObject



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.full_messages.to_sentence if @item.errors.present?
  redirect_to admin_pos_show_order_path(:number => @order.number)
end

#associate_userObject



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.full_messages.to_sentence}"
  else
    @order.save!
    flash[:notice] = 'Successfully Associated User'
  end

  redirect_to admin_pos_show_order_path(:number => @order.number)
end

#clean_orderObject



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

#findObject



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

#newObject



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

#removeObject



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_quantityObject



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.full_messages.to_sentence if @item.errors.present?
  redirect_to admin_pos_show_order_path(:number => @order.number)
end

#update_paymentObject



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.full_messages.to_sentence
    redirect_to admin_pos_show_order_path(:number => @order.number)
  end
end

#update_stock_locationObject



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.full_messages.to_sentence
  end
  redirect_to admin_pos_show_order_path(:number => @order.number)
end