0

I need some change in website. When product add to cart then page auto redirect to checkout page . Magento default option show only for auto redirect cart page but I need redirect to checkout page

  • You need to customize that section when adding product to cart. – Sukumar Gorai Aug 27 '18 at 18:59
  • how to customize – user129727 Aug 27 '18 at 19:00
  • Are you using default add to cart action? – Sukumar Gorai Aug 27 '18 at 19:00
  • @SukumarGorai yes – user129727 Aug 27 '18 at 19:01
  • use porto theme – user129727 Aug 27 '18 at 19:01
0

app/code/core/Mage/Checkout/controllers/CartController.php

Override the above Class. Then you will find the addAction() method, in this method magento add products to cart so you can add your logics and change the redirect url to your custom url.

0

There are many ways to do this

When product add to cart then page auto redirect to checkout page

You can do this at the server side or at the client (browser side). To do it simply at the client, add a one-liner js at the top of this file:

app/design/frontend/{your_theme}/default/template/checkout/cart.phtml

<?php // place the following at the top of cart.phtml ?>
<script type="text/javascript">
window.location.replace('<?php echo $this->getUrl('checkout/onepage') ?>');
</script>

The above assume that you want to redirect to onepage checkout. But you can easily modify it to accommodate other checkout types.

To do it at the server side have many more possibilities depending on the exact requirements. For example, you can have a custom controller to handle the creation of the quote object. The same controller can then redirect to the checkout page. You can also listen to the event checkout_cart_add_product_complete and then set the redirect URL in your observer:

public function cartRedirect($observer)
{
    if (!Mage::getSingleton('checkout/session')->getQuote()->getHasError()) {
        Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
        $url = Mage::getUrl('checkout/onepage');
        $observer->getResponse()->setHeader('Location', $url);
    }
}
0

Add product to cart then auto redirect to checkout page use magento event.

Create your custom module & Declare event observers in config.xml

<events>
        <checkout_cart_product_add_after>
            <observers>
                <custommodule>
                    <class>custommodule/observer</class>
                    <method>cartProductAddAfter</method>
                </custommodule>
            </observers>
        </checkout_cart_product_add_after>            
</events>

Create your observers file in model . To redirect Magento to checkout use something similar in the Observer code:

class Vendor_Custommodule_Model_Observer 
{

    public function cartProductUpdateAfter($observer)
    {
        $this->cartProductAddAfter($observer);
    }

    public function cartProductAddAfter($observer)
    {
        $response = $observer->getResponse();
        $url = Mage::helper('checkout/url')->getCheckoutUrl();
        $response->setRedirect($url);        
    }
}   

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.