访问Magento搜索结果集合
我需要获取由访问Magento搜索结果集合,magento,search,Magento,Search,我需要获取由Magento搜索结果返回的sku列表。我在谷歌搜索了一下,但在搜索结果页面上显示这些产品时,却找不到它们的来源。我打开了searchresults.phtml文件。当调用$this->getChildHtml('content')时,看起来就是产品循环的地方,但我认为核心/文本列表有一些魔力。无论如何,我想访问搜索结果提供的产品集合,并在searchresults.phtml文件中循环使用它 编辑:只是澄清一下,我真正需要的是访问来自搜索结果的产品集合 编辑:结果显示searchr
Magento
搜索结果返回的sku
列表。我在谷歌搜索了一下,但在搜索结果页面上显示这些产品时,却找不到它们的来源。我打开了searchresults.phtml
文件。当调用$this->getChildHtml('content')
时,看起来就是产品循环的地方,但我认为核心/文本列表有一些魔力。无论如何,我想访问搜索结果提供的产品集合,并在searchresults.phtml文件中循环使用它
编辑:只是澄清一下,我真正需要的是访问来自搜索结果的产品集合
编辑:结果显示searchresults.phtml是一个自定义页面。目录搜索 下课
\app\code\core\Mage\CatalogSearch\Block\Advanced\Result.php
在result.php中创建新函数
protected function skuProductCollection(){
return $this->getSearchModel()->getProductCollection()->getColumnValues('sku');
}
并在phtml文件中编写以下代码
<?php $allSku = $this->skuProductCollection() ?>
<?php print_r($allSku); ?>
希望这能帮助你在app/design/frontend/{package}/{theme}/catalog/product/list.phtml中 有一句话:
$_productCollection=$this->getLoadedProductCollection();
如果您想在该模板中获取所有SKU(不限于每页),可以执行以下操作:
$select = clone $_productCollection->getSelect();
$select
->reset(Zend_Db_Select::LIMIT_COUNT)//remove this line if you want list of skus belonging only to current page
->reset(Zend_Db_Select::LIMIT_OFFSET) // and this one too
->reset(Zend_Db_Select::COLUMNS)
->reset(Zend_Db_Select::ORDER)
->columns('sku');
$all_skus = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchCol($select,'');
在意识到我正在使用自定义模板后,我现在看到我可能需要解决两个问题: catalogsearch/result.phtml catalogsearch/advanced/result.phtml 对于result.phtml,块是Mage\u CatalogSearch\u block\u result。在该块中,您可以调用
$this->\u productCollection()
。sku在集合中。我想这对高级教育也是一样的
编辑:对于高级搜索,您必须使用
$this->getChild('search\u result\u list')->\u productCollection
我需要访问searchresults.phtml文件中的产品集合。