0

Is their any way we can get the lowest price from product collection ?

I have array of products id

Array
(
    [0] => 662348
    [1] => 659160
)

I want the minimum & maximum price of products. min price product & max price product.

I have tried

$proIds=array(2,6,7);
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
    $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
    /** Apply filters here */
    $collection = $productCollection->addAttributeToSelect('*')
                ->addFieldToFilter('entity_id', array('in' => $proIds));

                echo '<pre>';print_r($collection->getData());

2 Answers 2

0

You can pass all the prices into empty array and then apply this function.

max(); min();

0

You can get min and max price from any collection :

Max Price : $maxPrice = $productCollection->getMaxPrice();

Min Price : $minPrice = $productCollection->getMinPrice();

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.