kapilt / getpaid

Automatically exported from code.google.com/p/getpaid
0 stars 0 forks source link

negative quantity is allowed in the "Product Details" portlet #255

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I've noticed that to put a negative number in the form of footer of
the portlet "Product Details" doesn't give an error and allow to have
a cart with a negative price.

I first supposed that it could be avoided in
constraining  "quantity" to be a non negative number in the ILineItem
interface

but on the other hand when you put a string that can't be converted to
a number, an error is thrown -- ConversionErrror
at
       # check quantity from request
       qty = int(self.request.get('quantity', 1))
of browser/cart.py ---
 error that is not handled despite the fact that quantity is declared
in the interface as a number

Original issue reported on code.google.com by lucielej...@gmail.com on 17 Apr 2009 at 3:22

GoogleCodeExporter commented 8 years ago
In cart.py in def handle_update there is a raise statement
once deleted,
we can put qty = int(self.request.get('quantity', 1)) inside a try except
which solves the problem of a string that can't be converted to a number 
and finally we can by default set qty to 1 if a negative number is entered

--- 
src/Products.PloneGetPaid/Products/PloneGetPaid/browser/cart.py (révision 
156)
+++ src/Products.PloneGetPaid/Products/PloneGetPaid/browser/cart.py (copie de 
travail)
@@ -83,8 +83,15 @@
         item_factory = component.getMultiAdapter( (self.cart, self.context),
                                                 interfaces.ILineItemFactory )
         # check quantity from request
-        qty = int(self.request.get('quantity', 1))
+        qty=1
         try:
+            qty = int(self.request.get('quantity', 1))
+        except ValueError :
+            pass
+        finally:
+            if qty <0 :
+                qty = 1  
+        try:
             item_factory.create(quantity=qty)

         except interfaces.AddRecurringItemException:
@@ -316,6 +323,7 @@

     @form.action(_("Update"), condition="isNotEmpty")
     def handle_update( self, action, data ):
+        
         try:
             data = self.quantity_column.input(self.container.values(), self.request)
             self.form_reset = True
@@ -324,7 +332,6 @@
                 if self.container[item_id].quantity == 0:
                     del self.container[ item_id ]
         except:
-            raise
             self.form_reset = True
             #reset the form data in the request
             for i in self.request.form.keys():

Original comment by danielle...@gmail.com on 16 Dec 2010 at 2:28