How to get the formatted price with currency using factory method ?

Loading...
How to get the formatted price with currency using factory method ?

Block file : -

namespace Test\Module\Block;

class Product extends \Magento\Framework\View\Element\Template

{

protected $priceHelper;

public function __construct(

\Magento\Framework\View\Element\Template\Context $context,

\Magento\Framework\Pricing\Helper\Data $priceHelper

) {

$this->priceHelper = $priceHelper;

parent::__construct($context);

}

public function getFormattedPrice($price)

{

return $this->priceHelper->currency($price, true, false);

}

}

PHTML file :

$price = $this->getFormattedPrice(200);

echo $price;



Copyright © 2024 Tridhya Tech Limited, Inc. All rights reserved.