Skip to content

Commit

Permalink
feat: add seo urls
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrdrvn committed Aug 13, 2020
1 parent 0ad1bde commit 484a183
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 264 deletions.
381 changes: 199 additions & 182 deletions catalog/controller/extension/d_vuefront/blog/post.php

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion catalog/controller/extension/d_vuefront/common/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ public function get() {
)
);
}
}

public function searchUrl($args) {
$this->load->model('extension/d_vuefront/seo');

$result = $this->model_extension_d_vuefront_seo->searchKeyword($args['url']);


return $result;
}
}
171 changes: 94 additions & 77 deletions catalog/controller/extension/d_vuefront/common/page.php
Original file line number Diff line number Diff line change
@@ -1,77 +1,94 @@
<?php

class ControllerExtensionDVuefrontCommonPage extends Controller
{
private $codename = "d_vuefront";

public function get($args)
{
$this->load->model('extension/'.$this->codename.'/page');
$information_info = $this->model_extension_d_vuefront_page->getPage($args['id']);
$category_keyword = $this->model_extension_d_vuefront_page->getPageKeyword($args['id']);

if (!empty($category_keyword['keyword'])) {
$keyword = $category_keyword['keyword'];
} else {
$keyword = '';
}

return array(
'id' => $information_info['information_id'],
'title' => $information_info['title'],
'name' => $information_info['title'],
'description' => html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8'),
'sort_order' => (int)$information_info['sort_order'],
'meta' => array(
'title' => html_entity_decode($information_info['meta_title'], ENT_QUOTES, 'UTF-8'),
'description' => html_entity_decode($information_info['meta_description'], ENT_QUOTES, 'UTF-8'),
'keyword' => html_entity_decode($information_info['meta_keyword'], ENT_QUOTES, 'UTF-8')
),
'keyword' => $keyword
);
}

public function getList($args)
{
$this->load->model('extension/'.$this->codename.'/page');

if (in_array($args['sort'], array('sort_order', 'title'))) {
$args['sort'] = 'i.' . $args['sort'];
} elseif (in_array($args['sort'], array('name'))) {
$args['sort'] = 'id.' . $args['sort'];
}

$posts = array();

$filter_data = array(
'sort' => $args['sort'],
'order' => $args['order'],
'start' => ($args['page'] - 1) * $args['size'],
'limit' => $args['size']
);

if (!empty($args['search'])) {
$filter_data['filter_title'] = $args['search'];
$filter_data['filter_description'] = $args['search'];
}

$page_total = $this->model_extension_d_vuefront_page->getTotalPages($filter_data);

$results = $this->model_extension_d_vuefront_page->getPages($filter_data);

foreach ($results as $result) {
$posts[] = $this->get(array('id' => $result['information_id']));
}

return array(
'content' => $posts,
'first' => $args['page'] === 1,
'last' => $args['page'] === ceil($page_total / $args['size']),
'number' => (int)$args['page'],
'numberOfElements' => count($posts),
'size' => (int)$args['size'],
'totalPages' => (int)ceil($page_total / $args['size']),
'totalElements' => (int)$page_total,
);
}
}
<?php

class ControllerExtensionDVuefrontCommonPage extends Controller
{
private $codename = "d_vuefront";

public function get($args)
{
$this->load->model('extension/'.$this->codename.'/page');
$information_info = $this->model_extension_d_vuefront_page->getPage($args['id']);
$category_keyword = $this->model_extension_d_vuefront_page->getPageKeyword($args['id']);

if (!empty($category_keyword['keyword'])) {
$keyword = $category_keyword['keyword'];
} else {
$keyword = '';
}

return array(
'id' => $information_info['information_id'],
'title' => $information_info['title'],
'name' => $information_info['title'],
'description' => html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8'),
'sort_order' => (int)$information_info['sort_order'],
'meta' => array(
'title' => html_entity_decode($information_info['meta_title'], ENT_QUOTES, 'UTF-8'),
'description' => html_entity_decode($information_info['meta_description'], ENT_QUOTES, 'UTF-8'),
'keyword' => html_entity_decode($information_info['meta_keyword'], ENT_QUOTES, 'UTF-8')
),
'keyword' => $keyword,
'url' => $this->vfload->resolver('common/page/url')
);
}

public function getList($args)
{
$this->load->model('extension/'.$this->codename.'/page');

if (in_array($args['sort'], array('sort_order', 'title'))) {
$args['sort'] = 'i.' . $args['sort'];
} elseif (in_array($args['sort'], array('name'))) {
$args['sort'] = 'id.' . $args['sort'];
}

$posts = array();

$filter_data = array(
'sort' => $args['sort'],
'order' => $args['order'],
'start' => ($args['page'] - 1) * $args['size'],
'limit' => $args['size']
);

if (!empty($args['search'])) {
$filter_data['filter_title'] = $args['search'];
$filter_data['filter_description'] = $args['search'];
}

$page_total = $this->model_extension_d_vuefront_page->getTotalPages($filter_data);

$results = $this->model_extension_d_vuefront_page->getPages($filter_data);

foreach ($results as $result) {
$posts[] = $this->get(array('id' => $result['information_id']));
}

return array(
'content' => $posts,
'first' => $args['page'] === 1,
'last' => $args['page'] === ceil($page_total / $args['size']),
'number' => (int)$args['page'],
'numberOfElements' => count($posts),
'size' => (int)$args['size'],
'totalPages' => (int)ceil($page_total / $args['size']),
'totalElements' => (int)$page_total,
);
}

public function url($data)
{
$page_info = $data['parent'];
$result = $data['args']['url'];

$result = str_replace("_id", $page_info['id'], $result);
$result = str_replace("_name", $page_info['name'], $result);


if ($page_info['keyword']) {
$result = '/'.$page_info['keyword'];
}

return $result;
}
}
8 changes: 6 additions & 2 deletions catalog/controller/extension/d_vuefront/store/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public function get($args)
$this->load->model('extension/'.$this->codename.'/category');
$this->load->model('tool/image');
$category_info = $this->model_catalog_category->getCategory($args['id']);
if (empty($category_info)) {
return array();
}

$category_keyword = $this->model_extension_d_vuefront_category->getCategoryKeyword($args['id']);

if (!empty($category_keyword['keyword'])) {
Expand Down Expand Up @@ -114,13 +118,13 @@ public function url($data)

$result = str_replace("_id", $category_info['id'], $result);
$result = str_replace("_name", $category_info['name'], $result);


if ($category_info['keyword']) {
$result = '/'.$category_info['keyword'];
}


return $result;
}
}
19 changes: 18 additions & 1 deletion catalog/controller/extension/d_vuefront/store/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function get($args)
$popup_height = $this->config->get('config_image_popup_height');
$description_length = $this->config->get('config_product_description_length');
}

if ($product_info['image']) {
$image = $this->model_tool_image->resize($product_info['image'], $width, $height);
$imageLazy = $this->model_tool_image->resize($product_info['image'], 10, ceil(10 * $height / $width));
Expand Down Expand Up @@ -160,6 +160,7 @@ public function get($args)
'attributes' => $this->vfload->resolver('store/product/attribute'),
'reviews' => $this->vfload->resolver('store/review/get'),
'options' => $this->vfload->resolver('store/product/option'),
'url' => $this->vfload->resolver('store/product/url'),
'keyword' => $keyword,
'meta' => array(
'title' => html_entity_decode($product_info['meta_title'], ENT_QUOTES, 'UTF-8'),
Expand Down Expand Up @@ -282,4 +283,20 @@ public function images($data)

return $images;
}

public function url($data)
{
$product_info = $data['parent'];
$result = $data['args']['url'];

$result = str_replace("_id", $product_info['id'], $result);
$result = str_replace("_name", $product_info['name'], $result);


if ($product_info['keyword']) {
$result = '/'.$product_info['keyword'];
}

return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

"home": "common/home/get",

"searchUrl": "common/home/searchUrl",

"uploadFile": "common/file/upload",

"countriesList": "common/country/getList",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ type Page {
title: String @deprecated(reason: "Changed to name!")
name: String
description: String
url(url: String): String
keyword: String
meta: Meta
sort_order: Int
Expand Down Expand Up @@ -163,6 +164,7 @@ type Post {
next: Post
prev: Post
meta: Meta
url(url: String): String
}

type PostResult {
Expand Down Expand Up @@ -216,6 +218,7 @@ type Product {
images(limit: Int = 3): [productImage]
keyword: String
meta: Meta
url(url: String): String
}

type productAttribute {
Expand Down Expand Up @@ -412,6 +415,12 @@ type Total {
text: String
}

type SearchUrlResult {
url: String
type: String
id: String
}

type RootMutationType {
uploadFile(file: Upload): FileResult
accountLogin(email: String, password: String): LoginResult
Expand Down Expand Up @@ -471,5 +480,6 @@ type RootQueryType {
accountAddressList: [AccountAddress]
accountAddress(id: String): AccountAddress
checkoutLink: CheckoutLinkResult
searchUrl(url: String): SearchUrlResult
}

55 changes: 55 additions & 0 deletions catalog/model/extension/d_vuefront/seo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

class ModelExtensionDVuefrontSeo extends Model
{
public function searchKeyword($keyword) {
$type = '';
$id = 0;
if(VERSION >= '3.0.0.0') {
$parts = explode('/', preg_replace("/^\//", "", $keyword));

// remove any empty arrays from trailing
if (utf8_strlen(end($parts)) == 0) {
array_pop($parts);
}

foreach ($parts as $part) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE keyword = '" . $this->db->escape($part) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");

if ($query->num_rows) {
$url = explode('=', $query->row['query']);

if ($url[0] == 'product_id') {
$type = 'product';
$id = $url[1];
}

if ($url[0] == 'category_id') {
$type = 'category';
$id = $url[1];
}

if ($url[0] == 'manufacturer_id') {
$type = 'manufacturer';
$id = $url[1];
}

if ($url[0] == 'information_id') {
$type = 'page';
$id = $url[1];
}
} else {
break;
}
}
} else {
// $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` LIKE 'product_id=".(int)$product_id."'");
}

return array(
'type' => $type,
'id' => $id,
'url' => $keyword
);
}
}
2 changes: 1 addition & 1 deletion system/library/d_shopunity/extension/d_vuefront.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"catalog/controller/extension/d_vuefront",
"catalog/controller/extension/module/d_vuefront_schema",
"catalog/model/extension/d_vuefront",
"catalog/view/javascript/d_vuefront"
"catalog/view/javascript/d_vuefront",
"system/library/d_graphql"
],
"changelog": [
Expand Down

0 comments on commit 484a183

Please sign in to comment.