0

My phtml file is extended with this class:

class Select extends \Magento\Catalog\Block\Product\View\Options\AbstractOptions
{
    protected $_escaper;  
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Pricing\Helper\Data $pricingHelper,
        \Magento\Framework\Registry $registry,
        \Magento\Catalog\Helper\Data $catalogData
      ) {
        $this->registry = $registry;
        parent::__construct($context, $pricingHelper, $catalogData);
      }
    private function getCurrentProduct()
    {
        if (is_null($this->product)) {
            $this->product = $this->registry->registry('product');

            if (!$this->product->getId()) {
                throw new LocalizedException(__('Failed to initialize product'));
            }
        }

        return $this->product;
    }

When i call my function $this->getCurrentProduct() i get nothing, what i am doing wrong here. Its a product page

2
  • in what page are you using this? – Marius Jun 23 '20 at 11:14
  • @Marius its a single product page. if you need more information about XML files i can update the question – Ifaruki Jun 23 '20 at 11:22
1

This registry key will be filled only on the product detail page:

also, you may use

$this->registry->registry('current_product')

instead of

$this->registry->registry('product')

1
  • i have laready tried that without success sadly – Ifaruki Jun 23 '20 at 11:22

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.