0

I override the \Magento\Catalog\Block\Product\View it's working but I am trying to inject class means it's not working please tell me what I did wrong and tell me how to do this without injecting the core class

    <?php
    namespace Eventbefore\Block\Product;

    use Magento\Framework\Session\SessionManagerInterface;
    use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
    use Magento\Framework\Stdlib\Cookie\PublicCookieMetadata;
    use Magento\Framework\Stdlib\CookieManagerInterface;

    class View extends \Magento\Catalog\Block\Product\View{

        protected $logger;

        protected $objectManager;

        protected $_curl;

        public function __construct(
            CookieManagerInterface $cookieManager,
            CookieMetadataFactory $cookieMetadataFactory,
            SessionManagerInterface $sessionManager, 
            \Magento\Framework\ObjectManagerInterface $objectManager,
            \Magento\Framework\HTTP\Client\Curl $curl)
        {
            $this->_curl = $curl;
            $this->objectManager = $objectManager;
            $this->_cookieManager = $cookieManager;
            $this->_cookieMetadataFactory = $cookieMetadataFactory;
            $this->_sessionManager = $sessionManager;
             //parent::__construct($context);
        }
}

Error:

Eventbefore\Block\Product\View

      Missed required argument urlEncoder in parent::__construct call. File: /opt/lampp/htdocs/rumin/app/code/Cart/Eventbefore/Block/Product/View.php

1 Answer 1

0

According to this question Magento 2: Override Magento\Catalog\Block\Product\View Block

and to the exception you have, I guess you have to add this to the construct method and pass it to the parent cuonstructor

public function __construct(
        .......
        \Magento\Framework\Url\EncoderInterface $urlEncoder, 
) {
    parent::__construct(...., $urlEncoder, ...);

}
3
  • Is that necessary to inject that class, those classes already in core files right? Feb 19, 2018 at 10:31
  • According to your exception you have to inject it... or uncomment parent cunstroctor
    – sissy
    Feb 19, 2018 at 10:35
  • I have uncommented and tried it's coming like this, Fatal error: Uncaught Error: Call to a member function registry() on null in /opt/lampp/htdocs/vendor/magento/module-catalog/Block/Product/View.php:172 Stack trace: #0 /opt/lampp/htdocs/rumin/vendor/magento/module-catalog/Block/Product/View.php(128): Magento\Catalog\Block\Product\View->getProduct() Feb 19, 2018 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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