How to get the product by price range through object manager in phtml file. Like following

Get product where price is greater than 1 and less than 25

3 Answers 3


Try it.


//$productId = 100;
$sku = "testsku";
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$prodCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');

$collection = $prodCollection->create()
            ->addAttributeToFilter('price', array('in' => range(1, 25)));
foreach ($collection as $product){
     echo 'Name =  '.$product->getName().'<br>';
     echo 'Id  =  '.$product->getId().'<br>';
     echo 'Sku  =  '.$product->getSku().'<br>';
     echo 'Image' =  '.$product->getImage().'<br>';

  • Hero Bro Thanks. Thank you so much please tell how to get image also. Mar 1, 2018 at 10:51
  • check update code @Bunny Xudot Mar 1, 2018 at 11:19
  • now code work for you please accept and upvot my answer.@Bunny Xudot Mar 1, 2018 at 11:22
  • @Ravindrasinh Zala, Bunny Xudot haven't enough reputation point for upvote. behalf of him i'll do that... Mar 1, 2018 at 11:31

create a object of abstractProduct Block then call the getProductPrice method and pass product object as parameter. see below.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$abstractProductBlock = $block->getLayout()->createBlock('\Magento\Catalog\Block\Product\AbstractProduct');

$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $productCollection->create()
            ->addAttributeToSort('created_at', 'DESC')
    <?php foreach ($collection as $product) :?>
        <div class="item-box">
            <a href="<?php echo $product->getProductUrl(); ?>" >
                <span class="imgbx">
                    <img src="<?php echo $abstractProductBlock->getImage($product, 'latest_collection_list')->getImageUrl(); ?>" alt="<?php echo $product->getName(); ?>" />
                <h3><?php echo $product->getName(); ?></h3>
                <span class="hm-price"><?php echo $abstractProductBlock->getProductPrice($product) ?></span>
    <?php endforeach;  ?>

Try this.


$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$products = $objectManager->create("Magento\Catalog\Model\Product")->getCollection()
            ->addAttributeToFilter('price', array('in' => range(1, 25)));

foreach ($products as $product) {
    echo "<pre>";

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.