仅在搜索结果页中隐藏缺货产品

时间:2014-11-19 15:55:59

标签: magento magento-1.7

我们可以通过以下方式轻松隐藏类别和目录搜索中的缺货产品:系统>配置>目录>库存>显示缺货产品

然而,我们如何才能在搜索结果中隐藏产品?

3 个答案:

答案 0 :(得分:4)

您可以覆盖班级_getSearchableProducts中的Mage_CatalogSearch_Model_Resource_Fulltext功能,以便始终搜索库存产品。

要修改的文件:app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php

/**
 * Retrieve searchable products per store
 *
 * @param int $storeId
 * @param array $staticFields
 * @param array|int $productIds
 * @param int $lastProductId
 * @param int $limit
 * @return array
 */
protected function _getSearchableProducts($storeId, array $staticFields, $productIds = null, $lastProductId = 0, $limit = 100)
{        
    ...

    ->join(
        array('stock_status' => $this->getTable('cataloginventory/stock_status')),
        $writeAdapter->quoteInto(
            'stock_status.product_id=e.entity_id AND stock_status.stock_status = 1 AND stock_status.website_id=?', // add stock_status = 1 condition
            $websiteId
        ),
        array('in_stock' => 'stock_status')
    );

    ....
}

请记住以后重新索引“目录搜索索引”。

答案 1 :(得分:1)

使用观察者的上述解决方案也隐藏了类别。问题是只在搜索结果中隐藏。所以直接添加instock过滤器产品集合results.phtml是合适的。

Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);

如果我在这里想念任何事情,请纠正我。

答案 2 :(得分:0)

我知道你可以通过哪种方式实现这一目标。

在Magento / app / design / frontend / rwd / default / template / catalogsearch / result.phtml里面

$this->getProductListHtml() ;

为您提供所需的搜索结果。

在list.phtml里面检查一下。

$_productCollection=$this->getLoadedProductCollection(); 

Magento允许您在加载集合之前/之后观察集合添加过滤器的方式,称为观察者方式

在您观察的事件中,请尝试使用以下特别针对搜索结果:

Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);

希望它有所帮助。

相关问题