diff --git a/artel/store/cart.py b/artel/store/cart.py index bb80ceb..814f879 100644 --- a/artel/store/cart.py +++ b/artel/store/cart.py @@ -66,14 +66,17 @@ class SessionCart(BaseCart): # TODO - add logging ... - def update_item_quantity(self, item_id: int, change: int) -> None: + def update_item_quantity(self, item_id: int, new_quantity: int) -> None: self.validate_item_id(item_id) + if new_quantity < 1: + self.remove_item(item_id) + return try: - self.session[settings.CART_SESSION_ID][str(item_id)] += change + self.session[settings.CART_SESSION_ID][str(item_id)] = new_quantity self.session.modified = True except KeyError: # TODO - add logging - self.add_item(item_id, change) + self.add_item(item_id, new_quantity) def get_items(self) -> List[CartItem]: _items = [] diff --git a/artel/store/static/js/cart.js b/artel/store/static/js/cart.js index 32d5d33..34cf520 100644 --- a/artel/store/static/js/cart.js +++ b/artel/store/static/js/cart.js @@ -122,16 +122,18 @@ $(document).on('click', '.add-to-cart-button', function(event) { const productID = $(this).data('product-id'); const newQuantity = input.val(); const csrfToken = $(this).data('csrf-token'); + const url = $(this).data("update-cart-url") formData.append('product_id', productID); formData.append('quantity', newQuantity); - + console.log(input.val()) $.ajax({ - type: 'POST', - url: '/../../cart/item/', + type: 'PUT', + url: url, data: formData, // Use the serialized form data headers: { 'X-CSRFToken': csrfToken }, dataType: 'json', + success: location.reload(), processData: false, // Prevent jQuery from processing the data contentType: false, // Let the browser set the content type }); diff --git a/artel/store/templates/store/cart.html b/artel/store/templates/store/cart.html index 4dca58e..5ecf9b3 100644 --- a/artel/store/templates/store/cart.html +++ b/artel/store/templates/store/cart.html @@ -6,7 +6,7 @@
Full Name
+Imię i Nazwisko
{{customer_data.full_name}}
@@ -29,7 +29,7 @@Phone
+Numer telefonu
{{customer_data.phone}}
@@ -38,7 +38,7 @@Address
+Adres
{{customer_data.full_address}}
@@ -51,7 +51,7 @@