cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Final price of the product in custom script ?

How to get Final price of the product in custom script ?

Hello Magedevs,

 

How can I get final price of any product which is displaying in product page I mean it should contain following things ?

 

1. Special Price

2. Catalog Rule 

3. Currency conversion

 

 

Waiting.......

 

 

Thank you

Hiren Patel

5 REPLIES 5

Re: How to get Final price of the product in custom script ?

Hello @Hiren_K_Patel 

 

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();

 

 

2. Configurable product

if ($product->getTypeId() == 'configurable') {
$basePrice = $product->getPriceInfo()->getPrice('regular_price');

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

 

Problem solved? Click Accept as Solution!

Re: How to get Final price of the product in custom script ?

Hi @Bhanu Periwal 

 

This code not giving me code which contain  catalog rule.

 

Re: How to get Final price of the product in custom script ?

Hello @Hiren_K_Patel 

For getting all rules applied in your cart you can use the below code:

Class <your classname>
{
protected $_item;

public function __construct(
    ...
    \Magento\Quote\Model\Quote\Item $item
    ...
) {
    ...
    $this->_item = $item;
    ...
}

public function GetAppliedRulesDetails() {
         $appliedIds = $this->_item->getAppliedRuleIds();
         /* here you need to load the results ids and get required details */
         }

}




Problem solved? Click Accept as Solution!

Re: How to get Final price of the product in custom script ?

Thank you @Bhanu Periwal 

 

but, this is for cart rule and it retrieve data of cart item.

 

I need same price which display in product page.

Re: How to get Final price of the product in custom script ?

Which files can I put these scripts on?