Vendor\Module\etc\di.xml
<preference for="Magento\CatalogSearch\Controller\Result\Index" type="Vendor\Module\Controller\Result\Index" />
Vendor\Module\Controller\Result\Index.php
namespace Vendor\Module\Controller\Result;
class Index extends \Magento\Framework\App\Action\Action
{
public function __construct(
Context $context,
Session $catalogSession,
StoreManagerInterface $storeManager,
Http $request,
LayoutInterface $layout,
ScopeConfigInterface $scopeConfig,
\Magento\Catalog\Model\CategoryFactory $catalogCategoryFactory,
\Magento\Framework\Registry $registry,
\Vendor\Module\Model\Client\Connector $tglssearchClientConnector
) {
$this->catalogSession = $catalogSession;
$this->storeManager = $storeManager;
$this->request = $request;
$this->layout = $layout;
$this->scopeConfig = $scopeConfig;
$this->catalogCategoryFactory = $catalogCategoryFactory;
$this->registry = $registry;
$this->tglssearchClientConnector = $tglssearchClientConnector;
/* $this->resultPageFactory = $resultPageFactory;
$this->layerResolver = $layerResolver;
$this->_queryFactory = $queryFactory;
$this->_storeManager = $storeManager; */
parent::__construct(
$context
);
}
public function execute()
{
....
$rootCategory = $this->catalogCategoryFactory->create()
->load($rootCategoryId)
->setName($this->__('Sale')) //ERROR HERE
->setMetaTitle($this->__('Sale'))
->setMetaDescription($this->__('Sale'))
->setMetaKeywords($this->__('Sale'));
....
In the line ->setName($this->__('Sale'))
Why do i get Interceptor error…What does this mean?
Fatal error: Call to undefined method Vendor\Module\Controller\Result\Index\Interceptor::__() in C:\xampp\htdocs\magento2x_3\app\code\Vendor\Module\Controller\Result\Index.php on line 143
Best Answer
The translation function
__()
is defined inapp/functions.php
and is not a part of$this
. You should call it directly, without$this
, as follows: