0
I created these functions in case the quantity of the product is changed, regardless of whether it is by the arrow buttons or directly in the field, the "Update" button appears, only for the product that underwent the change. However, if I change 1 product, the button appears for all others. And when I click on the same product again, the button removes it, but adds another button on another product.
<form action="http://.../checkout/cart/updatePost/" method="post" id="form-validate" class="form form-cart">
<input name="form_key" type="hidden" value="rW5XuwwQiEurJLOt">
<div class="cart table-wrapper">
<table id="shopping-cart-table" class="cart items data table">
<caption role="heading" aria-level="2" class="table-caption">Itens do Carrinho de Compras</caption>
<thead>
<tr>
<th class="col item" scope="col"><span>Item</span></th>
<th class="col price" scope="col"><span>Preço</span></th>
<th class="col qty" scope="col"><span>Qtd</span></th>
<th class="col subtotal" scope="col"><span>Subtotal</span></th>
</tr>
</thead>
<tbody class="cart item">
<tr class="item-info">
<td data-th="Item" class="col item">
<a href="http://.../estojo-lowcost-azul-lentes-de-contato.html" title="Estojo para lentes de contato Bausch & Lomb‎ azul" tabindex="-1" class="product-item-photo">
<span class="product-image-container" style="width:165px;">
<span class="product-image-wrapper" style="padding-bottom: 100%;">
<img class="product-image-photo" src="http://.../pub/media/catalog/product/cache/3a98496dd7cb0c8b28c4c254a98f915a/c/b/cbl.jpg" max-width="165" max-height="165" alt="Estojo para lentes de contato Bausch & Lomb‎ azul"></span>
</span>
</a>
<div class="product-item-details">
<strong class="product-item-name">
<a href="http://.../estojo-lowcost-azul-lentes-de-contato.html">Estojo para lentes de contato Bausch & Lomb‎ azul</a>
</strong>
</div>
</td>
<td class="col price" data-th="Preço">
<span class="price-excluding-tax" data-label="Excl. Impostos">
<span class="cart-price">
<span class="price">R$4,90</span>
</span>
</span>
</td>
<td class="col qty" data-th="Qtd">
<div class="field qty">
<label class="label" for="cart-2217-qty">
<span>Qtd</span>
</label>
<div class="control qty">
<input id="cart-2217-qty" name="cart[2217][qty]" data-cart-item-id="1530" value="4" type="number" size="4" title="Qtd" class="input-text qty" maxlength="12" data-validate="{required:true,'validate-greater-than-zero':true}" data-role="cart-item-qty">
</div>
<div class="qty-changer">
<a href="javascript:void(0)" class="qty-inc"><i class="porto-icon-up-dir"></i></a>
<a href="javascript:void(0)" class="qty-dec"><i class="porto-icon-down-dir"></i></a>
</div>
</div>
</td>
<td class="col subtotal" data-th="Subtotal">
<span class="price-excluding-tax" data-label="Excl. Impostos">
<span class="cart-price">
<span class="price">R$19,60</span> </span>
</span>
</td>
</tr>
<tr class="item-actions">
<td colspan="100">
<div class="actions-toolbar">
<div id="gift-options-cart-item-2217" data-bind="scope:'giftOptionsCartItem-2217'" class="gift-options-cart-item">
<!-- ko template: getTemplate() -->
<!-- ko if: isActive() || hasActiveOptions() -->
<!-- /ko -->
<!-- /ko -->
</div>
<a class="action action-edit" href="http://.../checkout/cart/configure/id/2217/product_id/64518/" title="Editar parâmetros do item">
<span>
Editar </span>
</a>
<a href="#" title="Remover item" class="action action-delete" data-post="{"action":"http:\/\/...\/checkout\/cart\/delete\/","data":{"id":"2217","uenc":"aHR0cDovLzE4LjIyOS4xNDUuODQvY2hlY2tvdXQvY2FydC8,"}}">
<span>
Remover item </span>
</a><button id="updateCar" type="submit" name="update_cart_action" data-cart-item-update="" value="update_qty" title="Atualizar Carrinho de Compras" class="action update" style="display: none;"><span>Atualizar</span></button><button id="updateCar"
type="submit" name="update_cart_action" data-cart-item-update="" value="update_qty" title="Atualizar Carrinho de Compras" class="action update" style="display: none;"><span>Atualizar</span></button><button id="updateCar" type="submit" name="update_cart_action"
data-cart-item-update="" value="update_qty" title="Atualizar Carrinho de Compras" class="action update" style="display: none;"><span>Atualizar</span></button><button id="updateCar" type="submit" name="update_cart_action" data-cart-item-update=""
value="update_qty" title="Atualizar Carrinho de Compras" class="action update" style="display: none;"><span>Atualizar</span></button>
</div>
</td>
</tr>
</tbody>
<tbody class="cart item">
<tr class="item-info">
<td data-th="Item" class="col item">
<a href="http://.../renu-fresh-120ml.html" title="Renu Fresh 120ml " tabindex="-1" class="product-item-photo">
<span class="product-image-container" style="width:165px;">
<span class="product-image-wrapper" style="padding-bottom: 100%;">
<img class="product-image-photo" src="http://.../pub/media/catalog/product/cache/3a98496dd7cb0c8b28c4c254a98f915a/l/2/l2412989.jpg" max-width="165" max-height="165" alt="Renu Fresh 120ml "></span>
</span>
</a>
<div class="product-item-details">
<strong class="product-item-name">
<a href="http://.../renu-fresh-120ml.html">Renu Fresh 120ml </a>
</strong>
</div>
</td>
<td class="col price" data-th="Preço">
<span class="price-excluding-tax" data-label="Excl. Impostos">
<span class="cart-price">
<span class="price">R$24,90</span> </span>
</span>
</td>
<td class="col qty" data-th="Qtd">
<div class="field qty">
<label class="label" for="cart-2218-qty">
<span>Qtd</span>
</label>
<div class="control qty">
<input id="cart-2218-qty" name="cart[2218][qty]" data-cart-item-id="1350" value="1" type="number" size="4" title="Qtd" class="input-text qty" maxlength="12" data-validate="{required:true,'validate-greater-than-zero':true}" data-role="cart-item-qty">
</div>
<div class="qty-changer">
<a href="javascript:void(0)" class="qty-inc"><i class="porto-icon-up-dir"></i></a>
<a href="javascript:void(0)" class="qty-dec"><i class="porto-icon-down-dir"></i></a>
</div>
</div>
</td>
<td class="col subtotal" data-th="Subtotal">
<span class="price-excluding-tax" data-label="Excl. Impostos">
<span class="cart-price">
<span class="price">R$24,90</span>
</span>
</span>
</td>
</tr>
<tr class="item-actions">
<td colspan="100">
<div class="actions-toolbar">
<div id="gift-options-cart-item-2218" data-bind="scope:'giftOptionsCartItem-2218'" class="gift-options-cart-item">
<!-- ko template: getTemplate() -->
<!-- ko if: isActive() || hasActiveOptions() -->
<!-- /ko -->
<!-- /ko -->
</div>
<a class="action action-edit" href="http://.../checkout/cart/configure/id/2218/product_id/64516/" title="Editar parâmetros do item">
<span>
Editar </span>
</a>
<a href="#" title="Remover item" class="action action-delete" data-post="{"action":"http:\/\/...\/checkout\/cart\/delete\/","data":{"id":"2218","uenc":"aHR0cDovLzE4LjIyOS4xNDUuODQvY2hlY2tvdXQvY2FydC8,"}}">
<span>
Remover item </span>
</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="cart main actions">
<a class="action continue" href="http://.../" title="Continuar Comprando">
<span>Continuar Comprando</span>
</a>
<button type="submit" name="update_cart_action" data-cart-empty="" value="empty_cart" title="Limpar Carrinho de Compras" class="action clear" id="empty_cart_button">
<span>Limpar Carrinho de Compras</span>
</button>
<input type="hidden" value="" id="update_cart_action_container" data-cart-item-update="">
</div>
</form>
function habilitaButton() {
var divTableCart = document.getElementById('shopping-cart-table');
var itemProduct = divTableCart.getElementsByClassName('action-delete');
for(var j =0; j < itemProduct.length; j++){
itemProduct[j].insertAdjacentHTML("afterend", '<button id="updateCar" type="submit" name="update_cart_action" data-cart-item-update="" value="update_qty" title="Atualizar Carrinho de Compras" class="action update"><span>Atualizar</span></button>');
}
}
function removeButton(){
var divTableCart = document.getElementById('shopping-cart-table');
var itemProduct = divTableCart.getElementsByClassName('action-delete');
for(var l =0; l < itemProduct.length; l++){
document.getElementById("updateCar").style.display="none";
}
}
var QtdyProduct = document.getElementsByClassName("control qty");
for(var i =0; i < QtdyProduct.length; i++){
var qtdAlterada = QtdyProduct[i].getElementsByTagName('input')[0];
qtdAlterada.addEventListener("blur", habilitaButton);
qtdAlterada.addEventListener("focusin", removeButton);
}
Can you post HTML? Then you could test the code.
– Vítor Ferragini
hi @Vítorferragini has yes.
– R.Park