Magento: 单产品(product)或者当前类别(category)最大和最小价格 Min/Max Product Price in a Category

1. 当前类别最大最小价格:

$minPrice   = Mage::getModel('catalog/product')->getCollection()
			   ->addStoreFilter()
			   ->addAttributeToSelect('price')
			   ->addAttributeToSort('price', 'ASC')->getFirstItem()->getMinimalPrice()*1;
			   
$maxPrice   = Mage::getModel('catalog/product')->getCollection()
			   ->addStoreFilter()
			   ->addAttributeToSelect('price')
			   ->addAttributeToSort('price', 'DESC')->getFirstItem()->getMinimalPrice()*1;
 

2 当前产品最大最小价格:

$categoryModel = Mage::getModel('catalog/category')->load($id); // Replace with Id of Cat

$productColl = Mage::getModel('catalog/product')->getCollection()
->addCategoryFilter($categoryModel)
->addAttributeToSort('price', 'asc')
->setPageSize(1)
->load();

$lowestProductPrice = $productColl->getFirstItem()->getPrice();

$productColh = Mage::getModel('catalog/product')->getCollection()
->addCategoryFilter($categoryModel)
->addAttributeToSort('price', 'desc')
->setPageSize(1)
->load();

$highestProductPrice = $productColh->getFirstItem()->getPrice();
 

转自:Magento: 单产品(product)或者当前类别(category)最大和最小价格 Min/Max Product Price in a Category

 

 

 

 

 

 

 

 

你可能感兴趣的:(Magento: 单产品(product)或者当前类别(category)最大和最小价格 Min/Max Product Price in a Category)