This is working, but always with the same product-priview.png, productName and price. How can I replace productId, Image, productName, price and url with my real product info. How can I check if the product was already in the cart and if it is in the cart, just update the quantity.
function addProduct(target) {
productId = productId + 1;
var productAdded =
<li class="cd-cart__product">
<div class="cd-cart__image">
<a href="#0"><img src="assets/img/product-preview.png" alt="placeholder"></a>
</div>
<div class="cd-cart__details">
<h3 class="truncate">
<a href="#0">Product Name</a>
</h3>
<span class="cd-cart__price">$10.00</span>
<div class="cd-cart__actions">
<a href="#0" class="cd-cart__delete-item">Delete</a>
<div class="cd-cart__quantity">
<label for="cd-product-'+ productId +'">Qty</label>
<span class="cd-cart__select">
<select class="reset" id="cd-product-'+ productId +'" name="quantity">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
<svg class="icon" viewBox="0 0 12 12">
<polyline fill="none" stroke="currentColor" points="2,4 6,8 10,4 "/>
</svg>
</span>
</div>
</div>
</div>
</li>;
cartList.insertAdjacentHTML('beforeend', productAdded);
};
question from:
https://stackoverflow.com/questions/65874560/how-can-i-update-shopping-cart-product-preview-image-product-name-price-shoul 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…