Pergunta

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.

Foi útil?

Solução

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;
    }

}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top