Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

refresh - How can I update shopping cart? Product-preview image, Product name, price should be updated

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...