1

In Magento, when the AddtoCart button is clicked the product should go straight to checkout page instead of cart page, i dont need to add the product to cart page, is it possible?

Any ideas? Thanks.

  • Sander,i thought to add the product to cart programmatically and redirect to checkout page, but the not able to get the solution, and i don't know this is the correct method. – Helphin Feb 18 '14 at 10:44
  • you can make a redirect on the cart page that forwards to the checkout. This is probably easier than adding products programatically – Sander Mangel Feb 18 '14 at 10:47
  • but i dont want to show up cart page – Helphin Feb 18 '14 at 10:49
  • 1
    thats what the redirect is for. You can do this with an observer or by rewriting the controller of the cart – Sander Mangel Feb 18 '14 at 10:50
  • If you want you can add your final solution as an answer and accept it to close the question – Sander Mangel Feb 18 '14 at 11:16
1

Then config file i have added events observer,

<config>
....
    <frontend>
        <events>
            <controller_action_postdispatch>
                <observers>
                    <controller_action_after>
                        <class>membership/observer</class>
                        <method>membershipControllerActionPostDispatch</method>
                    </controller_action_after>
                </observers>
            </controller_action_postdispatch>
            <add_to_cart_after>
                <observers>
                    <add_to_cart_after>
                        <class>membership/observer</class>
                        <method>membershipCheckout</method>
                    </add_to_cart_after>
                </observers>
            </add_to_cart_after>
        </events>
    </frontend>
.....    
</config>

and My Observer file,

class Att_Membership_Model_Observer
{
    public function membershipControllerActionPostDispatch($observer)
    {
        if($observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_cart_add')
        {
            Mage::dispatchEvent("add_to_cart_after", array('request' => $observer->getControllerAction()->getRequest()));
        }
    }
   public function membershipCheckout($observer)
   {
      if (!Mage::helper('customer')->isLoggedIn())
      {
         Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/onepage', array('_secure'=>true)));
      }
   }

}

this gives solution for me, the addtocart go straight to checkout page.

Thanks @sander

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.