My favorites
▼
|
Sign in
substruct
Open-source Ruby on Rails E-Commerce
Project Home
Downloads
Wiki
Issues
Source
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
151
attachment: substruct_issue_151_patch
(1.7 KB)
1
2
3
4
5
6
7
8
9
10
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
45
46
47
48
49
Index: test/functional/store_controller_test.rb
===================================================================
--- test/functional/store_controller_test.rb (revision 163)
+++ test/functional/store_controller_test.rb (working copy)
@@ -184,6 +184,12 @@
a_cart = assigns(:order)
# It should not have added anything.
assert_equal a_cart.items.length, 2
+
+ # Try adding a product with a non-numerical quantity
+ a_product = items(:towel)
+ xhr(:post, :add_to_cart_ajax, :id => a_product.id, :quantity => "a")
+ a_cart = assigns(:order)
+ assert_equal a_cart.items.length, 1
end
Index: app/controllers/store_controller.rb
===================================================================
--- app/controllers/store_controller.rb (revision 163)
+++ app/controllers/store_controller.rb (working copy)
@@ -173,19 +173,23 @@
else
product = Product.find(params[:id])
end
- quantity = params[:quantity]
- quantity ||= 1
+ begin
+ quantity = params[:quantity].to_int
+ rescue NoMethodError
+ quantity = (params[:quantity].to_i != 0) ? params[:quantity].to_i : 1
+ end
+
logger.info "QUANTITY: #{quantity}"
logger.info "PRODUCT QUANTITY: #{product.quantity}"
logger.info "Quantity too much? #{(quantity.to_i > product.quantity.to_i)}"
# Checks quantity against available.
- if quantity.to_i > product.quantity.to_i
+ if quantity > product.quantity.to_i
logger.info "There's an error adding to the cart..."
render :nothing => true, :status => 400 and return
else
- @order.add_product(product, quantity.to_i)
+ @order.add_product(product, quantity)
logger.info "Product added...success"
render :partial => 'cart' and return
end
Powered by
Google Project Hosting