How to get all manufacturers for category in Magento

I've got such a problem with Magento CMS. I need to retrieve all manufacturers for category. At first glance this is not a problem, because there are a Filter block and Layer navigation from which you can take the necessary methods.

First of all I create a public method in redefined category model /app/code/local/Mage/Catalog/Model/Category.php

public function getManufacturers() { $collection = Mage::getResourceModel('catalog/product_attribute_collection') ->setItemObjectClass('catalog/resource_eav_attribute'); $setIds = $this->getProductCollection()->getSetIds(); $collection->getSelect()->distinct(true); $collection ->setAttributeSetFilter($setIds) ->addStoreLabel(Mage::app()->getStore()->getId()) ->setOrder('position', 'ASC'); $collection->addIsFilterableFilter();; $collection->load(); return $collection; }

I call this method in category template:

$manufscturers = $_category->getManufacturers();

So we get a huge object Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection.

Then:

$items = $manufscturers->getItems();

And we get object Mage_Catalog_Model_Resource_Eav_Attribute.

Then I do not know what to do. That is a dead end. Maybe it's the wrong way?

The version of Magento - 1.4.0.1

Thank's for your help!

-------------Problems Reply------------

Here is how you should get all manufacturers for a category:

$category = Mage::registry('current_category');
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
$manufacturers = array();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'manufacturer') {
$filterBlockName = 'catalog/layer_filter_attribute';
$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
foreach($result->getItems() as $option) {
$manufacturers[$option->getValue()] = $option->getLabel();
}
}
}
var_dump($manufacturers);

Hope this was useful.
Cheers!

As far as I can see, you have achieved product attribute collection that doesn't depends from given category or product collection.

My advise to you is to take product product collection for given cateogory like:

$layer = $this->getLayer();
$productCollection = $layer->getProductCollection();

then iterate through it and get all all attribute values for given category. Cache the results. Exactly the same is done in magento (in "magento way" ofcourse)

Category:magento Views:1 Time:2011-05-16

Related post

  • Copy and Paste Category in Magento 2010-06-17

    I want to copy my first category to a second category in Magento. What should I do? Thanks, Wesley. --------------Solutions------------- By code: <?php $category = Mage::getModel('catalog/category') ->load(123); // The ID of the category you wa

  • how can i remove main-category from the URL of sub-category in magento 2010-09-01

    hi i have a website in magento which contain url like mydomain/Parent-category/sub-category but i wnat to this URL for sub-category Like mydomain/Subcategory..please help me how can i remove main-category from the URL of sub-category in magento...i w

  • Display all sub category product when click main category in magento? 2011-05-31

    Display all sub category product when click main category in magento. like Sub category name(subcategory 1) product 1 of sub category 1 product 2 of sub category 1 product3 of sub category 1 Sub category 2 product 1 of sub category 2 product 2 of sub

  • Displaying the end time of a category in Magento 2011-07-16

    How would I go about displaying the "active to" time that you can assign to a category in Magento. Ultimately I plan on using this information to create countdown timers for some short term sales on a client's site - but I cannot figure out what vari

  • Get the current category with Magento version 1.4.2 2011-07-19

    I have always used : $current_category = Mage::registry('current_category'); to get the current category in Magento version 1.4.1.1 but this isn't working anymore with Magento version 1.4.2 How can I get it with the 1.4.2 version ? --------------Solu

  • Magento filter manufacturers by category 2011-08-15

    So I have a category called "backpacks" and I want to get all the manufacturers of backpacks. How do I accomplish this in Magento. Is this possible? The following code will get all manufacturers but how to I filter it down further. I am using Magento

  • "Shop By " Feature in category page magento 2009-11-02

    My problem is that I am using a theme in magento and using the 2-column left layout of the template. I want to show the "shop by" feature in category page. when I search anything on the site it shows the "shop by" block is the link of the site. Pleas

  • Include product category in Magento order emails 2009-12-16

    I'd like the ability to list the category name alongside the product in the New Order transactional email like shown in the screenshot below. Any help would be appreciated. Thanks. --------------Solutions------------- You must overload the block in M

  • Sales by Category in Magento? 2010-03-22

    We have a category called "Clearance" on our Magento website. Ideally it would be nice to be able to get a report of all orders sold in that category. Is there anyway I can join the orders collection with the products collection and filter by categor

  • Get Current Top Level Category with Magento 2010-06-25

    How do I get the current (active) top level category and its subcategories?? I do not want the root category, just the highest level category and all of its subcategories. If I am in the Women’s Category for instance: Women - Apparel -- Shirts -- Pan

  • New products by category in Magento 2010-07-15

    This should be supposed to be silly thing but it’s driving me nuts! All I want is to show the new products for a specified category, but all I get is new products from any category. Supposing I want to show up the category 74, I’ve tried almost any c

  • How to hide an active category in Magento without disabling the URL? 2010-07-20

    Hey, we're running Magento 1.4.0.1 and would like to hide active categories from the navigation. When we do this, the parent category's URL 404s but all the children categories' URLs are still valid. i.e. magentostore.ex/brands/company is valid magen

  • Category list not working on category page - Magento 2010-09-18

    Firstly I am new to Magento, so please explain in detail if you can help. I have used the following code: <div class="left-nav-inner"> <h3 id="products">Products</h3> <h4>Shop by:</h4> <ul id="product-menu"> <?p

  • Display new arrivals by category in Magento 2010-11-27

    I would like to display the most recently added products from a specific category on my Magento store. I have studied the code at http://www.tridian.com/developer-blog/adding-new-arrivals-to-magento/. From what I've found so far, this seems to be the

  • Pull specific category in Magento and only return configurables 2011-01-20

    I am trying to develop a module that only loops through one category and shows those products. The following code does that, however it will pull the product for every size that is in that category. Can someone help me modify it to only pull the conf

  • Filter For Popular Products By Category in Magento 2011-03-29

    What we are try to do seems simple enough, we want to show the popular products from each category within our menu. We're looking to get 5 of those products, since that's what the UI is designed to handle. We would like them sorted by popularity, whi

  • How to create sub category on Magento APi 2011-04-27

    I am currently using Magento ver. 1.5.0.1. Can anyone tell me how do i create a sub category using soapv2. Here my code format category_data = { "name" => "LIGHTING", "is_active" => 1 } soap.call('catalogCategoryCreate',session,4,category_data,

  • How could I group attributes values in a category in Magento? 2011-06-09

    I've created a custom attribute in Magento, called 'brand_name' and 'brand_id' I need in each categories, to show all the "brands" available for this categories. Example: I've a Shoes category, in my Shoes category I've products with brand name like

  • How to load products which is not in particular category in magento 2011-06-24

    I have to load all available products from the particular attribute-set value additionally it needs to filter only the products which are not under particular category/categories. How can i load product collection here. Please help me --------------S

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.115 (s). 11 q(s)