Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Issues Returning Product Attributes? 
 
willolbrys
Jr. Member
 
Total Posts:  11
Joined:  2008-05-05
Brooklyn, NY
 

I cobbled this little bit of code to return the names of manufacturers within a given category, but the problem is it only works on one category and not the others. I am at my wit’s end trying to understand why! I’m using the Magento sample data as a base and afaik its not working due to some type of dwarven runes etched into my laptop.

class Test_Catalog_Block_Navigation extends Mage_Catalog_Block_Navigation
{
    
public function drawBrandBrowse($urlKey)
    
{    
        
// get the product category based on the url key.
        
$categories Mage::getModel('catalog/category')->getCollection()
                        ->
addAttributeToFilter(array(array('attribute'=>'url_key''eq'=>$urlKey)))
                        ->
load();
                        
        
$category Mage::getModel('catalog/category')->load($categories->getFirstItem());
        
        if (
$categories->count() != 1):
            return 
Mage::getModel('catalog/category');
        endif;
        
        
$products $category->getProductCollection();
        
$products->addAttributeToSelect(array('manufacturer'), 'inner');
        
        
$pm = array();
        
        foreach(
$products as $product){
          $pm[] 
$product->getAttributeText("manufacturer");
        
}

        
return array_unique($pm);
    
}
}

this code works fine with the electronics category but not living-room or furniture or apparel or even subcategories of electronics. Is it because they are different types of products? I know some of them dont have the manufacturer attribute set, but the majority do.

thanks and confused,

will

p.s. when it works for electronics this is what I get:

array
        
=> string 'Crucial' (length=7)
        
=> string 'Crucial' (length=7)
        
=> string 'Samsung' (length=7)
        
=> string 'AMD' (length=3)
        
=> string 'Western Digital' (length=15)
        
=> string 'Western Digital' (length=15)
        
=> string 'Intel' (length=5)
        
=> string 'LG' (length=2)
        
=> string 'Intel' (length=5)
        
=> string 'Seagate' (length=7)
        
10 => string 'Seagate' (length=7)
        
11 => string 'LG' (length=2)
        
12 => string 'Apple' (length=5)
        
13 => string 'Microsoft' (length=9)
        
14 => string 'Logitech' (length=8)
        
15 => string 'Logitech' (length=8)
        
16 => string 'Microsoft' (length=9)
        
17 => string 'HTC' (length=3)
        
18 => string 'Crucial' (length=7)
        
19 => string 'AMD' (length=3)
 
Magento Community Magento Community
Magento Community
Magento Community
 
willolbrys
Jr. Member
 
Total Posts:  11
Joined:  2008-05-05
Brooklyn, NY
 

Well, I figured it out. It’s because, somehow I can’t explain, the same data is incomplete. It took me about 15 hours to figure it out. Given I’m not a Magento whiz, and I learned a lot about EAV in the process, I’m a little miffed. The sample data does not include all the entries for catalog_product_entity_int. When I made a new product it would appear, but tons of the products don’t have the manufacturer attribute_id (102) assigned to its proper entity in this table. Still, the manufacurer is appearing the admin panel. Could someone please tell me how that is even possible?! All these products are assigned their proper manufacurer in the admin panel, and yet there are only NINETEEN entries in catalog_product_entity_int.

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