0

I have created a custom attribute 'manufacturer' with options like 'Fossil, Tommy Hilfiger, etc'. Now I just need listing for each brand.

For example "https://magento.store.com/fossil.phtml" should return all products under the 'Fossil' manufacturer and likewise. Is there any way to accomplish this.

Thank you in advance.

2

2 Answers 2

1

Here is the logic to filter products by your custom attribute manufacturer.

Below example code filters products with attribute manufacturer value Fossil.

$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('manufacturer', 'Fossil');

foreach ($products as $product) {
    /* Your logic here */
}
3
0

After all researches, I made it. Like I have created a CMS page in CMS > Pages with content

{{block type="core/template" template="page/html/brands.phtml"}}

So the URL looks like.

 https://magento.store.com/brand?q=fossil

For listing the products corresponding to brands

$brand = Mage::app()->getRequest()->getParam('q');



$productModel = Mage::getModel('catalog/product');
$attr = $productModel->getResource()->getAttribute("brands");
if ($attr->usesSource()) {
     $brand_id = $attr->getSource()->getOptionId($brand);
     //$brand_label = $attr->getSource()->getOptionText($brand_id);
}

$_productCollection = Mage::getResourceModel('catalog/product_collection');
Mage::getModel('catalog/layer')->prepareProductCollection($_productCollection);
$_productCollection->addAttributeToSelect('*')->addAttributeToFilter(array( array( 'attribute' => 'brands', 'eq' => $brand_id ) ))->addStoreFilter();

the above logic will find the attribute id first. Then it will add to addAttributeToFilter to find corresponding product collection. Then we can give the style to the listing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.