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
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(); }
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 */ } }
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.
Which files can I put these scripts on?