Magento Forum

   
list of Manufacturer with products.. 
 
Brazil_Dist
Jr. Member
 
Avatar
Total Posts:  10
Joined:  2009-06-11
Roche, Switzerland
 

Hello all!

I am working on a new project and I need the list of all manufacturer with min 1 article.

I have a code pretty good but it show me all manufacturer even manufacturer with no products.

I sure it’s not a big deal to do this check but my PHP skills limited.... can some one please help me?

there is the code:

<?php

    
include_once 'app/Mage.php';
    
Mage::app();

    
$attribute Mage::getModel('eav/entity_attribute')
            ->
loadByCode('catalog_product''manufacturer');

    
$valuesCollection Mage::getResourceModel('eav/entity_attribute_option_collection')
            ->
setAttributeFilter($attribute->getData('attribute_id'))
            ->
setStoreFilter(0false);

    
$preparedManufacturers = array();
    foreach (
$valuesCollection as $value{
        $preparedManufacturers[$value
->getOptionId()$value->getValue();
    
}

    
if (count($preparedManufacturers)) {
    
foreach($preparedManufacturers as $optionId => $value{
        
echo ' <a href="catalogsearch/advanced/result/?manufacturer[]='.$optionId.'"><img style="float: right; margin: 2px;" src="/media/catalog/brands/'.str_replace(' ''_'$value ).'-ico.png" alt="'$value .'" title="'$value .'"class="ico-brands"></a> ';
        
        
    
}
  
} ?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brazil_Dist
Jr. Member
 
Avatar
Total Posts:  10
Joined:  2009-06-11
Roche, Switzerland
 

OK the solution came form the Fragento forum finnaly.

it’s so simple . just past :

if($collection->getSize()) before the echo.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Amasty
Mentor
 
Avatar
Total Posts:  3749
Joined:  2009-11-10
 

Hi!
Improved Navigation module includes ‘creation of manufacturer lists’ functionality - http://amasty.com/improved-navigation-shop-by-brands.html

Also “shop by brand’ functionality allows to:
- Perfectly manage brand functionality
- Brand logos display mode
- Featured brands block
- Multiple and single select of ‘brands’ attributes
- Nice short urls for brand pages

For more details, user guide and live demo please follow the link http://amasty.com/improved-navigation-shop-by-brands.html

 
Magento Community Magento Community
Magento Community
Magento Community
 
FMEExtensions
Mentor
 
Avatar
Total Posts:  1140
Joined:  2009-08-07
 

If you need ready made functionality use the following FMEs Magento Extension;

Shop By Brands Magento Extension by FME

 
Magento Community Magento Community
Magento Community
Magento Community
 
christinavick
Sr. Member
 
Total Posts:  259
Joined:  2013-11-13
 

Hi,

Get list of all Manufacturers/Brands with products count

The following code will return the All the manufactures/brands of Magento site with products count:

/**
     * Get all Brands collection
     *
     * @return Mage_Catalog_Block_Product_Brand
     */
    public function getAllBrands()
    
{
      $product 
Mage::getModel('catalog/product');
      
$attributes Mage::getResourceModel('eav/entity_attribute_collection')
                  ->
setEntityTypeFilter($product->getResource()->getTypeId())
                  ->
addFieldToFilter('attribute_code''manufacturer');
      
$attribute $attributes->getFirstItem()->setEntity($product->getResource());
      
$manufacturers $attribute->getSource()->getAllOptions(false);

      
# adding products count to the brands collection
      
foreach ($manufacturers as $key => $value{
           $collection 
Mage::getModel('catalog/product')->getCollection();
           
$collection->addFieldToFilter(array(array('attribute' => 'manufacturer''eq' => $value['value'])));
           
$numberOfProducts count($collection);
           
$manufacturers[$key]['products_count'$numberOfProducts;
       
}

      
# sort the array in desc order
      
$pcount = array();
      foreach (
$manufacturers as $key => $row)
      
{
         $pcount[$key] 
$row['products_count'];
      
}
      array_multisort
($pcountSORT_DESC$manufacturers);

      return 
$manufacturers;
    
}

Hope this will help you!!

Thanks

iLoveMage

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