2 added 420 characters in body
source | link

Try bellow code

<?php

namespace Mainf\Stickers\Block;

class Discount extends \Magento\Framework\View\Element\Template
{
    protected $_product = null;

    protected $_registry;
    protected $_productFactory;

    /**
     * @param \Magento\Framework\View\Element\Template\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context\Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Registry\Magento\Catalog\Model\ProductFactory $registry$productFactory,
        array $data = []
    )
  {
   {     $this->_registry = $registry;
        $this->_registry>_productFactory = $registry;$productFactory;
        parent::__construct($context, $data);
    }

    public function _prepareLayoutgetCurrentCategory()
    {       
        return parent::_prepareLayout$this->_registry->registry('current_category');
    }

    public function getCurrentCategorygetCurrentProduct()
    {       
        return $this->_registry->registry('current_category''current_product');
    }

    public function getCurrentProductisDiscounted()
    {       
        return$idProd = $this->_registry>getCurrentProduct()->registry>getData('current_product''entity_id'); 

    }   
  return true;
    }
?>}

Display current product data in your template (custom.phtml) file

if ($currentProduct = $block->getCurrentProduct()) {
    echo $currentProduct->getName() . '<br />';
    echo $currentProduct->getSku() . '<br />';
    echo $currentProduct->getId() . '<br />';       
}

Try bellow code

<?php

namespace Mainf\Stickers\Block;

class Discount extends \Magento\Framework\View\Element\Template
{
    protected $_registry;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,       
        \Magento\Framework\Registry $registry,
        array $data = []
    )
     {       
        $this->_registry = $registry;
        parent::__construct($context, $data);
    }

    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }

    public function getCurrentCategory()
    {       
        return $this->_registry->registry('current_category');
    }

    public function getCurrentProduct()
    {       
        return $this->_registry->registry('current_product');
    }   
 
}
?>

Display current product data in your template (custom.phtml) file

if ($currentProduct = $block->getCurrentProduct()) {
    echo $currentProduct->getName() . '<br />';
    echo $currentProduct->getSku() . '<br />';
    echo $currentProduct->getId() . '<br />';       
}

Try bellow code

<?php

namespace Mainf\Stickers\Block;

class Discount extends \Magento\Framework\View\Element\Template
{
    protected $_product = null;

    protected $_registry;
    protected $_productFactory;

    /**
     * @param \Magento\Framework\View\Element\Template\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Catalog\Model\ProductFactory $productFactory,
        array $data = []
    ) {
        $this->_registry = $registry;
        $this->_productFactory = $productFactory;
        parent::__construct($context, $data);
    }

    public function getCurrentCategory()
    {       
        return $this->_registry->registry('current_category');
    }

    public function getCurrentProduct()
    {       
        return $this->_registry->registry('current_product');
    }

    public function isDiscounted()
    {
        $idProd = $this->getCurrentProduct()->getData('entity_id'); 

        return true;
    }
}

Display current product data in your template (custom.phtml) file

if ($currentProduct = $block->getCurrentProduct()) {
    echo $currentProduct->getName() . '<br />';
    echo $currentProduct->getSku() . '<br />';
    echo $currentProduct->getId() . '<br />';       
}
1
source | link

Try bellow code

<?php

namespace Mainf\Stickers\Block;

class Discount extends \Magento\Framework\View\Element\Template
{
    protected $_registry;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,       
        \Magento\Framework\Registry $registry,
        array $data = []
    )
    {       
        $this->_registry = $registry;
        parent::__construct($context, $data);
    }

    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }

    public function getCurrentCategory()
    {       
        return $this->_registry->registry('current_category');
    }

    public function getCurrentProduct()
    {       
        return $this->_registry->registry('current_product');
    }   

}
?>

Display current product data in your template (custom.phtml) file

if ($currentProduct = $block->getCurrentProduct()) {
    echo $currentProduct->getName() . '<br />';
    echo $currentProduct->getSku() . '<br />';
    echo $currentProduct->getId() . '<br />';       
}