0

I want to display products between range of 5000 to 10000 on top in my category page, how can i do this in magento?

I tried to merge collection using

$_productCollection1 = Mage::getModel('catalog/product')
                            ->getCollection()
                             ->addStoreFilter(Mage::app()->getStore()->getId())
                               ->addCategoryFilter($category)
                              ->addAttributeToFilter('showontop', 1)
                               ->setOrder('price','asc')
                            ->load();

$_productCollection2 = array();
$_productCollection2 = Mage::getModel('catalog/product')
                            ->getCollection()
                             ->addStoreFilter(Mage::app()->getStore()->getId())
                               ->addCategoryFilter($category)
                              ->addAttributeToFilter('showontop', 0)
                               ->setOrder('price','desc')
                            ->load();
//print_r($_productCollection1->getAllIds());
print_r($_productCollection2->getAllIds()); die();
$merged_ids = array_merge($_productCollection1->getAllIds(), $_productCollection2->getAllIds());

$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addFieldToFilter('entity_id', array('in' => $merged_ids))
->addAttributeToSelect('*');

but no result

2
  • what u mean by range of 5000 to 10000?
    – Amit Bera
    Commented Jan 26, 2017 at 7:54
  • products price between these range and all products between this range have attribute showontop as yes.
    – Sunil
    Commented Jan 26, 2017 at 8:39

3 Answers 3

1

u can achieved result by single collection instead of three collection

try this

$_productCollection1 = Mage::getModel('catalog/product')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->addStoreFilter(Mage::app()->getStore()->getId())
                    ->addCategoryFilter($category)
                    ->addAttributeToFilter(
                        array('showontop', 'showontop'),
                        array(
                            array('eq'=> 1 ), 
                            array('eq'=> 0 )
                        )
                    )
                    ->addAttributeToSort('price','asc');
1
  • u can alos set limit $_productCollection1->setPage(5000,10000) Commented Feb 3, 2017 at 12:45
1

you can price limit by following code

$products = Mage::getModel('catalog/product')->getCollection()
         ->addAttributeToSelect('price')->addAttributeToSelect('sku')
         ->addFieldToFilter('entity_id', array('in' => $merged_ids));

         $products->addPriceData();

// Apply price limit
$products->getSelect()->where('price_index.final_price <= ?', 10000)
->where('price_index.final_price >= ?', 5000);
      echo '<pre>';   print_r($products->getData());
0

Below code work for me for getting products whose price between 5000 to 10000

Hope it will help you

$collection = Mage::getModel('catalog/product')->getCollection();
$collection
    ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
    ->addMinimalPrice()
    ->addFinalPrice();
$collection->addAttributeToFilter('price',array('from'=>5000,'to'=>10000));

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.