Wednesday, April 18, 2012

Magento increment QTY Box in Cart or View page

Magento had default textbox for Quantity but some time we require to add the qty box  with increment value without entering the value in textbox.We can add the followimg code in cart or view page



1) Add the one new file called jquery.qty.js and enter the following code

jQuery(document).ready(function(){
jQuery("div.quantity").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');
        jQuery(".plus").click(function()
        {
            var currentVal = parseInt(jQuery(this).prev(".qty").val());
            if (!currentVal || currentVal=="" || currentVal == "NaN") currentVal = 1;
          jQuery(this).prev(".qty").val(currentVal + 1);

        });
        jQuery(".minus").click(function()
       {
            var currentVal = parseInt(jQuery(this).next(".qty").val());
            if (currentVal == "NaN") currentVal = 1;
            if (currentVal > 1)
            {
                jQuery(this).next(".qty").val(currentVal - 1);
            }
        });
 
        });

and place as per your theme folder structure

2)Add the Following
If you want in cart page open app/design/frontend/default/yourtheme/template/catalog/prdouct/view/addtocart.phtml search for qty code and place div like this
 <div class="quantity">    
        <input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="2" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" />
</div>

IF u want in view page open app/design/frontend/default/yourtheme/template/checkout/cart/item/default.phtml search for qty code and place div like this
<div class="quantity">
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
</div>

Just check you will get the incerement box in cart and view page

Hope this will help you!

1 comment:

  1. I was looking for this solution. I will try on my website

    Please contact us
     Renderindia Infotech Bangalore
    magento e commerce development company Bangalore

    ReplyDelete

Thankyou for your Comments

LinkWithin

Blog has moved, searching new blog...