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, 2019 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– BoboFeb 17, 2019 at 20:44
1 Answer
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;
}
}