Просмотр исходного кода

Fixed issue with multiple quantity fields updated on cart page if the item has variation.

cart.js - added code to check if the item has variation and select proper version of it depending on product_variation_id
slow_tiger 1 год назад
Родитель
Сommit
086668010d
1 измененных файлов с 12 добавлено и 1 удалено
  1. 12 1
      static/js/cart.js

+ 12 - 1
static/js/cart.js

@@ -50,7 +50,18 @@ function updateItemRow(item_row, cart_items, item_amount) {
   // if item quantity goes down to 0, remove it
   // from the DOM.
 
-  let item = cart_items.find(item => item.product_id == item_row.id);
+  // Getting the proper item to update on the car page
+  let item = null;
+
+  for (let i = 0; i < cart_items.length; i++) {
+    if (cart_items[i].product_id == item_row.id) {
+      if (!cart_items[i].options.product_variation_id || (cart_items[i].options.product_variation_id == item_row.querySelector("#product_id").value)) {
+        item = cart_items[i];
+        break;
+      }
+    }
+  }
+
   if (item) {
 
     // update quantity value for input field quantity_manual