Skip to content

Commit 4cd58d8

Browse files
committed
Fix seo urls for product, category and cms page
1 parent 4087b20 commit 4cd58d8

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

model/blog/post.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ModelBlogPost extends Model
3131
public function getPost($post_id)
3232
{
3333
$post = new NewsClass((int) $post_id, (int) $this->context->language->id, $this->context->shop->id);
34+
3435
return array(
3536
'id' => $post->id,
3637
'title' => $post->title,

model/common/page.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,28 @@ public function getPage($page_id)
1616
{
1717
$page = new CMS($page_id, $this->context->language->id, $this->context->shop->id);
1818

19+
$dispatcher = Dispatcher::getInstance();
20+
$params = array();
21+
$params['id'] = $page->id;
22+
$params['rewrite'] = $page->link_rewrite;
23+
$params['meta_keywords'] = Tools::str2url($page->meta_keywords);
24+
$params['meta_title'] = Tools::str2url($page->meta_title);
25+
26+
$url = $dispatcher->createUrl(
27+
'cms_category_rule',
28+
$this->context->cookie->id_lang,
29+
$params,
30+
true,
31+
'',
32+
$this->context->cookie->id_shop
33+
);
34+
1935
return array(
2036
'id' => $page->id,
2137
'title' => $page->meta_title,
2238
'description' => html_entity_decode($page->content, ENT_QUOTES, 'UTF-8'),
2339
'sort_order' => (int) $page->position,
24-
'keyword' => $page->link_rewrite
40+
'keyword' => $url
2541
);
2642
}
2743

model/store/category.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,38 @@ public function getCategory($category_id)
3131
$thumb = $this->context->link->getCatImageLink($category->link_rewrite, $category->id_image);
3232
$thumbLazy = $this->context->link->getCatImageLink($category->link_rewrite, $category->id_image);
3333
}
34+
$dispatcher = Dispatcher::getInstance();
35+
36+
$params = array();
37+
38+
$params['id'] = $category->id;
39+
$params['rewrite'] = $category->link_rewrite;
40+
41+
if ($dispatcher->hasKeyword(
42+
'category_rule',
43+
$this->context->cookie->id_lang,
44+
'meta_keywords',
45+
$this->context->cookie->id_shop
46+
)) {
47+
$params['meta_keywords'] = Tools::str2url($category->getFieldByLang('meta_keywords'));
48+
}
49+
if ($dispatcher->hasKeyword(
50+
'category_rule',
51+
$this->context->cookie->id_lang,
52+
'meta_title',
53+
$this->context->cookie->id_shop
54+
)) {
55+
$params['meta_title'] = Tools::str2url($category->getFieldByLang('meta_title'));
56+
}
57+
58+
$url = Dispatcher::getInstance()->createUrl(
59+
'category_rule',
60+
$this->context->cookie->id_lang,
61+
$params,
62+
true,
63+
'',
64+
$this->context->cookie->id_shop
65+
);
3466

3567
return array(
3668
'id' => $category->id,
@@ -39,7 +71,7 @@ public function getCategory($category_id)
3971
'parent_id' => $category->id_parent,
4072
'image' => $thumb,
4173
'imageLazy' => $thumbLazy,
42-
'keyword' => $category->link_rewrite
74+
'keyword' => $url
4375
);
4476
}
4577

resolver/store/product.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ public function get($args)
4545

4646
$that = $this;
4747

48+
$link = $this->context->link->getProductLink(
49+
$product,
50+
null,
51+
null,
52+
null,
53+
null,
54+
null,
55+
0,
56+
true
57+
);
58+
59+
$link = str_replace($this->context->link->getPageLink(''), '', $link);
4860
return array(
4961
'id' => $product->id,
5062
'name' => $product->name,
@@ -58,7 +70,7 @@ public function get($args)
5870
'imageLazy' => $imageLazy,
5971
'stock' => $product->quantity > 0,
6072
'rating' => (float)0,
61-
'keyword' => $product->link_rewrite,
73+
'keyword' => $link,
6274
'images' => function ($root, $args) use ($that) {
6375
return $that->getImages(array(
6476
'parent' => $root,
@@ -179,6 +191,11 @@ public function getImages($data)
179191
$args = $data['args'];
180192

181193
$result = $this->model_store_product->getProductImages($product['id'], $args['limit']);
194+
$images = Product::getCover($product['id']);
195+
196+
$result = array_filter($result, function ($value) use ($images) {
197+
return $value['id_image'] != $images['id_image'];
198+
});
182199

183200
return $result;
184201
}

0 commit comments

Comments
 (0)