【问题标题】:How to add custom product on catalog search collection?如何在目录搜索集合中添加自定义产品?
【发布时间】: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


    【解决方案1】:

    这里是问题:

    $collection2 = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', array(1,2));
    foreach($collection2 as $customdata)
    {
    $collection->addItem($customdata);
    }
    

    $collection2->getData();为 $customdata 提供了不合适的对象。

    $customdata 是正确的object of Mage_Catalog_Model_Product

    【讨论】:

    • 您能详细说明一下吗?
    • 但是当我使用 $collection = Mage::getResourceModel('catalogsearch/fulltext_collection')->addFieldToFilter('entity_id', array(1,2));它也给了我同样的结果。 @amit
    • @KeyurShah,明天见。
    猜你喜欢
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多