You are right, you are creating a relationship / relationship between custom and child products, but what happens when you create your custom product, you are not setting setConfigurableAttributesData strong>, which basically sets up the superapplication information for this custom product.
foreach($configAttrCodes as $attrCode){ $super_attribute= Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product',$attrCode->code); $configurableAtt = Mage::getModel('catalog/product_type_configurable_attribute')->setProductAttribute($super_attribute); $newAttributes[] = array( 'id' => $configurableAtt->getId(), 'label' => $configurableAtt->getLabel(), 'position' => $super_attribute->getPosition(), 'values' => $configurableAtt->getPrices() ? $configProduct->getPrices() : array(), 'attribute_id' => $super_attribute->getId(), 'attribute_code' => $super_attribute->getAttributeCode(), 'frontend_label' => $super_attribute->getFrontend()->getLabel(), ); } $existingAtt = $product->getTypeInstance()->getConfigurableAttributes(); if(empty($existingAtt) && !empty($newAttributes)){ $configProduct->setCanSaveConfigurableAttributes(true); $configProduct->setConfigurableAttributesData($newAttributes); $configProduct->save(); }
This is a small snippet that should get you there, let me know if you have any questions or need more help.
source share