/
sitemap.php
114 lines (83 loc) · 4.27 KB
/
sitemap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
class ModelToolSitemap extends Model {
private function getPathByCategory($category_id) {
$category_id = (int)$category_id;
if($category_id < 1) return false;
$max_level = 10;
$sql = "SELECT CONCAT_WS('_'";
for($i = $max_level - 1; $i >= 0; --$i) {
$sql .= ",t$i.category_id";
}
$sql .= ") AS path FROM " . DB_PREFIX . "category t0";
for($i = 1; $i < $max_level; ++$i) {
$sql .= " LEFT JOIN " . DB_PREFIX . "category t$i ON (t$i.category_id = t" . ($i - 1) . ".parent_id)";
}
$sql .= " WHERE t0.category_id = '" . $category_id . "'";
$query = $this->db->query($sql);
return $query->num_rows ? $query->row['path'] : false;
}
public function getProducts() {
$product_data = $this->cache->get('product.sitemap.' . (int)$this->config->get('config_store_id'));
if(!$product_data) {
//cache for seo_pro
$category_path = array();
$query = $this->db->query("SELECT c.category_id FROM " . DB_PREFIX . "category c WHERE c.status = '1'");
foreach($query->rows as $row) {
$category_path[$row['category_id']] = $this->getPathByCategory($row['category_id']);
}
$category_path[0] = false;
$this->cache->set('category.seopath', $category_path);
$product_path = array();
$query = $this->db->query("SELECT p.product_id, date(GREATEST(p.date_added, p.date_modified)) as 'date'," .
" (SELECT category_id FROM " . DB_PREFIX . "product_to_category p2c WHERE p2c.product_id = p.product_id ORDER BY main_category DESC LIMIT 1) as category_id" .
" FROM " . DB_PREFIX . "product p" .
" LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id)" .
" WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"
);
foreach($query->rows as $row) {
$product_path[$row['product_id']] = $category_path[$row['category_id']];
}
$this->cache->set('product.seopath', $product_path);
$product_data = $query->rows;
$this->cache->set('product.sitemap.' . (int)$this->config->get('config_store_id'), $product_data);
}
return $product_data;
}
public function getAllCategories() {
$category_data = $this->cache->get('category.sitemap.' . (int)$this->config->get('config_store_id'));
if(!$category_data || !is_array($category_data)) {
$query = $this->db->query("SELECT c.category_id, c.parent_id, date(GREATEST(c.date_added, c.date_modified)) as 'date' FROM " . DB_PREFIX . "category c" .
" LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id)" .
" WHERE c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND c.status = '1'");
$category_data = array();
foreach($query->rows as $row) {
$category_data[$row['parent_id']][$row['category_id']] = $row;
}
$this->cache->set('category.sitemap.' . (int)$this->config->get('config_store_id'), $category_data);
}
return $category_data;
}
public function getManufacturers() {
$manufacturer_data = $this->cache->get('manufacturer.sitemap.' . (int)$this->config->get('config_store_id'));
if(!$manufacturer_data) {
$query = $this->db->query("SELECT m.manufacturer_id FROM " . DB_PREFIX . "manufacturer m" .
" LEFT JOIN " . DB_PREFIX . "manufacturer_to_store m2s ON (m.manufacturer_id = m2s.manufacturer_id)" .
" WHERE m2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
$manufacturer_data = $query->rows;
$this->cache->set('manufacturer.sitemap.' . (int)$this->config->get('config_store_id'), $manufacturer_data);
}
return $manufacturer_data;
}
public function getInformations() {
$informations_data = $this->cache->get('information.sitemap.' . (int)$this->config->get('config_store_id'));
if(!$informations_data) {
$query = $this->db->query("SELECT i.information_id FROM " . DB_PREFIX . "information i" .
" LEFT JOIN " . DB_PREFIX . "information_to_store i2s ON (i.information_id = i2s.information_id)" .
" WHERE i2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND i.status = '1' AND i.sort_order <> '-1'");
$informations_data = $query->rows;
$this->cache->set('information.sitemap.' . (int)$this->config->get('config_store_id'), $informations_data);
}
return $informations_data;
}
}
?>