Spaces:
Sleeping
Sleeping
Update templates/cart.html
Browse files- templates/cart.html +6 -5
templates/cart.html
CHANGED
|
@@ -130,11 +130,11 @@
|
|
| 130 |
</div>
|
| 131 |
<div class="cart-item-quantity mt-2">
|
| 132 |
<!-- Decrease button -->
|
| 133 |
-
<button onclick="updateQuantity('decrease', '{{ item.Name }}', {{ item.Price__c }}, '{{ customer_email }}')">-</button>
|
| 134 |
<!-- Quantity input field -->
|
| 135 |
<input type="text" value="{{ item.Quantity__c }}" readonly data-item-name="{{ item.Name }}">
|
| 136 |
<!-- Increase button -->
|
| 137 |
-
<button onclick="updateQuantity('increase', '{{ item.Name }}', {{ item.Price__c }}, '{{ customer_email }}')">+</button>
|
| 138 |
</div>
|
| 139 |
</div>
|
| 140 |
<div class="cart-item-actions">
|
|
@@ -169,7 +169,7 @@
|
|
| 169 |
</div>
|
| 170 |
|
| 171 |
<script>
|
| 172 |
-
function updateQuantity(action, itemName,
|
| 173 |
const inputField = document.querySelector(`input[data-item-name="${itemName}"]`);
|
| 174 |
const priceField = document.querySelector(`.cart-item-details .item-price`);
|
| 175 |
const subtotalField = document.querySelector('#subtotal');
|
|
@@ -188,8 +188,9 @@
|
|
| 188 |
// Update the input field value locally
|
| 189 |
inputField.value = currentQuantity;
|
| 190 |
|
| 191 |
-
// Calculate the
|
| 192 |
-
let
|
|
|
|
| 193 |
priceField.innerText = newItemPrice.toFixed(2); // Update item price
|
| 194 |
|
| 195 |
// Calculate new subtotal
|
|
|
|
| 130 |
</div>
|
| 131 |
<div class="cart-item-quantity mt-2">
|
| 132 |
<!-- Decrease button -->
|
| 133 |
+
<button onclick="updateQuantity('decrease', '{{ item.Name }}', {{ item.Price__c }}, [{{ item.Add_Ons__c | split(',') | map(attribute='price') }}], '{{ customer_email }}')">-</button>
|
| 134 |
<!-- Quantity input field -->
|
| 135 |
<input type="text" value="{{ item.Quantity__c }}" readonly data-item-name="{{ item.Name }}">
|
| 136 |
<!-- Increase button -->
|
| 137 |
+
<button onclick="updateQuantity('increase', '{{ item.Name }}', {{ item.Price__c }}, [{{ item.Add_Ons__c | split(',') | map(attribute='price') }}], '{{ customer_email }}')">+</button>
|
| 138 |
</div>
|
| 139 |
</div>
|
| 140 |
<div class="cart-item-actions">
|
|
|
|
| 169 |
</div>
|
| 170 |
|
| 171 |
<script>
|
| 172 |
+
function updateQuantity(action, itemName, basePrice, addOnPrices, customerEmail) {
|
| 173 |
const inputField = document.querySelector(`input[data-item-name="${itemName}"]`);
|
| 174 |
const priceField = document.querySelector(`.cart-item-details .item-price`);
|
| 175 |
const subtotalField = document.querySelector('#subtotal');
|
|
|
|
| 188 |
// Update the input field value locally
|
| 189 |
inputField.value = currentQuantity;
|
| 190 |
|
| 191 |
+
// Calculate the total price for the item (base price + add-ons * quantity)
|
| 192 |
+
let addOnTotal = addOnPrices.reduce((acc, price) => acc + price, 0); // Sum all add-on prices
|
| 193 |
+
let newItemPrice = (basePrice + addOnTotal) * currentQuantity;
|
| 194 |
priceField.innerText = newItemPrice.toFixed(2); // Update item price
|
| 195 |
|
| 196 |
// Calculate new subtotal
|