5

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.

  • 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 – Rakesh Donga Jan 12 at 11:15
  • Have you checked this code? is it working? It is not working for me. – Chirag Patel Jan 12 at 11:29
  • yes this code working for me – Rakesh Donga Jan 12 at 11:30
  • $_product->getSpecialPrice(); is not working for me – Chirag Patel Jan 12 at 11:34
  • if($orgprice > $specialprice){ echo $_product->getSpecialPrice(); } – Rakesh Donga Jan 12 at 11:46
0

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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