Magento 2 How to override framework feed file?
-
23-03-2021 - |
Question
I am trying to override Magento Framework Feed.php
file,
After googling alot I found how to override framework file but that's not worked for me.
Please give me the right eay to override framework feed file.
Vendor/Namespace/etc/di.xml
<?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\Framework\App\Feed" type="Serole\Corefiles\App\Feed" />
</config>
Vendor/Namespace/App/Feed.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Vendor\Namespace\App;
use Zend\Feed\Writer\FeedFactory;
/**
* Default XML feed class
*/
class Feed extends \Magento\Framework\App\Feed
{
/**
* @var array
*/
private $feeds;
/**
* Feed constructor.
* @param array $data
*/
public function __construct(array $data)
{
$this->feeds = $data;
}
/**
* {@inheritdoc}
*/
public function getFormattedContent() : string
{
echo '<pre>'; print_r($this->feeds); die();
return FeedFactory::factory($this->feeds)->export(FeedFactoryInterface::FORMAT_RSS);
}
}
Please guide me.
Solution
The process which I follwed in my question is correct, it started working with this solution,
I was trying to override it in an existing module where I did other functionalities, but when I create a new module for overriding, it worked there. I don't know the difference between both of those modules but it solved my problem.
This answer is strange but it worked for me.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange