Class: BasketsController
Instance Method Summary
collapse
#basket_edit_link, #has_receipt?
#clean_search, #require_admin
#error
#best_euros, #current_basket, #current_basket_or_nil, #current_clerk, #date, #euros, #has_ssl?, #markdown, #new_basket, #paginate, #shipping_method
Instance Method Details
#checkout ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/controllers/baskets_controller.rb', line 14
def checkout
if @basket.empty?
render :edit , :notice => t(:basket_empty)
return
end
order = @basket.kori || Order.new( :basket => @basket )
order.pos_checkout( current_clerk.email )
order.save!
if has_receipt?
redirect_to receipt_order_path(order)
else
redirect_to order_path(order)
end
end
|
#create ⇒ Object
114
115
116
117
118
119
120
121
|
# File 'app/controllers/baskets_controller.rb', line 114
def create
@basket = Basket.create(params_for_basket)
if @basket.save
redirect_to basket_path(@basket), :notice => t(:create_success, :model => "basket")
else
render :edit
end
end
|
#destroy ⇒ Object
130
131
132
133
134
135
136
137
138
139
|
# File 'app/controllers/baskets_controller.rb', line 130
def destroy
if @basket.locked?
flash.notice = t('basket_locked')
else
flash.notice = t('basket') + " " + t(:deleted)
@basket.destroy
end
redirect_to baskets_path
end
|
#discount ⇒ Object
refactor discount out of edit
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/controllers/baskets_controller.rb', line 66
def discount
if discount = params[:discount]
if i_id = params[:item]
item = @basket.items.find { |it| it.id.to_s == i_id }
item_discount( item , discount )
else
@basket.items.each do |it|
item_discount( it , discount )
end
end
@basket.save!
else
flash[:error] = "No discount given"
end
redirect_to office.edit_basket_path(@basket)
end
|
#ean ⇒ Object
ean search at the top of basket edit
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'app/controllers/baskets_controller.rb', line 84
def ean
return if redirect_if_locked
ean = params[:ean]
ean.sub!("P+" , "P-") if ean[0,2] == "P+"
prod = Product.find_by_ean ean
if(prod)
@basket.add_product prod
else
prod = Product.find_by_scode ean
if(prod)
@basket.add_product prod
else
redirect_to office.products_path(:q => {"name_or_product_name_cont"=> ean},:basket => @basket.id)
return
end
end
redirect_to office.edit_basket_path(@basket)
end
|
#edit ⇒ Object
104
105
106
107
108
109
110
111
112
|
# File 'app/controllers/baskets_controller.rb', line 104
def edit
return if redirect_if_locked
if p_id = (params[:add] || params[:delete])
add = params[:add].blank? ? -1 : 1
@basket.add_product Product.find(p_id) , add
flash.now.notice = params[:add] ? t('product_added') : t('item_removed')
end
@basket.save!
end
|
#index ⇒ Object
8
9
10
11
12
|
# File 'app/controllers/baskets_controller.rb', line 8
def index
@q = Basket.ransack( params[:q] )
@basket_scope = @q.result( :distinct => true )
@baskets = @basket_scope.includes({:items => :product} , :kori).paginate( :page => params[:page], :per_page => 20 )
end
|
#new ⇒ Object
60
61
62
63
|
# File 'app/controllers/baskets_controller.rb', line 60
def new
@basket = Basket.create!
render :edit
end
|
#order ⇒ Object
as an action this order is meant as a verb, ie order this basket
39
40
41
42
43
44
45
|
# File 'app/controllers/baskets_controller.rb', line 39
def order
if @basket.empty?
return render :edit , :notice => t(:basket_empty)
end
order = Order.create! :basket => @basket , :email => current_clerk.email , :ordered_on => Date.today
redirect_to order_path(order)
end
|
#purchase ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/baskets_controller.rb', line 47
def purchase
if @basket.empty?
render :edit , :notice => t(:basket_empty)
return
end
if @basket.locked
render :show , :notice => t(:basket_locked)
return
end
purchase = Purchase.create! :basket => @basket
redirect_to office.purchase_path(purchase)
end
|
#show ⇒ Object
29
30
31
|
# File 'app/controllers/baskets_controller.rb', line 29
def show
gon.basket_id = @basket.id
end
|
#update ⇒ Object
123
124
125
126
127
128
|
# File 'app/controllers/baskets_controller.rb', line 123
def update
return if redirect_if_locked
@basket.update_attributes(params_for_basket)
flash.notice = t(:update_success, :model => "basket")
redirect_to edit_basket_path(@basket)
end
|
#zero ⇒ Object
33
34
35
36
|
# File 'app/controllers/baskets_controller.rb', line 33
def zero
@basket.zero_prices!
render :edit
end
|