0

im create configurable product programatically. all works fine but attribute is not set to configurable product when i open product in admin is look like

see image.

enter image description here

how i can set attribute to configurable product..

i used this code to set attribute

$superAttributeIds = array('92');
$cProduct = Mage::getModel('catalog/product')->load(1261);
$cProduct->getTypeInstance()->setUsedProductAttributeIds($superAttributeIds); 

$cProduct->setCanSaveConfigurableAttributes(true);
try
{
        $cProduct->save();
}
catch( Exception $e) 
{
        echo $e->getMessage();
}
0

Try this solution

        foreach (array('size', 'color') as $attributeCode) {
            $usedProductAttributesIds[] = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, $attributeCode)->getId();
        }

        $configProduct->getTypeInstance()->setUsedProductAttributeIds($usedProductAttributesIds);
        $configurableAttributesData = $configProduct->getTypeInstance()->getConfigurableAttributesAsArray();

        $configProduct->setCanSaveConfigurableAttributes(true);
        $configProduct->setConfigurableAttributesData($configurableAttributesData);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.