Magento 1.9 – Add Buy Now and Add to Cart Buttons

addtocartce-1.9.2.2magento-1.9

I want to add both buttons "Buy Now" as well as "Add to Cart", If the user clicks on Buy-now it will redirect to the "onestepcheckout" page directly (Magento extension), for Add to Cart need default functionality. I'm using Magento 1.9.2.4

Please suggest how to add both functionalities without extension.

Best Answer

Please add this in your phtml file where you want to add :

<div class="add-to-cart">
        <div class="qty-view">
        <?php if(!$_product->isGrouped()): ?>
        <label for="qty"><?php echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty validate-greater-than-zero-qty validate-digits" />
        <?php endif; ?>
        </div>
        <button type="button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
        <button type="button" title="Buy Now" class="button btn-cart" onclick="setcheckoutLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span>Buy Now</span></span></button>
        <?php echo $this->getChildHtml('', true, true) ?>
</div>

and must be added this script for Buy Now button :

<script type="text/javascript">
function setcheckoutLocation(location)
{
    showLoadingAnimation();
    jQuery.ajax({
        type:"GET",
        url:location,
        success:function(data){
            window.location.href = "<?php echo Mage::helper('checkout/url')->getCheckoutUrl(); ?>";
        }
    });
}
</script>