I want to implement Ajax Quantity Increment and Decrement Button functionality on cart items on Minicart. I didn't find any article or any module to achieve this. as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.Could anyone help me with it?
-
magento.stackexchange.com/questions/216496/…– Mukesh PrajapatiOct 20, 2018 at 5:35
-
Thanks for comments Mukesh Prajapati but i need as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.– trilok kumarOct 20, 2018 at 6:05
-
yes, from above link you can add increment and increment functionality after that you have to write custom ajax code to update mini cart via ajax.– Mukesh PrajapatiOct 20, 2018 at 6:18
-
magearray.com/enhanced-mini-cart.html This is available module for that– Mukesh PrajapatiOct 20, 2018 at 6:21
-
Thanks for comments Mukesh Prajapati the above link extension link doesn't contains demo– trilok kumarOct 20, 2018 at 6:23
2 Answers
We can make it easier by adding +1 and -1 links to change the quantity of each item. We will do this with some very simple JavaScript which takes the current value and adjusts it. Once this has been done, we submit the form through JavaScript to reduce customer effort.
<?php
<input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" id="cart[<?php echo $_item->getId() ?>][qty]"/>
?>
app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart/item/default.phtml
Increase by one:
<?php
<a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, 1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
?>
Decrease by one:
<?php
<a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, -1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
?>
Now the JavaScript function. We do not want it duplicated for every item so you can either put it in your theme’s JavaScript file or just below the table in the parent template -
app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart.phtml
function changeItemQuantity( id , num ) {
var qty_id = "cart[" + id + "][qty]";
var currentVal = parseInt( $(qty_id).value );
if ( currentVal != NaN )
{
$(qty_id).value = currentVal + num;
$("products-table-basket").submit();
}
}
References
You can download the extension and installed it for minicart Ajax Quantity Increment and Decrement Button.
https://github.com/kirtinariya1/MinicartAjaxQtyIncrementDecrement
-
-
-
FYI If click + (increment) or - (decrement ) first time not updating, if i click again then only it will reflect, how to solve this issue– zusApr 7, 2021 at 2:32
-
Any help for ajax not working on first click. magento.stackexchange.com/q/335615/57334– zusApr 14, 2021 at 15:32