Question

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.

Était-ce utile?

La solution

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 */
}

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top