tags:

views:

978

answers:

3

I have an issue with displaying product custom attributes. I've read every resources through google but still no success. The problem is that I have to show size attribute of configurable product on category grid and list view. Every solution on google suggested something like

$_product->getAttributeText('size')

but I ended up at just a single string - "S" or "M" instead of an array. How can I fetch all possible sizes of all simple products which belongs to particular configurable product without much hassle?

UPDATE

After using solution proposed by Joseph Mastey I encountered another problem. I managed to show all possible options for given attribute, but now I need to show only these options which are available to buy. For example if t-shirt size L is out of stock or is disabled, L option should not be shown. How can I solve this issue?

+1  A: 

When dealing with configurable products (or any time you're dealing with a concept for only one type of product, as configurable attributes are), you'll probably be working with getTypeInstance. See below, I grab the configurable attributes for the product, then find the one for size. You could also just run through every configurable attribute if you wanted. Or if size is the only configurable attribute, just skip that if().

$attrs  = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
foreach($attrs as $attr) {
    if(0 == strcmp("size", $attr['attribute_code'])) {
        $options    = $attr['values'];
        foreach($options as $option) {
            print "{$option['store_label']}<br />";
        }
    }
}

Hope that helps! Thanks,

Joe

Joseph Mastey
Thank you very much for your help. There was only one simple issue, getConfigurableAttributesAsArray had to be called with $_product parameter.
artega
A: 

Hello,

I am also trying to show configurable product attributes drop down on grid view, but when I call above code it shows me fatal error : Call to a member function hasData() on a non-object in /app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php on line 240.

Can you please help?

Thanks, Riti

riti
Did you try calling it like this $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
artega
+1  A: 

Using our commercial API extension package NETZKOLLEKTV Core API enables you to add configurable products via Magento Core API among many other additional functions.

For more information visit NETZKOLLEKTIV Core API

You may also visit our tutorial how to create Configurable Products using the SOAP/XML-RPC API (in german, unfortunately).

NETZKOLLEKTIV