1

I've combined my checkout page (OneStepCheckout) and cart page. The /checkout/cart (the cart page) is still accessible, and I wouldn't want my customer to accidentally access that page (reviewing your cart twice would be quite confusing).

Is there anyway I can redirect this page with magento to /checkout ?

2

In this case you need 301 redirection from checkout/cart to your checkout page

  Mage::app()->getResponse()
        ->setRedirect($someUrl, 301)
        ->sendResponse();

use event controller_action_predispatch_checkout_cart_index fire an observer

<frontend>
    <events>
        <controller_action_predispatch_checkout_cart_index>
            <observers>
                <customRedir>
                    <class>YourModulePrefix/observer</class>
                    <method>customRedir</method>
                </customRedir>
            </observers>
        </controller_action_predispatch_checkout_cart_index>
        </events>
</frontend>

Observer code:

<?php
class MymoduleNameSpace_ModuleName_Model_Observer{

    public function customRedir($oberver){
          Mage::app()->getResponse()
        ->setRedirect($someUrl, 301)
        ->sendResponse();
        die();

    }
}

Full Module:

As per as your request, i have out full module and as per as customer will redirect to checkout/cart to contacts us using 301 redirection.

config code:

location: app\code\local\Stackexchange\Magento67150\etc\config.xml

code:

<?xml version="1.0"?>
<config>
  <modules>
    <StackExchange_Magento67150>
      <version>0.1.0</version>
    </StackExchange_Magento67150>
  </modules>
  <global>
    <models>
      <magento67150>
        <class>StackExchange_Magento67150_Model</class>
        <resourceModel>magento67150_mysql4</resourceModel>
      </magento67150>
    </models>
    <events>
      <controller_action_predispatch_checkout_cart_index> <!-- identifier of the event we want to catch -->
        <observers>
          <controller_action_predispatch_checkout_cart_index_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>magento67150/observer</class> <!-- observers class alias -->
            <method>customRedir</method>  <!-- observer's method to be called -->
             </controller_action_predispatch_checkout_cart_index_handler>
        </observers>
      </controller_action_predispatch_checkout_cart_index>
    </events>
  </global>
</config> 

Observer code:

location: app\code\local\Stackexchange\Magento67150\Model\Observer.php

Code:

<?php
class StackExchange_Magento67150_Model_Observer
{

            public function customRedir(Varien_Event_Observer $observer)
            {

                $controller = $observer->getControllerAction();
                $controller->getResponse()->setRedirect(Mage::getUrl('contacts'),301)
                ->sendResponse();
                return;
            }

}

Module file: app/etc/modules/StackExchange_Magento67150.xml

code is:

<?xml version="1.0"?>
<config>
  <modules>
    <StackExchange_Magento67150>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </StackExchange_Magento67150>
  </modules>
</config>
  • Thanks for your response, but as a magento 'noob', I must ask: where do I put this code? – Frank May 8 '15 at 18:15
  • Hey you want to redirect from checkout/cart to your checkout pahe – Amit Bera May 8 '15 at 18:17
  • Works! Thanks a lot. I had not figured out yet how to create modules. Therefore my first comment. Thanks again! – Frank May 11 '15 at 10:32
  • One issue though. If I'm at /checkout, and I clear my cart, I will be directed to /checkout/cart, which redirects me to /checkout, which redirects me back to /checkout/cart etcetcetcetc until my browser errors. – Frank May 13 '15 at 9:28

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.