Magento 仅在搜索结果页面中隐藏缺货产品
我们可以通过系统>配置>目录>库存>显示缺货产品,轻松地在类别和目录搜索中隐藏缺货产品Magento 仅在搜索结果页面中隐藏缺货产品,magento,magento-1.7,Magento,Magento 1.7,我们可以通过系统>配置>目录>库存>显示缺货产品,轻松地在类别和目录搜索中隐藏缺货产品 然而,我们怎么能只在搜索结果中隐藏产品呢?我知道一种方法可以实现这一点 内置Magento/app/design/frontend/rwd/default/template/catalogsearch/result.phtml $this->getProductListHtml() ; 提供所需的搜索结果 Inside list.phtml检查一下 $_productCollection=$this-
然而,我们怎么能只在搜索结果中隐藏产品呢?我知道一种方法可以实现这一点 内置Magento/app/design/frontend/rwd/default/template/catalogsearch/result.phtml
$this->getProductListHtml() ;
提供所需的搜索结果
Inside list.phtml检查一下
$_productCollection=$this->getLoadedProductCollection();
Magento允许您在加载集合之前/之后观察集合添加筛选器的方式,称为观察者方式
在您观察到的事件中,尝试使用以下搜索结果:
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);
希望能有所帮助。我知道一种方法可以让你实现这一目标 内置Magento/app/design/frontend/rwd/default/template/catalogsearch/result.phtml
$this->getProductListHtml() ;
提供所需的搜索结果
Inside list.phtml检查一下
$_productCollection=$this->getLoadedProductCollection();
Magento允许您在加载集合之前/之后观察集合添加筛选器的方式,称为观察者方式
在您观察到的事件中,尝试使用以下搜索结果:
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);
希望有帮助。上述使用observer的解决方案也隐藏了该类别中的内容。问题是只在搜索结果中隐藏。因此,直接添加instock filter product collection results.phtml是合适的 i、 e
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection)代码>
如果我遗漏了任何内容,请更正。上述使用observer的解决方案还隐藏了in类别。问题是只在搜索结果中隐藏。因此,直接添加instock filter product collection results.phtml是合适的
i、 eMage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection)代码>
如果我遗漏了任何内容,请更正。您可以覆盖类中的\u getSearchableProducts
函数Mage\u CatalogSearch\u Model\u Resource\u 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')
);
....
}
记得在之后重新索引“目录搜索索引”。您可以覆盖类中的\u getSearchableProducts
函数,以便它始终搜索库存产品
要修改的文件: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')
);
....
}
记得在之后重新索引“目录搜索索引”