Skip to main content

I overridedoverridden module-catalog/product/price/amount/default.phtml file in my theme

<?php 
    echo $this->helper('Test\ProductDetail\Helper\Data')->DisplayDiscountLabel($_product);
?>

In helper file I have following code ;

 namespace Test\ProductDetail\Helper;


 class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
public function DisplayDiscountLabel($_product)
{
   $originalPrice = $_product->getPrice();
    $finalPrice = $_product->getFinalPrice();

    $percentage = 0;
    if ($originalPrice > $finalPrice) {
        $percentage = number_format(($originalPrice - $finalPrice) * 100 / $originalPrice,0);
    }

    if ($percentage) {
        return "(".$percentage."%)";
    }

   }
}

but problem is that in phtml file I am not getting value of $_product?

I overrided module-catalog/product/price/amount/default.phtml file in my theme

<?php 
    echo $this->helper('Test\ProductDetail\Helper\Data')->DisplayDiscountLabel($_product);
?>

In helper file

 namespace Test\ProductDetail\Helper;


 class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
public function DisplayDiscountLabel($_product)
{
   $originalPrice = $_product->getPrice();
    $finalPrice = $_product->getFinalPrice();

    $percentage = 0;
    if ($originalPrice > $finalPrice) {
        $percentage = number_format(($originalPrice - $finalPrice) * 100 / $originalPrice,0);
    }

    if ($percentage) {
        return "(".$percentage."%)";
    }

   }
}

but problem is that in phtml file I am not getting value of $_product?

I overridden module-catalog/product/price/amount/default.phtml file in my theme

<?php 
    echo $this->helper('Test\ProductDetail\Helper\Data')->DisplayDiscountLabel($_product);
?>

In helper file I have following code ;

 namespace Test\ProductDetail\Helper;


 class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
public function DisplayDiscountLabel($_product)
{
   $originalPrice = $_product->getPrice();
    $finalPrice = $_product->getFinalPrice();

    $percentage = 0;
    if ($originalPrice > $finalPrice) {
        $percentage = number_format(($originalPrice - $finalPrice) * 100 / $originalPrice,0);
    }

    if ($percentage) {
        return "(".$percentage."%)";
    }

   }
}

but problem is that in phtml file I am not getting value of $_product?

Source Link
jassi
  • 1.3k
  • 4
  • 30
  • 50

How to display discount on Special price in product detail page?

I overrided module-catalog/product/price/amount/default.phtml file in my theme

<?php 
    echo $this->helper('Test\ProductDetail\Helper\Data')->DisplayDiscountLabel($_product);
?>

In helper file

 namespace Test\ProductDetail\Helper;


 class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
public function DisplayDiscountLabel($_product)
{
   $originalPrice = $_product->getPrice();
    $finalPrice = $_product->getFinalPrice();

    $percentage = 0;
    if ($originalPrice > $finalPrice) {
        $percentage = number_format(($originalPrice - $finalPrice) * 100 / $originalPrice,0);
    }

    if ($percentage) {
        return "(".$percentage."%)";
    }

   }
}

but problem is that in phtml file I am not getting value of $_product?