Magento – How to associated products to configurable product programmatically

configurable-productproduct

How can I associate simple products to a configurable product programmatically?

Best Answer

Assuming you know the product ids and the simple products have values for the configurable attribute:

$configurable_product = Mage::getModel('catalog/product')->load($id_of_configurable);
$configurable_product->getTypeInstance()
                     ->saveProducts(
                         $configurable_product, 
                         $array_of_simple_product_ids
                     );
Related Topic