How do I find the max weight and min weight of a category with 3000 products.
I'm trying use:
public function getProductCollectionFilter($_productCollection)
{
$_productCollection = $this->_currentCategory->getProductCollection();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
$weights = array();
foreach ($_productCollection as $product) {
$_product = Mage::getModel('catalog/product')->load($product->getId());
$weight = $_product->getAttributeText('karma_weight');
if (strpos($weight, 'kg') !== false) {
$weight = str_replace('kg', '', $weight);
$weight = (int) $weight;
$weight = $weight * 1000;
}
$weight = str_replace('g', '', $weight);
$weight = (int) $weight;
$weights[] = $weight;
}
return $weights;
}
and:
public function getMaxRangeWeight()
{
$maxWeight = 0;
$_productCollection = $this->_currentCategory->getProductCollection();
$weights = $this->getProductCollectionFilter($_productCollection);
foreach ($weights as $weight){
if ($weight > $maxWeight) $maxWeight = $weight;
}
return $maxWeight;
}
That work. But with a category have 500 -> 3000 product the page can't load.