Magento-从分层导航检索当前集合中的最高产品价格

Magento-从分层导航检索当前集合中的最高产品价格,magento,filter,Magento,Filter,分层导航过滤器是在中创建的 app/design/frontend/base/theme/template/catalog/layer/filter.phtml 如何在此文件中检索当前产品集合中最高产品价格的值 我已经尝试了我认为是从Mage\u Catalog\u Model\u Layer\u Filter\u Price中的明显选择$this->getMaxPricint(),但这似乎在Filter.phtml中不起作用。假设$collection是“Catalog/product”的集

分层导航过滤器是在中创建的

app/design/frontend/base/theme/template/catalog/layer/filter.phtml
如何在此文件中检索当前产品集合中最高产品价格的值


我已经尝试了我认为是从
Mage\u Catalog\u Model\u Layer\u Filter\u Price
中的明显选择
$this->getMaxPricint()
,但这似乎在Filter.phtml中不起作用。

假设$collection是“Catalog/product”的集合,这应该可以做到:

$product = $collection->setOrder('price', 'DESC')->getFirstItem();
你能试试这个吗(告诉我结果)


获得最高和最低的价格在类别清单,你们可以使用下面的代码

$min_price = Mage::getSingleton('catalog/layer')->setCurrentCategory(Mage::registry('current_category'))->getProductCollection()->getMinPrice();
$max_price = Mage::getSingleton('catalog/layer')->setCurrentCategory(Mage::registry('current_category'))->getProductCollection()->getMaxPrice();
但它不适用于搜索和高级搜索层导航。因此,您可以使用下面的代码进行所有页面层导航。
$min_price = $this->getLayer()->getProductCollection()->getMinPrice();
$max_price = $this->getLayer()->getProductCollection()->getMaxPrice();

您可以在
app/design/frontend/THEME/default/template/catalog/layer/view.phtml
文件上使用以下代码。

我不这么认为分层导航加载了您访问目录的所有产品价格。在我看来,系统会过滤您选择的价格范围内的产品。因此,根据Magento wiki,MaxPrice不应可用:
价格范围也被逻辑地挑选出来显示为另一个过滤器。范围本身是由范围内所含产品的价格决定的。显示的价格范围永远不会超过10个,产品也会相应地分发。
检查此主题Hi Oğuz,我接受在呈现分层导航时已对集合进行过滤,并且我需要另一种检索最高价格的方法。出于这个原因,我决定为同一类别创建另一个集合,按价格排序,限制为1条记录。现在的问题是,当我尝试获取产品价格时,它会导致一个错误:
调用未定义的方法Mage_Reports\u Model\u Mysql4\u product_Collection::getPrice()
@Oğuzğelikdemir:这是我用来检索集合的代码:
$catid=2;$cat=Mage::getModel('catalog/category')->load($catid);$storeId=Mage::app()->getStore()->getId();$products=Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('price')->addCategoryFilter($cat)->setStoreId($storeId)->addStoreFilter($storeId)->setOrder('price','ASC')->setPage(1,1);$highprice=999//$产品->获取描述()谢谢-我尝试了以下
$catid=2$可见性=数组(Mage\u目录\模型\产品\可见性::可见性\两者,Mage\u目录\模型\产品\可见性::可见性\搜索中);$highprice=Mage::getModel('catalog/category')->load($catid)->getProductCollection()->addAttributeToSelect('final_price')->addAttributeToFilter('visibility',$visibility)->setOrder('price','DESC')->getFirstItem()但它返回“1”,我的最高价格应该更接近500英镑?还有,你知道为什么
Mage::registry('current_category')
会产生错误吗?试试不带->addAttributeToSelect('final_price')至于错误,我不知道。你想用它做什么?错误是什么?删除
->addAttributeToSelect('final_price')
会产生相同的值。奇怪的我想使用
->addAttributeToSelect('final_price')
动态设置类别ID。完整解决方案:
$layer=Mage::getSingleton('catalog/layer');$\u category=$layer->getCurrentCategory();$catid=$_category->getId();$visibility=数组(Mage\u目录\模型\产品\可见性::可见性\两者,Mage\u目录\模型\产品\可见性::可见性\搜索中);$highprice=Mage::getModel('catalog/category')->load($catid)->getProductCollection()->addAttributeToFilter('visibility',$visibility)->setOrder('price','DESC')->getFirstItem()->getPrice()谢谢Himansu,它帮助我在搜索页面中找到最低价格+从我这里得到1
$min_price = $this->getLayer()->getProductCollection()->getMinPrice();
$max_price = $this->getLayer()->getProductCollection()->getMaxPrice();