0

I have a situation where i have a slider and need to be able to filter the loaded products by min and max price. But the only products in use are group products that don't have direct prices.

Any suggestions on filtering Group Products by price.

Using the minPrice and maxPrice price generation functions.

2 Answers 2

0

My solutions was to run a loop over the category and do a price comparison

  public function priceIds($min, $max, $catid)
    {
        $products = Mage::getModel('catalog/category')->load($catid)
            ->getProductCollection();

        $ids = array();

        foreach ($products as $product) {
            if($product->getTypeId() == 'simple') {

                $price = $product->getPrice();
                echo $price;
                if($price >= $min  && $price <= $max)
                {
                    $ids[] = $price->getId();
                }
            }elseif($product->getTypeId() == 'grouped')
            {
                $associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);

                foreach($associatedProducts as $aproduct)
                {
                    //echo $aproduct->getPrice();
                    //echo $aproduct->getId();
                    if($aproduct->getPrice() >= $min  &&  $aproduct->getPrice() <= $max )
                    {

                        $ids[] = $product->getId();
                        break;
                    }
                }
            }
            //;



        }
        //var_dump($ids);
        return $ids;

    }

And in the filter check if the product entity_id is in the reutrned id array.

0

you can use bellow code to filter collection.

->addFieldToFilter('attr_price', 
     array(array('from'=>'0','to'=>'5000'), 
     array('from'=>'15000','to'=>'20000'))
 )

I hope this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.