1

I'm configuring a magento webshop for one of our clients. They've got colorcodes and due to that I have to set up configurable products. However, before the configurable products are being shown on the webshop I need to select an attribute to assign to it...

Now this is really unhandy if I have to import an entire catalog of +/- 800 products...

I already found the next script to make this automatically but I have no clue where to put it... I've already tried using it in the configurable.php file, didn't work. Please help me out!

    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(), 
        ); 
        echo "test ";
    } 
 echo "test2 ";
    if(empty($existingAtt) && !empty($newAttributes)){ 
        $configProduct->setCanSaveConfigurableAttributes(true); 
        $configProduct->setConfigurableAttributesData($newAttributes); 
        $configProduct->save(); 

1 Answers1

0

This script is best used a shell script to assign the config attributes to products. Its not complete thou. I had to add alot to this script, like the ability to feed it product ids, and attribute codes to configure along with the configurable attributes.

Its hard to show you whats missing from it, since you need alot more than just this script to assign the attributes. I run one script that grabs all the ids of the configurable products and then makes a cache file with them. I them use another script to feed those ids to the above script so that it may configure them. So in total, 3 scripts. I then use a shell script to run that process.

This was posted by another user to help point you in the direction you need to be heading, but is no way a standalone script. I can email you my source files for all three scripts and you can reverse them down to see what I did if that helps.

Rob David
  • 11
  • 2
  • 1