Skip to content

Commit

Permalink
Добавлена возможность задавать префиксы ЧПУ для определённых route
Browse files Browse the repository at this point in the history
  • Loading branch information
mpn2005 committed Jan 14, 2024
1 parent 544dbb0 commit 0bbda10
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions upload/catalog/controller/startup/seo_url.php
Expand Up @@ -6,7 +6,22 @@ class ControllerStartupSeoUrl extends Controller {
private $enable_postfix = false;
private $enable_slash = false;
private $mode = 0;


/* Префикс ЧПУ для определённых роутов.
Пример - Приставка /brand/ для всех производителей :
private $prefix_by_route = [
'product/manufacturer/info' => 'brand',
];
Пример - Приставка /category/ для категорий и /product/ для товаров :
private $prefix_by_route = [
'product/category' => 'category',
'product/product' => 'product',
];
*/
private $prefix_by_route = [];

public function __construct($registry) {
parent::__construct($registry);

Expand Down Expand Up @@ -36,6 +51,10 @@ public function index() {
}
}
$parts = $parts_filtered;

if ( count($parts) > 1 && in_array($parts[0], $this->prefix_by_route) ) {
array_shift($parts);
}

// Убираем окончание после точки, если оно есть
if ($this->postfix && count($parts) > 0) {
Expand Down Expand Up @@ -167,13 +186,17 @@ public function rewrite($link) {

if (isset($data['route'])) {
$route = $data['route'];

$keyword = $this->getKeyword($data['route']);

if ($keyword !== false) {
$url = '/' . $keyword;
unset($data['route']);
}

if ( !empty($this->prefix_by_route[$route]) ) {
$url = '/' . $this->prefix_by_route[$route] . $url;
}
}

if (!empty($route) && $route == 'product/product' && !empty($data['product_id'])) {
Expand Down

0 comments on commit 0bbda10

Please sign in to comment.