2013-10-10 95 views
0

我需要获得由Magento搜索结果返回的skus的列表。我浏览过并搜索了一下,但在搜索结果页面上显示产品时找不到产品的来源。我打开了searchresults.phtml文件。它看起来像是当$this->getChildHtml('content')被称为是产品循环的地方,但我认为核心/文本列表有一些魔力。无论如何,我想访问搜索结果提供的产品集合,并在searchresults.phtml文件中循环访问。访问Magento搜索结果集合

编辑:只是为了澄清,我真正需要的是访问来自搜索结果的产品集合。

编辑:原来,searchresults.phtml是一个自定义页面。

回答

0

意识到我是用一个自定义模板,我现在看到的工作大概有两个地方我需要解决后:

catalogsearch/result.phtml

catalogsearch /先进/ result.phtml

对于result.phtml该块是Mage_CatalogSearch_Block_Result。在该区块中,您可以拨打$this->_productCollection()。 SKU在收藏中。我假设高级版本也是如此。

编辑:对于高级搜索,你必须使用$this->getChild('search_result_list')->_productCollection

0

目录搜索

延长下面类

\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); ?> 

希望这会帮助你

在应用程序/设计/前端/ {包}/{}主题
+0

我需要访问searchresults.phtml文件中的产品集合。 – gwgeller

+0

嗨@gwgeller我编辑我的答案检查它 – shivam

1

/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,'');