How to redirect a simple product's page to the parent configurable product page?


the code below should work only if the simple products are assigned to only one configurable product.
by default, magento allows you to add a simple product to as many configurable products you need.

Let's create a module and call it StackExchange_Redirect.
You will need the following files.

app/etc/modules/StackExchange_Redirect.xml - the declaration file

<?xml version="1.0"?>
                <Mage_Catalog />

app/code/local/StackExchange/Redirect/etc/config.xml - the module configuration file where you declare an observer for the product view page

<?xml version="1.0"?>

app/code/local/StackExchange/Redirect/Model/Observer.php - the observer that should redirect to the configurable product page.

class StackExchange_Redirect_Model_Observer
    public function redirectToConfigurable($observer)
        $id = Mage::app()->getRequest()->getParam('id');
        $configurableParentIds = Mage::getResourceSingleton('catalog/product_type_configurable')
        if (isset($configurableParentIds[0])) {
            $mainProduct = Mage::getModel('catalog/product')
            Mage::app()->getResponse()->setRedirect($mainProduct->getProductUrl(), 301);
        return $this;

when you are done, clear the cache.

  • Where do I put this code? – yavonz15 Mar 3 '16 at 11:49
  • I've edited the answer and provided a full module that should work. – Marius Mar 3 '16 at 11:58
  • It returns the error Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting '{' /Model/Observer.php on line 4 – yavonz15 Mar 3 '16 at 12:12
  • 1
    sorry, I missed a bracket. You could have spotted this :). – Marius Mar 3 '16 at 12:14
  • Unfortunately, the same error – yavonz15 Mar 3 '16 at 12:20

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.