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

Get list of all Manufacturers with product count
 
MonsoonCons
Jr. Member
 
Total Posts:  5
Joined:  2012-04-18
 

I am using the following code to list all the manufacturers and it works like a charm:

$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)) {
    
echo "<h2>Manufacturers</h2><ul>";
    foreach(
$preparedManufacturers as $optionId => $value{
        
echo "<li>" $value " - (" $optionId ")</li>";
    
}
    
echo "</ul>";
}

What I am looking for is a way to display the number of products associated with each of the manufacturers. Can someone please tell me the way of doing this?

Many thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
sumantechno
Guru
 
Avatar
Total Posts:  478
Joined:  2010-03-09
Bangalore
 

Check this code..This will solve your problem

<?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)) {
        
echo "<h2>Manufacturers</h2><ul>";
        foreach (
$preparedManufacturers as $optionId => $value{
            $collection 
Mage::getModel('catalog/product')->getCollection();
            
$collection->addFieldToFilter(array(array('attribute' => 'manufacturer''eq' => $optionId)));
            
$mumberOfProducrt count($collection);
            echo 
"<li>" $value " - (" $mumberOfProducrt ")</li>";
        
}
        
echo "</ul>";
    
}
?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
shivamsinghal
Jr. Member
 
Total Posts:  1
Joined:  2013-03-02
 

Hi,
I need to know where to put this to test?
please help?

 
Magento Community Magento Community
Magento Community
Magento Community
 
sergioamdreis
Jr. Member
 
Total Posts:  1
Joined:  2013-02-12
 

Hi,
This works perfectly. Thanks.

To try it, just create a test.php file in your magento root, with this code:

<?php

include 'app/Mage.php';
Mage::app();
echo 'TESTING';

.... CODE HERE ...
?>

Then try it using the url:  http://127.0.0.1/magento/test.php

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

Hello ... I use this code ans it’s work well..

but I need some improvement ... how do you show only manufacturer with product… ? thanks a lot.

 
Magento Community Magento Community
Magento Community
Magento Community
 
kstorm
Jr. Member
 
Total Posts:  4
Joined:  2013-07-09
 
Brazil_Dist - 25 June 2013 01:12 AM

Hello ... I use this code ans it’s work well..

but I need some improvement ... how do you show only manufacturer with product… ? thanks a lot.

BUMP BUMP. Need it to show the same.

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