3

I am trying to build a script that outputs all the product options for each product in the catalog into a CSV file.

I have tried using the code on this page: http://www.atwix.com/magento/configurable-product-attributes/

For this code:

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color');  
foreach ($attribute->getSource()->getAllOptions(true) as $option) {
    echo $option['value'] . ' ' . $option['label'] . "\n";
}

I get no output, what-so-ever.

For this code:

$productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
$attributeOptions = array();
foreach ($productAttributeOptions as $productAttribute) {
    foreach ($productAttribute['values'] as $attribute) {
        $attributeOptions[$productAttribute['label']][$attribute['value_index']] = $attribute['store_label'];
    }
}

I get this error:

Fatal error: Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getConfigurableAttributesAsArray() in /home/tws2/public_html/getopts.php on line 71

Ive been unable to find anything else on the internet for getting at the product options of a product with PHP code.

Can someone please explain to me how to use PHP to get at all the product options data for each product in the catalog, so I can output all this data into a CSV file.

The purpose of this is to transfer the product options data over to an identical Magento server that has the same catalog, just missing the product options data. Once I have all the CSV file of product options I was going to make another script to write them into the identical Magento server. This is how Ive been advised to do this task in-house, if you have a better suggestion please let me know.

  • Did you manage to find a solution for your question? – Sander Mangel Jun 24 '15 at 13:54
  • not a proper solution. i keep transferring over bits of data only to realize that ive missed something out... then i have to transfer that, only to realize ive missed out something again... ive been repeating this process over and over again. a complete solution to this problem would be great! – Jimmery Jun 24 '15 at 15:20
2

No answer but another option. Use Avs_FastSimpleImport to update product data with the attribute values. In the FastSimpleImport settings you can define missing options should be created

Check out the module here

2

Please note that this code you can apply only to the configurable product:

$productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
$attributeOptions = array();
foreach ($productAttributeOptions as $productAttribute) {
    foreach ($productAttribute['values'] as $attribute) {
        $attributeOptions[$productAttribute['label']][$attribute['value_index']] = $attribute['store_label'];
    }
}

So you can check is product configurable before go to this code:

if($product->isConfigurable()) {
    $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
    $attributeOptions = array();
    foreach ($productAttributeOptions as $productAttribute) {
        foreach ($productAttribute['values'] as $attribute) {
            $attributeOptions[$productAttribute['label']][$attribute['value_index']] = $attribute['store_label'];
        }
    }
}

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.