Commits

Maciej Wiśniowski  committed fa8cb1a

added property to values returned by get_properties methods; fixed price calculation for float property fields

  • Participants
  • Parent commits 7caa0a6

Comments (0)

Files changed (4)

File lfs/cart/models.py

                 "display_price": property.display_price,
                 "value": value,
                 "price": price,
+                "obj": property
             })
 
         return properties

File lfs/catalog/views.py

 import lfs.core.utils
 from lfs.caching.utils import lfs_get_object_or_404
 from lfs.cart.views import add_to_cart
-from lfs.catalog.models import Category
+from lfs.catalog.models import Category, Property
 from lfs.catalog.models import File
 from lfs.catalog.models import Product
 from lfs.catalog.models import ProductPropertyValue
     for key, option_id in request.POST.items():
         if key.startswith("property"):
             try:
-                po = PropertyOption.objects.get(pk=option_id)
-            except (ValueError, PropertyOption.DoesNotExist):
-                pass
-            else:
-                if po.property.add_price:
+                property = Property.objects.get(pk=key.split('-')[1])
+                if property.is_select_field:
                     try:
-                        po_price = float(po.price)
-                    except (TypeError, ValueError):
+                        po = PropertyOption.objects.get(pk=option_id)
+                    except (ValueError, PropertyOption.DoesNotExist, Property.DoesNotExist):
                         pass
                     else:
-                        property_price += po_price
+                        if po.property.add_price:
+                            try:
+                                po_price = float(po.price)
+                            except (TypeError, ValueError):
+                                pass
+                            else:
+                                property_price += po_price
+            except Property.DoesNotExist:
+                pass
 
     if product.for_sale:
         for_sale_standard_price = product.get_standard_price(request, with_properties=False)

File lfs/order/models.py

                 "unit": property_value.property.unit,
                 "display_price": property_value.property.display_price,
                 "value": value,
-                "price": price
+                "price": price,
+                "obj": property_value.property
             })
 
         return properties

File lfs/static/js/lfs.js

     if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
         xhr.setRequestHeader("X-CSRFToken", $.cookie("csrftoken"));
     }
-});
+});