I have override url-rewrite router in my custom module,and add my custom rewrite code in override router file.
after filter url created like below :
But I want to create url like :
http://domainname.com/services/aruba
I am using below code for rewrite url in router file .it's not working. it's goes to 404 result page.
//custom code
if ($request->getModuleName() === 'catalog' || $request->getModuleName() === 'cms') {
return;
}
$identifier = trim($request->getPathInfo(), '/');
$urlKey_explode = explode('/', $identifier);
if($urlKey_explode[0]=='services')
{
$url_string = $urlKey_explode[1];
//get manufacture
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
//Select product attribute from table
$sql = "SELECT
eav_attribute_option_value.option_id , eav_attribute_option_value.value
FROM
eav_attribute_option_value
join `eav_attribute_option` on `eav_attribute_option`.option_id = eav_attribute_option_value.option_id
WHERE
eav_attribute_option.attribute_id = 83
group by
eav_attribute_option_value.option_id";
$result_has_options_attribute_option = $connection->fetchAll($sql);
foreach ($result_has_options_attribute_option as $key => $value)
{
$productattriburtname = $value['value'];
if(strpos($url_string, $productattriburtname) !== false){
$manufacturerlabel = $value['value'];
$url_string = str_replace($productattriburtname, "-", $url_string);
break;
}
}
$request->setModuleName('catalog')->setControllerName('category')->setActionName('view');
$request->setParam('manufacturer', $manufacturerlabel);
$request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
return $this->actionFactory->create(
'Magento\Framework\App\Action\Forward',
['request' => $request]
);
}
//end custom code
Please advise me.
Best Answer
I have to Create a Custom Module for product attribute filter URL rewrite.
registration.php
module.xml
create etc/di.xml file
Override
Controller/CustomRouter.php