我需要以数组形式访问当前加载的搜索结果,但从catalog/layer/view.phtml
中。
我尝试使用以下代码,但它返回一个空数组...
$products = $this->getLayout()
->getBlockSingleton('catalog/product_list')
->getLoadedProductCollection()
->toArray();
echo "<pre>".print_r($products,true)."</pre>";
die();
这可能吗?
您需要
获取搜索模型。
下面是获取搜索模型的代码:
$search = Mage::getSingleton('catalogsearch/advanced');
以下是搜索产品的代码:
$search = Mage::getSingleton('catalogsearch/advanced')->addFilters(array('name' => $term));
然后,要在对象中获取结果,请输入以下行:
$search->getProductCollection();
祝你好运
佩萨赫