dont use preference use plugin to extend any core module that is in di.xml
<type name="Magento\Catalog\Controller\Product\View">
<plugin name="product-cont-test-module" type="Sugarcode\Test\Model\Plugin\Product" sortOrder="10"/>
</type>
and in Product.php
public function aroundExecute(\Magento\Catalog\Controller\Product\View $subject, \Closure $proceed)
{
echo 'I Am in Local Controller Before <br>';
$returnValue = $proceed(); // it get you old function return value
//$name='#'.$returnValue->getName().'#';
//$returnValue->setName($name);
echo 'I Am in Local Controller After <br>';
return $returnValue;// if its object make sure it return same object which you addition data
}
How to Override Core Block, Model and controller in Magento2How to Override Core Block, Model and controller in Magento2