<preference for="Magento\CatalogSearch\Controller\Result\Index" type="Vendor\Module\Controller\Result\Index" />


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; */
public function execute()

   $rootCategory = $this->catalogCategoryFactory->create()
        ->setName($this->__('Sale'))   //ERROR HERE

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
  • Did you try to empty /var/generation/? It might be an issue like this one: magento.stackexchange.com/questions/101456/…
    – Akif
    Aug 11 '16 at 10:45
  • yes cleared var/gen and ran setup upgrade
    – Sushivam
    Aug 11 '16 at 10:45
  • Any idea where s the root cause?
    – Sushivam
    Aug 11 '16 at 10:52
  • Can you add the rest of the controller and the module structure? And is this the actual error, or did you change to post it here? Vendor\Module\Controller\Result\Index\Interceptor::__()? Is it actually looking in Vendor\Module\Controller?
    – Akif
    Aug 11 '16 at 10:59
  • 1
    Can you find out which part of the line causes the error? ->setName or $this->__()?
    – Akif
    Aug 11 '16 at 11:11

The translation function __() is defined in app/functions.php and is not a part of $this. You should call it directly, without $this, as follows:

public function execute()

   $rootCategory = $this->catalogCategoryFactory->create()
      ->setName(__('Sale'))   //no more error
  • Yes @Peedee, thanks for the explanation...:)
    – Sushivam
    Aug 14 '16 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.