1

In 2014 I've added some code to auto update the product qty in the cart checkout of Magento so if I were to change the qty of the product it automatically updates this. Sometimes a customer forgets to press enter or click on update shoppingcart. This worked very well.

I've placed this code in the head.phmtl file of my template:

<script type="text/javascript">
function ajaxCartPost(item){
    element='cart[' + item +'][qty]';
    qty=document.getElementById(element).value;
    jQuery.ajax({
        url: '<?php echo Mage::getUrl('checkout/cart/ajaxcart')?>',
        dataType: 'json',
        data: jQuery("form#cartform").serializeArray(), 
        type:'POST',
        success: function(data) {
            if(data.status == 'Y'){
                jQuery('.cart').replaceWith(data.cart);
            }
        }
    });
    return false;
}

And disabled this line in /app/design/frontend/base/default/template/checkout/cart/item/default.phtml

<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" />

with

<input name="cart[<?php echo $_item->getId() ?>][qty]" id="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" maxlength="12" style="float: left; width:1.9em!important;" onkeyup="ajaxCartPost(<?php echo $_item->getId() ?>);"  />

I've updated the Magento shop from version 1.9.0.1 to 1.9.2.4 and all of a sudden this doesn't work anymore. I did some tracing to check and see if there was an error but there is none. Can someone point me to the right direction?

Br,

Steve

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.