1

How can I remove SKU from product name in search results? In category view, product name is without SKU but when I search for some product, the results is including SKU in product name.

  • Can you please explain what is different happen between category and search page? – Amit Bera Feb 17 at 13:59
  • The difference is that in the category page all the products are shown with a image and name, but in the search results the products are shown with a image and name that also includes SKU. I want remove that SKU from name – Bobo Feb 17 at 20:44
0

I found the solution

<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace theme\mytheme\Model\Plugin;

class Product
{
     public function afterGetName(\Magento\Catalog\Model\Product $subject, $result)
    {
      $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
      $requestInterface = $objectManager->get('Magento\Framework\App\RequestInterface');

      $routeName      = $requestInterface->getRouteName();

      if($routeName=='catalogsearch')
      {
          return str_replace ( $subject->getSku() , "",$result ) ;
      }
      return $result;
    }

}

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.