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 !
POST HASN'T TAG.
Amit Kumar
January 22
I am using apigee to do a callout in my magento dev org and I created a JSON for it but I need to create a configurable product with associated child product. I am able to create simple product but not configurable
Jens Mikkelsen
January 22
I agree its really frustraing! There should be a default option, to make simple products inherit the category from the configurable product. So frustrating to run catalog rules and find out, that one of 10 simple products to the configurable product is missing a category.