1

I'm trying to add a new extra "add to cart" called (Send as a gift) button in product view. The functionality of this button has to be a little different than the original button. When i press this second button , it has to redirect directly to checkout .

I mentioned that the original button is not redirect. So , in conclusion , first button does not need to redirect you to checkout, but the second it is necessary.

Can anyone can give me some ideas , how to do this? I am using magento 1.9 Thanks in advance!

1

Try this one!

In your app\design\frontend\[package]\[theme]\template\catalog\product\view\addtocart.phtml add a button along with add to cart button.

<button type="button" title="<?php echo $this->__('Check out') ?>" class="button btn-cart" onclick="setcheckoutLocation('<?php echo $this->getAddToCartUrl($_product) ?>','<?php echo Mage::getUrl('checkout/url') ?>')"><span><span><?php echo $this->__('Send as a Gift') ?></span></span></button>

Then add this script on this page itself:

<script>
 function setcheckoutLocation(location,chkout)
 {
  jQuery.ajax({
                type:"GET",
                url:location,
                success:function(data){
                     window.location.href = chkout;
                }
             });
}
</script>

This should work, I have tested it on Magento 1.9.2.4 !! Good Luck

  • Glad to help. :) – Lalit838 Sep 27 '17 at 13:07
  • One more question , if you want and can help me, i'm trying to create a session variable if the this button was pressed. What i was trying to do was to make it looks like this : 'code'<?php session_start(); if (isset($_GET["sendasagift"])) { $_SESSION['variable']= "yes"; } else {$_SESSION['variable']="no";} ?>'code' – Opr Sep 28 '17 at 12:43
0
  1. You have to rewritte in local : app>code>core>Mage>Checkout>controllers>CartController.php, clone addAction() in addcustomAction() then redirect to cart at the end in this new one addcustomAction() like this:

    ...
    
    $this->_redirect('checkout/cart');
    
  2. Your new button should looks like this:

    <button type="button" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/addcustom', array('product'=>$_product->getId(), 'form_key' => Mage::getSingleton('core/session')->getFormKey())); ?>')"><?php echo $this->__('Send as a gift') ?></button>
    

Now your new button add a product to cart with redirecting to checkout/cart

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.