I need to override product view block but i got an error :

Here's my di.xml :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
   <preference for="Magento\Catalog\Block\Product\View" type="Magento\Module_Inject_Session\Block\Product\View"/>

Here's my new block :

enter image description here

And there is this error and I have no idea what to do about it :

enter image description here

anyone one know where i'm wrong? or what is the correct way to override this file?


Try with below solutions, Replace _ with folder and separate each folder path like below,

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
   <preference for="Magento\Catalog\Block\Product\View" type="Magento\Module\Inject\Session\Block\Product\View"/>

Set your block php file at below location,


inside php file,

namespace  Magento\Module\Inject\Session\Block\Product;

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

    //your custom code.....


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.