2
我想要在自定義模塊的前端獲取屬於選定製造商的產品列表。我成功地獲得了製造商名單,但我無法檢索與特定製造商相關的產品。我搜查了很多,但我沒有得到任何解決方案。如何獲得製造商的產品?
這裏是我的代碼 塊文件: -
public function __construct()
{
parent::__construct();
$brand_id = $this->getRequest()->getParam('id');
$layer = $this->getLayer();
//$collection = Mage::getModel('catalog/product')->getCollection()
$collection = $layer->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('manufacturer', 20);
$this->setCollection($collection);
}
public function getProductCollection()
{
if (is_null($this->_productCollection))
{
$layer = $this->getLayer();
//$collection = Mage::getModel('catalog/product')->getCollection()
$collection = $layer->getProductCollection()
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addAttributeToFilter('manufacturer', 20)
->addStoreFilter(Mage::app()->getStore()->getId())
->addMinimalPrice()
->addUrlRewrite();
$this->_productCollection = $collection;
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_productCollection);
}
return $this->_productCollection;
}
public function getColumnCount()
{
return 3;
}
,這是我的PHTML代碼
<?php
$product = $this->getProductCollection();
foreach ($product as $prods)
{
echo '<pre>'; print_r($prods->getData()); die;
}
?>