I have made a module to override Magento\Catalog\Block\Product\View. I want to add some standard things to the MetaTitle and MetaDescription on the product page. Specifically for empty descriptions.
Alters
I alter the title string and save with
$this->pageConfig->setTitle($myString)
.
The same goes for the description
$this->pageConfig->setDescription($myOtherString)
Problem
The MetaTitle and MetaDescription on the product page stay the same.
Possible causes and solutions
I have investigated and ruled out the following:
- Cache
- Third party modules
- Module related problems (magento setup:upgrade,...)
Debug
When I echo the string I want to set I get the following error:
a:4:{i:0;s:282:"Warning: Cannot modify header information - headers already sent by (output started at /app/code/[MyVendor]/[MyModule]/Block/Product/View.php:61) in /www/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php on line 125";i:1;s:1702:"#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(2, 'Cannot modify h...', '/data/sites/web...', 125, Array)
#1 /www/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php(125): setcookie('mage-messages', '[]', 1533729078, '/', '', false, false)
#2 /www/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php(98): Magento\Framework\Stdlib\Cookie\PhpCookieManager->setCookie('mage-messages', '[]', Array)
#3 /www/vendor/magento/module-theme/Controller/Result/MessagePlugin.php(85): Magento\Framework\Stdlib\Cookie\PhpCookieManager->setPublicCookie('mage-messages', '[]', Object(Magento\Framework\Stdlib\Cookie\PublicCookieMetadata))
#4 /www/vendor/magento/framework/Interception/Interceptor.php(152): Magento\Theme\Controller\Result\MessagePlugin->afterRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Magento\Framework\View\Result\Page\Interceptor))
#5 /www/var/generation/Magento/Framework/View/Result/Page/Interceptor.php(26): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#6 /www/vendor/magento/framework/App/Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#7 /www/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#8 /www/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
But I think this is more an issue of the echo than error due to code error.
I mainly followed this logic. Is there another logic I should follow or does anyone have an idea of why the metainfo does not change?
Thanks for your time!