<?php
if (file_exists('config.php')) {
require_once('config.php');
}
require_once 'system/library/db.php';
require_once 'system/library/db/mysqli.php';
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$sql = 'SELECT category_id, name FROM `' . DB_PREFIX . 'category_description`';
$res = $db->query($sql);
foreach($res->rows as $row) {
$query = 'category_id=' . $row['category_id'];
$keyword = (get_seo_keyword($row['name']) . '_' .$row['category_id']);
if (!exist_query($query, $db)) {
//$up_sql = "INSERT INTO `" . DB_PREFIX . "url_alias` (`url_alias_id`, `query`, `keyword`) VALUES (NULL, '" . $query . "', '" . $keyword . "'); ";
$up_sql = "INSERT INTO `" . DB_PREFIX . "seo_url` (`seo_url_id`, `store_id`, `language_id`, `query`, `keyword`) VALUES (NULL, 0, 1, '" . $query . "', '" . $keyword . "'); ";
$db->query($up_sql);
print_r($query);
print_r(' successfully added');
print_r('<br>');
} else {
print_r('exist_query ');
print_r($query);
print_r('<br>');
}
}
print('done');
function exist_query($query, $db) {
$sql = "SELECT query FROM `" . DB_PREFIX . "seo_url` WHERE `query` = '" . $query . "'";
if ($db->query($sql)->num_rows) {
return true;
}
return false;
}
function get_seo_keyword($str) {
$tr = array(
"А" => "a",
"Б" => "b",
"В" => "v",
"Г" => "g",
"Д" => "d",
"Е" => "e",
"Ж" => "zh",
"З" => "z",
"И" => "i",
"Й" => "y",
"К" => "k",
"Л" => "l",
"М" => "m",
"Н" => "n",
"О" => "o",
"П" => "p",
"Р" => "r",
"С" => "s",
"Т" => "t",
"У" => "u",
"Ф" => "f",
"Х" => "h",
"Ц" => "c",
"Ч" => "ch",
"Ш" => "sh",
"Щ" => "sch",
"Ъ" => "",
"Ы" => "y",
"Ь" => "",
"Э" => "e",
"Ю" => "yu",
"Я" => "ya",
"а" => "a",
"б" => "b",
"в" => "v",
"г" => "g",
"д" => "d",
"е" => "e",
"ж" => "j",
"з" => "z",
"и" => "i",
"й" => "y",
"к" => "k",
"л" => "l",
"м" => "m",
"н" => "n",
"о" => "o",
"п" => "p",
"р" => "r",
"с" => "s",
"т" => "t",
"у" => "u",
"ф" => "f",
"х" => "h",
"ц" => "c",
"ч" => "ch",
"ш" => "sh",
"щ" => "sch",
"ъ" => "",
"ы" => "y",
"ь" => "",
"э" => "e",
"ю" => "yu",
"я" => "ya",
" " => "_",
"." => "",
"/" => "_"
);
$res = strtr($str, $tr);
if (preg_match('/[^A-Za-z0-9_\-]/', $res)) {
$res = preg_replace('/[^A-Za-z0-9_\-]/', '', $res);
}
return urlencode(strtolower($res));
}
?>
Это для категорий. По аналогии можете сделать для товаров!
Язык и id магазина - подставить ну не очень сложно же!