1

I want to be able to list out all the products by a specific manufacture.

I've been able to get a list of all the manufactures

function getAllManu()
    {
      $product = Mage::getModel('catalog/product');
      $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
                  ->setEntityTypeFilter($product->getResource()->getTypeId())
                  ->addFieldToFilter('attribute_code', 'manufacturer'); //can be changed to any attribute
      $attribute = $attributes->getFirstItem()->setEntity($product->getResource());
      $manufacturers = $attribute->getSource()->getAllOptions(false);

      return $manufacturers;
    }

But I don't know what to do next.

url string should be something like this:

website.com/manufacture/ (with pagination support)

EDIT

I'm guessing I need to do my own controller and extend extends Mage_Core_Controller_Front_Action

2
  • Do you mean manufacture is your action name, or manufacture will be dynamic here? Aug 25, 2014 at 6:29
  • manufacture is action name. Sorry that wasn't clear.
    – Brad
    Aug 26, 2014 at 13:34

1 Answer 1

2

Yes, you're right, you need your own controller but it would be better if you'd extend the Mage_Catalog_CategoryController. This way you could reuse some methods.

So, create your new module and in config.xml place:

<config>
...
<frontend>
    <routers>
        <manufacturer>
            <use>standard</use>
            <args>
                <module>Namespace_Module</module>
                <frontName>manufacturer</frontName>
            </args>
        </manufacturer>
    </routers>  
</frontend>

And your controller:

class Namespace_Module_ManufacturerController extends Mage_Catalog_CategoryController
{

}

This way http://mymagesite.com/index.php/manufacturer/view/name/nike will point to viewAction() method with $_GET['name']='nike'.

Now, override the _initCatagory() & viewAction() to match your requirements.

Also, you will need to override Mage_Catalog_Block_Product_List (see: http://inchoo.net/ecommerce/magento/overriding-magento-blocks-models-helpers-and-controllers/) and apply a manufacturer filter to the product collection rendered.

To apply the filter, first you would have to get from the request (the $_GET):

$manufacturer = $this->getRequest()->getParam('name');

and then in the _getProductCollection of the overridden block, change

$this->_productCollection = $layer->getProductCollection();

to

$this->_productCollection = $layer->getProductCollection();
if(isset($manufacturer))
   $this->_productCollection->addAttributeToFilter($manufacturer);

I have not tested it but it should work.

0

Your Answer

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

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