Friday 22 November 2013

Add Quantity Increment Decrement Buttons In Magento

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

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__(‘Add to Cart’); ?>
<?php if($_product->isSaleable()): ?>
<div>
<?php if(!$_product->isGrouped()): ?>
<div>
<label for=”qty”><?php echo $this->__(‘Qty:’) ?></label>
<span> <a href=”javascript:void(0)” onclick=”decrementQty(‘qty’);”><img src=”<?php echo $this->getSkinUrl(‘images/qty_mns_btn.jpg’) ?>” alt=”minus” /></a></span>
<span> <input type=”text” name=”qty” id=”qty” maxlength=”6″ value=”1″ title=”Antal” /></span>
<?php endif; ?>
<span> <a href=”javascript:void(0);” onclick=”incrementQty(‘qty’);”><img src=”<?php echo $this->getSkinUrl(‘images/qty_plus_btn.jpg’) ?>” alt=”minus” /></a></span>
</div>
<button title=”<?php echo $buttonTitle ?>” onclick=”productAddToCartForm.submit(this)”><span><span><?php echo $buttonTitle ?></span></span></button>
<?php echo $this->getChildHtml(”, true, true) ?>
</div>
<?php endif; ?>
<script type=”text/javascript”>
//<![CDATA[
function decrementQty(id) {
var val = parseInt($(id).getValue());
if(val != 1)
document.getElementById(id).value = val - 1;
}
function incrementQty(id) {
var val = parseInt($(id).getValue());
document.getElementById(id).value = val + 1;
}
//]]>
</script>

No comments:

Post a Comment