我正在尝试更新我的目录和目录搜索列表集合Magento\Catalog\Model\Layer::getProductCollection()
。我只需要在我的列表中显示分组产品。
首先,当我试图覆盖Magento\Catalog\Model\Layer
我的自定义模块时,它不起作用。
所以,我直接在vendor/magento/module-catalog/Model/Layer.php
. 该集合仅适用于图层导航过滤器,list.phtml
但不适用于图层导航过滤器。
任何人都可以让我知道如何覆盖 Magento 2 中的目录和目录搜索列表集合吗?
public function getProductCollection()
{
if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
$collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
} else {
$collection = $this->collectionProvider->getCollection($this->getCurrentCategory());
$collection->addAttributeToFilter('type_id', array('eq' => 'grouped'));
$this->prepareProductCollection($collection);
$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
}
return $collection;
}