18

How can I get Original price and Final price of given below types product?

  1. Simple product
  2. Configurable product
  3. Bundle product
  4. Group product

For simple product I can get price easily using below code.

$finalPrice = $product->getFinalPrice();
$originalPrice = $product->getPrice();

But I am not able to get Original price and Final price for Configurable product, Bundle product, Group product

Is there any easy way to get both prices of all other types of product.


EDIT :

I get price Original price and Final price of configurable product using below code. and take reference from get-price-range-configurable-product-magento-2

$basePrice = $product->getPriceInfo()->getPrice('regular_price');

$regularPrice = $basePrice->getMinRegularAmount()->getValue();
$specialPrice = $product->getFinalPrice();

Any help would be appreciated! Thanks.

6
  • you can get original price and final price here <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productCollectionFactory = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory'); $collection = $productCollectionFactory->create(); $collection->addAttributeToSelect('*'); $collection->addWebsiteFilter(); $collection->addMinimalPrice(); $collection->addFinalPrice(); $collection->addStoreFilter(); $collection->setVisibility($objectManager->get('\Magento\Catalog\Model\Product\Visibility')->getVisibleInSiteIds()); ?> <?php foreach ($collecti Jan 12, 2019 at 11:15
  • Have you checked this code? is it working? It is not working for me. Jan 12, 2019 at 11:29
  • yes this code working for me Jan 12, 2019 at 11:30
  • $_product->getSpecialPrice(); is not working for me Jan 12, 2019 at 11:34
  • if($orgprice > $specialprice){ echo $_product->getSpecialPrice(); } Jan 12, 2019 at 11:46

1 Answer 1

34

You can get Regular price and Final price of all types of product using below way.

  1. Simple Product
$regularPrice = $product->getPriceInfo()->getPrice('regular_price')->getValue();
$specialPrice = $product->getPriceInfo()->getPrice('special_price')->getValue();
  1. Configurable product
if ($product->getTypeId() == 'configurable') {
      $basePrice = $product->getPriceInfo()->getPrice('regular_price');

      $regularPrice = $basePrice->getMinRegularAmount()->getValue();
      $specialPrice = $product->getFinalPrice();
}
  1. Bundle product
if ($product->getTypeId() == 'bundle') {
      $regularPrice = $product->getPriceInfo()->getPrice('regular_price')->getMinimalPrice()->getValue();
      $specialPrice = $product->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue();            
}
  1. Group product
if ($product->getTypeId() == 'grouped') {
      $usedProds = $product->getTypeInstance(true)->getAssociatedProducts($product);            
      foreach ($usedProds as $child) {
          if ($child->getId() != $product->getId()) {
                $regularPrice += $child->getPrice();
                $specialPrice += $child->getFinalPrice();
          }
      }
}

Note : In above example $product is current product.

1
  • So you cannot get the minimal price based on special price of a bundled product? I get that will be the same as a "final_price" however in some cases catalog price rules may be the cause of the discount to the final price and not the "special price" set at product level and would like a way to differentiate?
    – harri
    Oct 12, 2022 at 8:24

Your Answer

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

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