2

Could someone advise what's the best way to get the current product in a custom helper? Basically if I am a product page I need to get it's sku

  • Helpers are usually used as elements/methods that are global and always available. Helpers can be called anywhere and you only need to inject them in the class. I think you should create a block class which should have the code as per shared in answer below. That shall solve the problem for you. – LAW Sep 13 '18 at 13:28
3
protected $_registry;

public function __construct(
    \Magento\Framework\App\Helper\Context $context        
    \Magento\Framework\Registry $registry
)
{        
    $this->_registry = $registry;
    parent::__construct($context);
}

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.