0

I want to disable the shopping cart page. I mean that when customers add products to cart, Magento will skip the shopping cart page and redirects them to the checkout page to shorten buying process.

Is there any way to make it successful?

Please suggest me.

  • 1
    magento verision? – Amit Bera May 8 '16 at 12:56
  • Want the redirection for after cart or at any time if user hit checkout/cart/ – Amit Bera May 8 '16 at 13:19
0

Assume that you have using magento 1.x version

and assume that you does not want access checkout/cart/ at all time.

For this case you can use Magento Event/observer.

This is case use magento event controller_action_predispatch_checkout_cart_index

and from this event observer redirect to checkout/onepage/ page

  <global>
    <events>
      <controller_action_predispatch_checkout_cart_index>
        <observers>
          <redirect_to_checkout_from_cart>
            <type>singleton</type>
            <class>[ModuleNameSpace]_[ModuleName]_Model_Observer</class>
            <method>forceToGoCheckoutPage</method>
          </redirect_to_checkout_from_cart>
        </observers>
      </controller_action_predispatch_checkout_cart_index>    
    </events>
  </global>

Observer:

<?php
class ModuleNameSpace]_[ModuleName]_Model_Observer{
    public function forceToGoCheckoutPage($observer){
        // force redirct to checkout page
          Mage::app()->getFrontController()->getResponse()
                ->setRedirect(Mage::getUrl('chekout/onepage'))
                ->sendResponse();
exit();

    }
}
0

My final observer:

I've added a check for cart items because if cart cookie expires or you refresh checkout or success order page, magento displays error 500, too many redirects. If there are no items in cart you must redirect to another page like homepage.

  public function forceCheckoutRedirect($observer){

  $numberOfItems = Mage::helper('checkout/cart')->getItemsCount();
  // force redirct to checkout page if cart is not empty
  if($numberOfItems > 0) {
    Mage::app()->getFrontController()->getResponse()
    ->setRedirect(Mage::getUrl('onepage'))
    ->sendResponse();
    exit();
  }
  else {
    Mage::app()->getFrontController()->getResponse()
    ->setRedirect(Mage::getUrl('/'))
    ->sendResponse();
    exit();

  }

}

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.