Post by letxob » Wed Aug 09, 2017 10:07 pm

Using version 3.
Working on this, not sure if it is the right approach.
One seo query per store and language, stored in $this and read out in seo_url class.

in catalog/controller/startup/seo_uls.php I use for rewrite:

public function rewrite($link) {
$url_info = parse_url(str_replace('&', '&', $link));

$url = '';

$data = array();

parse_str($url_info['query'], $data);

if (USE_SEO_CACHE) {
$pairs = $this->seo_pairs;
}

foreach ($data as $key => $value) {
if (isset($data['route'])) {

if (
($data['route'] == 'product/product' && $key == 'product_id') ||
(($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id') || ($data['route'] == 'extension/extension/blog/article' && $key == 'article_id')) {

if (USE_SEO_CACHE) {
$keyword = $pairs[$this->db->escape($key . '=' . (int)$value)];
if ($keyword != '') {
$url .= '/' . $keyword;
unset($data[$key]);
}

} else {

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");


if ($query->num_rows && $query->row['keyword']) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
}


} elseif ($key == 'path') {
$categories = explode('_', $value);

foreach ($categories as $category) {

if (USE_SEO_CACHE) {
$keyword = $pairs['category_id=' . (int)$category];
if ($keyword != '') {
$url .= '/' . $keyword;
} else {
$url = '';
break;
}
unset($data[$key]);
} else {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");

if ($query->num_rows && $query->row['keyword']) {
$url .= '/' . $query->row['keyword'];
} else {
$url = '';
break;
}
}
}

unset($data[$key]);
}elseif ($key == 'route') {

if (USE_SEO_CACHE) {
$keyword = $pairs[$this->db->escape($value)];
if ($keyword != '') {
//error_log($keyword);
$url .= '/' . $keyword;
unset($data[$key]);
}
} else {

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");

if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];

unset($data[$key]);
}
}
}
}
}

if ($url) {
unset($data['route']);

$query = '';

if ($data) {
foreach ($data as $key => $value) {
$query .= '&' . rawurlencode((string)$key) . '=' . rawurlencode((is_array($value) ? http_build_query($value) : (string)$value));
}

if ($query) {
$query = '?' . str_replace('&', '&', trim($query, '&'));
}
}

return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;
} else {
return $link;
}
}

in catalog/controller/startup/startup.php I add at the end:

// SEO CACHE
if ($this->config->get('config_seo_url')) {
if (USE_SEO_CACHE) {
$query = $this->db->query("SELECT query, keyword FROM " . DB_PREFIX . "seo_url WHERE store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
$pairs = array();
foreach ($query->rows as $row) {
$pairs[$row['query']] = $row['keyword'];
}
$this->registry->set('seo_pairs', $pairs);
}
}


note: USE_SEO_CACHE is a constant definede in my config.php.

This basically stores the query-keyword pair in an array in the registry for the requested store and lanaguage.
Which means not a query per url anymore but one big one.
Perhaps people with many categories and/or products may benefit from this.

Regards.

Newbie

Posts

Joined
Sun Jul 02, 2017 4:36 am
Who is online

Users browsing this forum: No registered users and 15 guests