Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
Handle template quantity and price to sum totalPrice

I was at the end of an e-commerce app project but the preferred way to handle it was switched to templates. So here's my question: I created each templates with each quantity to each product being added if needed smoothly, and I would like to calibrate the final calculation. I need to retrieve each quantity and each price, multiply these for each products, and finally sum each productPrices to a finalPrice. Also I would like to learn how can I handle input arrows and mix its use in the calculation. If any of you could help that'd be great. Please Help. Here's the code:

let cart = getCart();

const $itemTemplate = document.getElementById('itemTemplate');

const $cartItems = document.getElementById('cart__items');


for (let productKey in cart) {

    let product = cart[productKey];
    let $itemTemplateClone = document.importNode($itemTemplate.content, true);
    const $cartItem = $itemTemplateClone.querySelector('.cart__item');

    const $itemImg = $itemTemplateClone.querySelector('.itemImg');
    $itemImg.setAttribute('src', product.infos.imageUrl);
    $itemImg.setAttribute('alt', product.infos.altTxt);
    const $itemName = $itemTemplateClone.querySelector('.itemName');
    $itemName.textContent = product.infos.name;
    const $itemColor = $itemTemplateClone.querySelector('.itemColor');
    $itemColor.textContent = product.infos.color;
    const $itemPrice = $itemTemplateClone.querySelector('.itemPrice');
    $itemPrice.textContent = product.infos.price;
    const $itemQuantity = $itemTemplateClone.querySelector('.itemQuantity');
    $itemQuantity.setAttribute('value', product.quantity);

// the final calculation could go here in my opinion //

    const $selectQuantity = $itemTemplateClone.querySelector('.itemQuantity');
    $selectQuantity.addEventListener('change', (event) => {

// Don't know what to do next here to handle arrows, it lays in the quantity querySelector //

});
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda