Magento 2: Override Magento\Catalog\Block\Product\View Block

To resume

  • comment __construct method (temporary solution)
  • remove Interceptor generated (new one will be generated - need to be removed after each modification of __construct method)
  • in your layout use template="TT_Helloworld::myproduct.phtml"

you need to enter \TT\Helloworld\Helper\Data $helper before array $data = [] in the __contruct

public function __construct(
    \Magento\Catalog\Block\Product\Context $context,
    \Magento\Framework\Url\EncoderInterface $urlEncoder,
    \Magento\Framework\Json\EncoderInterface $jsonEncoder,
    \Magento\Framework\Stdlib\StringUtils $string,
    \Magento\Catalog\Helper\Product $productHelper,
    \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig,
    \Magento\Framework\Locale\FormatInterface $localeFormat,
    \Magento\Customer\Model\Session $customerSession,
    ProductRepositoryInterface $productRepository,
    \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
    \TT\Helloworld\Helper\Data $helper ,
    array $data = []
) {
    parent::__construct($context, $urlEncoder, $jsonEncoder, $string, $productHelper, $productTypeConfig, $localeFormat, $customerSession, $productRepository, $priceCurrency, $data,$helper);

Tags:

Magento2