foxseo2
foxseo2 copied to clipboard
Bug in observer - DefaultProductMeta.php
"/app/code/Fox/Seo/Observer/DefaultProductMeta.php(38): Fox\Seo\Helper\Data->checkMetaData(NULL, 'category')"
i got an exception on a product page, file Observer/DfaultProductMeta.php this is original code: `/** * Set default product meta data if set * * @param \Magento\Framework\Event\Observer $observer * */ public function execute(\Magento\Framework\Event\Observer $observer) { $category = $observer->getEvent()->getCategory();
$this->_foxSeoHelper->checkMetaData($category, 'category');
if ($robots = $category->getData('foxseo_metarobots'))
{
$this->_config->setRobots($robots);
}
}`
here is wrong method getCategory(), it should be getProduct(), "catalog_controller_product_init_after" event is also dispatches the data for it Magento_Catalog\Helper\Product.php:
try { $this->_eventManager->dispatch( 'catalog_controller_product_init_after', ['product' => $product, 'controller_action' => $controller] ); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->_logger->critical($e); return false; }
Hello eLoner, thank you for the comment. Can you please point more specific what to add and what to replace and where? My file 'Observer/DefaultProductMeta.php' is like below now, with the changes you suggest:
- [ ] <?php
- [ ]
- [ ] namespace Fox\Seo\Observer;
- [ ]
- [ ] use Magento\Framework\Event\ObserverInterface;
- [ ]
- [ ] class DefaultProductMeta implements ObserverInterface
- [ ] {
- [ ] /**
- [ ] * @var \Fox\Seo\Helper\Data
- [ ] */
- [ ] protected $_foxSeoHelper;
- [ ]
- [ ] /**
- [ ] * @var \Magento\Framework\View\Page\Config
- [ ] */
- [ ] protected $_config;
- [ ]
- [ ] public function __construct(
- [ ] \Fox\Seo\Helper\Data $foxSeoHelper,
- [ ] \Magento\Framework\View\Page\Config $config
- [ ] )
- [ ] {
- [ ] $this->_foxSeoHelper = $foxSeoHelper;
- [ ] $this->_config = $config;
- [ ] }
- [ ]
- [ ] /**
- [ ] * Set default product meta data if set
- [ ] *
- [ ] * @param \Magento\Framework\Event\Observer $observer
- [ ] *
- [ ] */
- [ ] public function execute(\Magento\Framework\Event\Observer $observer)
- [ ] {
- [ ] $category = $observer->getEvent()->getProduct(), "catalog_controller_product_init_after";
- [ ]
- [ ] $this->_foxSeoHelper->checkMetaData($category, 'category');
- [ ]
- [ ] if ($robots = $category->getData('foxseo_metarobots'))
- [ ] {
- [ ] $this->_config->setRobots($robots);
- [ ] }
- [ ] }
- [ ] }
I hope you can help me, thank you so much.