There are many problems when you’re working with configurable products. One of annoying issue was we forgot to make associated simple products inherit parent product categories. And of course, It will take us a lot of time to accomplish it manually. Therefore, I wrote scripts for this task. You can flow these below steps to make it done with a little time.

1/ You just needed create a new file script.php on the same index.php directory of your website.

set_time_limit(0);

require_once('app/Mage.php');
umask(0);
Mage::app();
$collection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');

foreach ($collection as $product){
if( $product->getTypeId() == "configurable"){
//var_dump($product->getCategoryIds()) ;
//echo "<br>";

$childProducts = Mage::getModel('catalog/product_type_configurable')
->getUsedProducts(null,$product);
//$i = 1;
//$productName = $product->getId(). " - ".$product->getName();
foreach($childProducts as $child){
$arrCats = $product->getCategoryIds();
if(is_array($arrCats)){
$modelProduct = Mage::getModel('catalog/product')->load($child->getId());
$modelProduct->setCategoryIds($arrCats);
$modelProduct->save();
}
//echo "<br>"."\t".$i++. " - ";
//var_dump($child->getCategoryIds());
//echo "Child ". $child->getId().$child->getName() ."<br>";
}
//echo "<br> --------------------------------------------------------------------------------------------------------------<br> ";
}

echo "Complete";
}

 

 

2/ Run this script by enter the url : http://yourwebsite/script.php

Is it easy ? Hope it can help other guys.
Enjoy coding !