我用函数在 app/code/local/myown/layoutmods/catalog/block/product/list/ 中编写了 Manufacturer.php 文件。现在,当我尝试使用它时,它会加载所有产品。我检查并调用了该文件,但它不会按制造商过滤。谢谢大家的建议。
protected function _getProductCollection() {
if (is_null($this->_productCollection)) {
// Get attribute value id:
$manufacturer_name = Mage::registry( 'current_category' )->getName();
$productModel = Mage::getModel('catalog/product');
$attr = $productModel->getResource()->getAttribute('manufacturer');
if ($attr->usesSource()) {
$manufacturer_id = $attr->getSource()->getOptionId($manufacturer_name);
}
// load and filter product collection
$collection = Mage::getModel('catalog/product')->getCollection();
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->addStoreFilter();
$this->_productCollection = $collection;
$this->_productCollection->addAttributeToSelect( 'manufacturer' )->addAttributeToFilter( 'manufacturer', array( 'eq' => $manufacturer_id ) );
}
return $this->_productCollection;
}