Class: CartController
Instance Method Summary
collapse
#get_login_link, #set_locale_with_config
Instance Method Details
#add_product ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'app/controllers/cart_controller.rb', line 15
def add_product
if params[:id]
current_cart.add_product_id( params[:id],1 )
redirect_to(:action => 'index')
else
redirect_to(:back)
end
end
|
#add_voucher ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'app/controllers/cart_controller.rb', line 70
def add_voucher
voucher = VoucherRule.find_by_id(current_cart.voucher)
if voucher.nil?
session.delete(:voucher_code)
render(:update) do |page|
page.replace_html 'voucher_message' , "<span>Le code promo #{@voucher_code} est invalide2.</span>"
page.replace_html 'tbody', :partial => 'tbody'
page.replace_html 'cart_total', :partial => 'total'
page.replace_html 'free_products', :partial => 'free_products'
end
else
session[:voucher_code] = voucher.code
render(:update) do |page|
page.replace_html 'voucher_message' , "<span>Code validé ! #{voucher.name}</span>"
page.replace_html 'tbody', :partial => 'tbody'
page.replace_html 'cart_total', :partial => 'total'
page.replace_html 'free_products', :partial => 'free_products'
end
end
end
|
#delete_product ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/controllers/cart_controller.rb', line 56
def delete_product
cart_product = current_cart.cart_items.find_by_id(params[:id])
current_cart.cart_items.find_all_by_product_id(cart_product.product_id).collect(&:delete) unless cart_product.nil?
current_cart.reload
special_offer
voucher
if request.xhr?
render(:update) do |page|
page.replace_html 'tbody', :partial => 'tbody'
page.replace_html 'cart_total', :partial => 'total'
end
end
end
|
#get_cart_items_count ⇒ Object
91
92
93
|
# File 'app/controllers/cart_controller.rb', line 91
def get_cart_items_count
render :text => "#{current_cart.cart_items.count} articles"
end
|
#index ⇒ Object
10
11
12
|
# File 'app/controllers/cart_controller.rb', line 10
def index
end
|
#update_quantity ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'app/controllers/cart_controller.rb', line 25
def update_quantity
cart_product = current_cart.cart_items.find_by_id(params[:id])
unless cart_product.nil?
new_quantity = params[:quantity].to_i
if cart_product.quantity < new_quantity if !cart_product.product.stop_sales
cart_product.update_attributes( :quantity => new_quantity )
elsif cart_product.product.stock >= new_quantity
cart_product.update_attributes( :quantity => new_quantity )
else
flash[:quantity_warning] = "Le stock disponible est insuffisant."
end
else cart_product.update_attributes( :quantity => new_quantity )
end
end
current_cart.reload
special_offer
voucher
if request.xhr?
render(:update) do |page|
page.replace_html 'tbody', :partial => 'tbody'
page.replace_html 'cart_total', :partial => 'total'
page.replace_html 'free_products', :partial => 'free_products'
end
end
end
|