Search code examples
phpmagentocsvfeed

Export configurable product size attribute


I have the following issue: I'm trying to build a product feed for a price comparison engine. My store sells clothes, and all my products are configurable. For example, the configurable product T Shirt is made up of 3 simple products, with the clothing size S, M and L.

My feed exports to a .csv file. There is one line for each configurable product. The problem is that i need a column called "size" which would include all the existing sizes of associated simple products (for example S|M|L).

I've tried several solutions like:

$prod_size = $product->getResource()->getAttribute('size')->getFrontend()->getValue($product);

$prod_size = $product->getAttributeText('size');

$prod_size = $product->getData('size');

$prod_size = $product->getSize();

I use this statement to join the data from associated products to the configurable product:

if ($GROUPED_PRODUCT['prod_size'] != "") {
    $PRODUCT['prod_size'] = $GROUPED_PRODUCT['prod_size'];
}

Can anyone please lend a hand?


Solution

  • This will get all the attributes with their values for a 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'];
        }
    }
    print_r($attributeOptions);
    

    Modify as per your need.