Magento 如何在目录搜索集合中添加自定义产品?
目前我正在尝试在CatalogSearch产品集合中添加自定义产品。目前我正在从事Magento 如何在目录搜索集合中添加自定义产品?,magento,search,collections,catalog,Magento,Search,Collections,Catalog,目前我正在尝试在CatalogSearch产品集合中添加自定义产品。目前我正在从事Mage\u CatalogSearch\u Model\u Layer。我知道它的核心部分,但在正确使用代码后,我使用overrideCatalogSearch\u Model进行管理 目前我正在研究这个方法 public function prepareProductCollection($collection) { $collection ->addAt
Mage\u CatalogSearch\u Model\u Layer
。我知道它的核心部分,但在正确使用代码后,我使用overrideCatalogSearch\u 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;
}
此代码将我的自定义产品添加到集合中,但在搜索结果中未找到产品时开始发出。表示如果在搜索结果中找到产品,则添加我的自定义产品,否则不会
我想知道我在哪里犯错?或者任何一步都没有。任何帮助都将不胜感激
谢谢这里是问题:
$collection2 = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', array(1,2));
foreach($collection2 as $customdata)
{
$collection->addItem($customdata);
}
$collection2->getData();为$customdata提供的对象不正确
$customdata是Mage_Catalog_Model_Product的适当
对象
请您详细说明一下好吗?但是当我使用$collection=Mage::getResourceModel('catalogsearch/fulltext_collection')->addFieldToFilter('entity_id',array(1,2));这也给了我同样的结果@amit@KeyurShah,明天见。