How to remove SKU from product name in search results?
-
18-02-2021 - |
سؤال
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.
المحلول
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;
}
}
لا تنتمي إلى magento.stackexchange