【发布时间】:2014-07-08 17:23:08
【问题描述】:
目前我正在尝试在 CatalogSearch 产品集合中添加自定义产品。目前我正在处理Mage_CatalogSearch_Model_Layer。我知道它的核心部分,但在正确处理我的代码后,我使用覆盖 CatalogSearch_Model 进行管理。
目前我正在研究这种方法
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
// my custom code start
$collection2 = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', array(1,2));
$collectiondata=$collection2->getData();
foreach($collectiondata as $customdata)
{
$collection->addItem($customdata);
}
return $this;
}
此代码将我的自定义产品添加到集合中,但在搜索结果中未找到产品时开始发出问题。意味着如果在搜索产品中找到,则添加我的自定义产品,否则不添加。
我想知道我在哪里犯错了?或缺少任何步骤。任何帮助将不胜感激
谢谢
【问题讨论】:
标签: magento search collections catalog