Saturday, September 19, 2015

Add Increase and Decrease Quantity Buttons in Magento


open addtocart.phtml file replace this code

Path :- app\design\frontend\default\your theme\template\catalog\product\view\addtocart.phtml


<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = Mage::helper('core')->quoteEscape($this->__('Add to Cart')); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <div class="qty-wrapper">
            <label for="qty"><?php echo $this->__('Qty:') ?></label>
            <input type="text" pattern="\d*" name="qty" id="qty" maxlength="12" value="<?php echo max($this->getProductDefaultQty() * 1, 1) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" / 
           <button class="button-arrow button-up" type="button">Increase</button>
           <button class="button-arrow button-down" type="button">Decrease</button>
        </div>
        <?php endif; ?>
        <div class="add-to-cart-buttons">
            <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
            <?php echo $this->getChildHtml('', true, true) ?>
        </div>
    </div>
<?php endif; ?>

<script type="text/javascript">

        //&lt;![CDATA[

        jQuery(function($) {

            $('.add-to-cart .button-up').click(function() {

                $qty = $(this).parent().find('.qty');

                qty = parseInt($qty.val()) + 1;

                $qty.val(qty);

            });

            $('.add-to-cart .button-down').click(function() {

                $qty = $(this).parent().find('.qty');

                qty = parseInt($qty.val()) - 1;

                if (qty < 0)

                    qty = 0;

                $qty.val(qty);

            });

        });

        //]]&gt;


        </script>

0 comments:

Post a Comment