Hello,
I'm using this code to get Magento manufacturers' label in current category page. (to show brands related to current category not all the brands):
$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(); } } }
I've added above code in a custom phtml file and add an custom cms block to category page pointing to this phtml file.
Actually it works fine in category pages. All I need is to get manufacturer IMAGE instead of their LABEL.
By the way I've used var_dump($option) to find the image or image url, but there is no such a thing for $option!
Please help me what to do.
Thanks
You'll have to extend Mage_Catalog_Model_Layer in order to modify this function:
public function getFilterableAttributes() { // $entity = Mage::getSingleton('eav/config') // ->getEntityType('catalog_product'); $setIds = $this->_getSetIds(); if (!$setIds) { return array(); } /** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */ $collection = Mage::getResourceModel('catalog/product_attribute_collection'); $collection ->setItemObjectClass('catalog/resource_eav_attribute') ->setAttributeSetFilter($setIds) ->addStoreLabel(Mage::app()->getStore()->getId()) ->setOrder('position', 'ASC'); $collection = $this->_prepareAttributeCollection($collection); $collection->load(); return $collection; }
It this attribute collection, you need to include your custom image name. You can check how SQL query looks by logging $collection->getSelect().
Other way would be to put all manufacturer images into media/manufacturer directory, and to add images like 1.jpg, 2.jpg, 3.jpg by manufacturer id, or you can name them by labels, and later you can load render paths to such images like:
$manufacturerImagePath = Mage::getBaseUrl('media') . 'manufacturer/' . $option->getValue() . '.jpg';
or with:
$manufacturerImagePath = Mage::getBaseUrl('media') . 'manufacturer/' . $option->getLabel() . '.jpg'
Of course, this approach is not the best practice, but it can solve the problem to you if you're not able to deal with extending Mage_Catalog_Model_Layer class.
There is a very useful Magento extension that you can leverage. I am using it too in my store and am quite happy with it. This Magento shop by brand extension from FME allows my customers to search for products from a particular brand or manufacturer. I can also create a separate brand page with a title, description, logo etc. There are other very useful features like users can search by alphabetical listings, display prominent brands in featured block, show related brands etc. You can have a look at it for detailed features below.
https://marketplace.magento.com/fme-shop-by-manufacturer-brand.html
As an Online logo maker, I just want to say that this is a fabulous piece of knowledge from your side and I also want to say that keep writing that type of content just for the assistance of the newbie designers who want that type of unique command.