我想在自定义模块的前端获取属于所选制造商的产品列表。我成功获得了制造商名单,但我无法检索与特定制造商相关的产品。我搜索了很多,但我没有得到任何解决方案。
这是我的代码 阻止文件: -
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;
}
?>
答案 0 :(得分:0)
如上所述,您需要执行以下几个步骤:
1)转到属性集,并确保将“manufacturer”分配给您正在使用的属性集。
2)确保在属性选项中添加了一些制造商。
3)为您的产品指定其中一个选项。
根据您的magento版本,这应该有效:
<?php echo $_product->getAttributeText('manufacturer') ?>
我可以看到你得到的错误:
给出错误在
中的非对象上调用成员函数getManufacturer()您确定要将此代码放在此行之后:
<?php $_product = $this->getProduct(); ?>
希望这个解决方案让你有一天...... !!!