Today we learn about how to get min price and max price from product collection. First, you have to get a collection of the product. Then their two predefined functions for getting min price getMinPrice and get max price getMaxPrice
Now we implement the code for getting min price and max price.
protected $_productCollectionFactory;
public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productFactory
) {
$this->_productCollectionFactory = $productFactory;
}
public function getProductCollection()
{
$productCollection = $this->_productCollectionFactory->create();
$maxPrice = $productCollection>getMaxPrice();
$minPrice = $productCollection>getMinPrice();
}
}
You can see the example of Min Price and Max Price in Layer collection.Follow Magento\Catalog\Model\Layer\Filter\AbstractFilter.php
$this->getLayer()->getProductCollection()->getMaxPrice();
$this->getLayer()->getProductCollection()->getMinPrice();
Revisions
- February 20, 2020 @ 15:13:53 [Current Revision] by Sharing Solution
- February 20, 2020 @ 15:13:51 by Sharing Solution
- February 20, 2020 @ 15:13:20 by Sharing Solution
No comments yet.