Call us now on 0115 9738074

Magento Q&A: How to redirect from simple product to configurable product

Difficulty: Medium

Modification: Core Controller

Q:

I am trying to find a way to redirect the url for a simple product to go to the corresponding configurable product. For example if I have a link to a small blue t-shirt, it would go to the main t-shirt page where the attributes are available to select.

A:

You will need to modify the ProductController to make it look for a configurable product and display it when someone asks for a simple product.

The file you need to modify is /app/code/core/Mage/Catalog/controllers/ProductController and the method name is _initProduct().

Find the code which retrieves the product to be displayed:

$product = Mage::getModel(‘catalog/product’)

->setStoreId(Mage::app()->getStore()->getId())
->
load($productId);

And add this code after it:

if($product->type_id==“simple”)

{

$parentId=$product->loadParentProductIds()->getData('parent_product_ids');
if(isset(
$parentId[0]))
{
$product
=Mage::getModel('catalog/product')->load($parentId[0]);
}
}

That’s it, simple and elegant.

Share and Enjoy:
  • Facebook
  • Digg
  • del.icio.us
  • StumbleUpon
  • Google Bookmarks

Tags: , , ,

Leave a Reply