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

时间:2011-12-20 00:10:38

标签: magento filter

中创建分层导航过滤器
app/design/frontend/base/theme/template/catalog/layer/filter.phtml

如何从此文件中检索当前产品系列中产品价格最高的值?

我已经尝试过我认为来自$this->getMaxPriceInt()的明显选择Mage_Catalog_Model_Layer_Filter_Price,但这似乎不适用于filter.phtml。

3 个答案:

答案 0 :(得分:5)

假设$ collection是'catalog / product'的集合,这应该可以解决问题:

$product = $collection->setOrder('price', 'DESC')->getFirstItem();

答案 1 :(得分:2)

在类别列表中获取最高和最低价格,您可以使用以下代码。

$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文件上使用以下代码。

答案 2 :(得分:0)

请你试试这个(让我知道结果)

$model = Mage::getModel('catalog/product');

$collection = $model->getCollection()
   ->addStoreFilter()
   ->addAttributeToSelect('price')
   ->addAttributeToSort('price', 'asc');

if(!emtpy($collection)):
   foreach($collection as $products) {
      echo $products->getPrice();
      echo $products->getName();
   }
endif;