Magento Forum

   
[SOLVED] get configurable attribute - available values in catalog/product/list.phtml
 
tweidt
Jr. Member
 
Total Posts:  2
Joined:  2011-09-20
 

Hello,

i have a problem, to display the available options from a dropdown attribute in the category-view.
I have a configurable atricle with a dropdown color list. For the product, i add 10 products for the colors red and black.
On the article detail page, the selectbox is visible whit the options red and black.

i want this two options now in the category-view, because, i want filter the procuts with jquery and i need the possible colors.

in my categoryview i show all products, grouped by subcatgories. The code show like this

<?php 
    $_category 
$this->getLayer()->getCurrentCategory();
    
    
$subs $_category->getAllChildren(true);
    
$show_parent false;
    
?>
    
    <?php 
if (count($subs) == && $subs[0] == $_category->getId()) $show_parent true?>
    <?php 
    
foreach($subs as $cat_id) :
        if (
$cat_id == $_category->getId() && !$show_parent) continue;

        
$category = new Mage_Catalog_Model_Category();
        
$category->load($cat_id);
    
?>
    
<div class="category-item">
        <
div class="category-headline">
            <
div class="bg"></div>
            <
div class="label"><h1><?php echo $category->getName();?></h1></div>
            <
div class="clearer"></div>
        </
div>
        </
h1>    
        <
div class="products">
            <
ul>
                
<?php 
                    $collection 
$category->getProductCollection();
                    
$collection->setOrder('price''asc') ;
                    foreach (
$collection as $_product) :
                        
$product = new Mage_Catalog_Model_Product();
                         
$product->load($_product->getId());    
                
?>        
                
<li class="item" data-price="<?php echo number_format($product->getFinalPrice(), 2) ?>">
                    <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                        <
img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(236); ?>" width="236" height="236" alt="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>" />
                    </
a>
                        
                    <
div class="short-description">
                        
<?php echo $product->getName(); ?><br/>
                        
<?php echo number_format($product->getFinalPrice(), 2?> &euro;
                    </
div>
                    
<?php 
                    
                    ?>
                
</li>
                
                
<?php endforeach;?>
            
</ul>
            <
div class="clearer"></div>
        </
div>
    </
div>
    
<?php endforeach;?>

I tried

$product->getAttributeText('shirt_color');

but this returned false. its not available.

i tried many other thinks, i founded by google, but the results were in generell, NULL, false or a fatal error. :(

i hope anyone can help.

Greets Tommy

 
Magento Community Magento Community
Magento Community
Magento Community
 
tweidt
Jr. Member
 
Total Posts:  2
Joined:  2011-09-20
 

I solved by Problem.

I add a method to

file:

app/code/local/Mage/Catalog/Model/Product/Type/Configurable.php

method:

/**
     * Retrieve Configurable Attribute as array
     *
     * @param  Mage_Catalog_Model_Product $product
     * @param $codeid
     * @return array
     */    
    public function getConfigurableAttributeAsArray($product$codeid{
        $attrs 
$this->getConfigurableAttributesAsArray($product);

        
$res = array();
        
        foreach (
$attrs as $attr{
            
if ($attr['attribute_code'== $codeid && is_array($attr['values'])) {
                
foreach ($attr['values'as $value{
                    
if (is_array($value)) {
                        $res[] 
$value['label'];
                    
}
                }
            }
        }  

        
return $res;
    
}

In my

app/design/frontend/[THEMEPACKAGE]/[THEME]/template/catalog/product/list.phtml

i add this lines to get the avaible values

if ($product->isConfigurable()) {
    $colors 
$product->getTypeInstance(true)->getConfigurableAttributeAsArray($product"article_color");
}

Greets Tommy

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top