1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Divine CMS - Open source CMS for widespread use. |
4
|
|
|
Copyright (c) 2019 Mykola Burakov ([email protected]) |
5
|
|
|
|
6
|
|
|
See SOURCE.txt for other and additional information. |
7
|
|
|
|
8
|
|
|
This file is part of Divine CMS. |
9
|
|
|
|
10
|
|
|
This program is free software: you can redistribute it and/or modify |
11
|
|
|
it under the terms of the GNU General Public License as published by |
12
|
|
|
the Free Software Foundation, either version 3 of the License, or |
13
|
|
|
(at your option) any later version. |
14
|
|
|
|
15
|
|
|
This program is distributed in the hope that it will be useful, |
16
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
GNU General Public License for more details. |
19
|
|
|
|
20
|
|
|
You should have received a copy of the GNU General Public License |
21
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
22
|
|
|
|
23
|
|
|
class ControllerProductBestseller extends \Divine\Engine\Core\Controller |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
private $max = 100; |
26
|
|
|
public function index() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$this->load->language('product/bestseller'); |
29
|
|
|
|
30
|
|
|
$this->load->model('catalog/product'); |
31
|
|
|
$this->load->model('catalog/cms'); |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
|
35
|
|
|
if (isset($this->request->get['sort'])) { |
36
|
|
|
$sort = $this->request->get['sort']; |
37
|
|
|
$this->document->setRobots('noindex,follow'); |
38
|
|
|
} else { |
39
|
|
|
$sort = 'total'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if (isset($this->request->get['order'])) { |
43
|
|
|
$order = $this->request->get['order']; |
44
|
|
|
} else { |
45
|
|
|
$order = 'DESC'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if (isset($this->request->get['page'])) { |
49
|
|
|
$page = $this->request->get['page']; |
50
|
|
|
$this->document->setRobots('noindex,follow'); |
51
|
|
|
} else { |
52
|
|
|
$page = 1; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (isset($this->request->get['limit'])) { |
56
|
|
|
$limit = ((int)$this->request->get['limit'] > 100 ? 100 : (int)$this->request->get['limit']); |
|
|
|
|
57
|
|
|
$this->document->setRobots('noindex,follow'); |
58
|
|
|
} else { |
59
|
|
|
$limit = $this->config->get('config_limit_store'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if ($this->config->get('seomanager_meta_title_bestseller')) { |
63
|
|
|
$this->document->setTitle($this->config->get('seomanager_meta_title_bestseller')); |
64
|
|
|
} else { |
65
|
|
|
$this->document->setTitle($this->language->get('heading_title')); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if ($this->config->get('seomanager_html_h1_bestseller')) { |
69
|
|
|
$data['heading_title'] = $this->config->get('seomanager_html_h1_bestseller'); |
|
|
|
|
70
|
|
|
} else { |
71
|
|
|
$data['heading_title'] = $this->language->get('heading_title'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if ($this->config->get('seomanager_meta_description_bestseller')) { |
75
|
|
|
$this->document->setDescription($this->config->get('seomanager_meta_description_bestseller')); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$data['description'] = html_entity_decode(($this->config->get('seomanager_description_bestseller')), ENT_QUOTES, 'UTF-8'); |
79
|
|
|
|
80
|
|
|
$data['breadcrumbs'] = array(); |
81
|
|
|
|
82
|
|
|
$data['breadcrumbs'][] = array( |
83
|
|
|
'text' => $this->language->get('text_home'), |
84
|
|
|
'href' => $this->url->link('common/home') |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
$url = ''; |
88
|
|
|
|
89
|
|
|
if (isset($this->request->get['sort'])) { |
90
|
|
|
$url .= '&sort=' . $this->request->get['sort']; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if (isset($this->request->get['order'])) { |
94
|
|
|
$url .= '&order=' . $this->request->get['order']; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if (isset($this->request->get['page'])) { |
98
|
|
|
$url .= '&page=' . $this->request->get['page']; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if (isset($this->request->get['limit'])) { |
102
|
|
|
$url .= '&limit=' . $this->request->get['limit']; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$data['breadcrumbs'][] = array( |
106
|
|
|
'text' => $this->language->get('heading_title'), |
107
|
|
|
'href' => $this->url->link('product/bestseller', $url) |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$data['text_empty'] = $this->language->get('text_empty'); |
111
|
|
|
$data['text_quantity'] = $this->language->get('text_quantity'); |
112
|
|
|
$data['text_manufacturer'] = $this->language->get('text_manufacturer'); |
113
|
|
|
$data['text_model'] = $this->language->get('text_model'); |
114
|
|
|
$data['text_price'] = $this->language->get('text_price'); |
115
|
|
|
$data['text_points'] = $this->language->get('text_points'); |
116
|
|
|
$data['text_sort'] = $this->language->get('text_sort'); |
117
|
|
|
$data['text_limit'] = $this->language->get('text_limit'); |
118
|
|
|
$data['text_go_back'] = $this->language->get('text_go_back'); |
119
|
|
|
|
120
|
|
|
$data['button_buy_it'] = $this->language->get('button_buy_it'); |
121
|
|
|
$data['button_list'] = $this->language->get('button_list'); |
122
|
|
|
$data['button_grid'] = $this->language->get('button_grid'); |
123
|
|
|
$data['button_continue'] = $this->language->get('button_continue'); |
124
|
|
|
|
125
|
|
|
$data['products'] = array(); |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
$m_start = ($page - 1) * $limit; |
|
|
|
|
129
|
|
|
|
130
|
|
|
$filter_data = array( |
131
|
|
|
'sort' => $sort, |
132
|
|
|
'order' => $order, |
133
|
|
|
'start' => $m_start, |
134
|
|
|
'limit' => (($m_start + $limit) > $this->max) ? $this->max - $m_start : $limit |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
$results = $this->model_catalog_cms->getBestSeller($filter_data); |
138
|
|
|
|
139
|
|
|
$product_total = $this->model_catalog_cms->getTotalBestSeller(); |
140
|
|
|
|
141
|
|
|
if ($product_total > $this->max) { |
142
|
|
|
$product_total = $this->max; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
foreach ($results as $result) { |
146
|
|
|
if ($result['image']) { |
147
|
|
|
$image = '/public_html/assets/images/' . $result['image']; |
148
|
|
|
} else { |
149
|
|
|
$image = '/public_html/assets/images/no_image.png'; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { |
153
|
|
|
$price = $this->currency->format($result['price'], $this->session->data['currency']); |
154
|
|
|
} else { |
155
|
|
|
$price = false; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
if ((float)$result['special']) { |
159
|
|
|
$special = $this->currency->format($result['special'], $this->session->data['currency']); |
160
|
|
|
} else { |
161
|
|
|
$special = false; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
if ($result['description_mini']) { |
165
|
|
|
$description = \voku\helper\UTF8::substr(strip_tags(html_entity_decode($result['description_mini'], ENT_QUOTES, 'UTF-8')), 0); |
166
|
|
|
} else { |
167
|
|
|
$description = \voku\helper\UTF8::substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get($this->config->get('config_theme') . '_product_description_length')) . '..'; |
|
|
|
|
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
$stickers = $this->getStickers($result['product_id']); |
171
|
|
|
|
172
|
|
|
$data['products'][] = array( |
173
|
|
|
'product_id' => $result['product_id'], |
174
|
|
|
'thumb' => $image, |
175
|
|
|
'name' => $result['name'], |
176
|
|
|
'description' => $description, |
177
|
|
|
'price' => $price, |
178
|
|
|
'special' => $special, |
179
|
|
|
'sticker' => $stickers, |
180
|
|
|
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1, |
181
|
|
|
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'] . $url) |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
$url = ''; |
186
|
|
|
|
187
|
|
|
if (isset($this->request->get['limit'])) { |
188
|
|
|
$url .= '&limit=' . $this->request->get['limit']; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
$data['sorts'] = array(); |
192
|
|
|
|
193
|
|
|
$data['sorts'][] = array( |
194
|
|
|
'text' => $this->language->get('text_default'), |
195
|
|
|
'value' => 'p.sort_order-ASC', |
196
|
|
|
'href' => $this->url->link('product/bestseller', 'sort=p.sort_order&order=ASC' . $url) |
197
|
|
|
); |
198
|
|
|
|
199
|
|
|
$data['sorts'][] = array( |
200
|
|
|
'text' => $this->language->get('text_name_asc'), |
201
|
|
|
'value' => 'pd.name-ASC', |
202
|
|
|
'href' => $this->url->link('product/bestseller', 'sort=pd.name&order=ASC' . $url) |
203
|
|
|
); |
204
|
|
|
|
205
|
|
|
$data['sorts'][] = array( |
206
|
|
|
'text' => $this->language->get('text_name_desc'), |
207
|
|
|
'value' => 'pd.name-DESC', |
208
|
|
|
'href' => $this->url->link('product/bestseller', 'sort=pd.name&order=DESC' . $url) |
209
|
|
|
); |
210
|
|
|
|
211
|
|
|
$data['sorts'][] = array( |
212
|
|
|
'text' => $this->language->get('text_price_asc'), |
213
|
|
|
'value' => 'ps.price-ASC', |
214
|
|
|
'href' => $this->url->link('product/bestseller', 'sort=ps.price&order=ASC' . $url) |
215
|
|
|
); |
216
|
|
|
|
217
|
|
|
$data['sorts'][] = array( |
218
|
|
|
'text' => $this->language->get('text_price_desc'), |
219
|
|
|
'value' => 'ps.price-DESC', |
220
|
|
|
'href' => $this->url->link('product/bestseller', 'sort=ps.price&order=DESC' . $url) |
221
|
|
|
); |
222
|
|
|
|
223
|
|
|
$data['sorts'][] = array( |
224
|
|
|
'text' => $this->language->get('text_model_asc'), |
225
|
|
|
'value' => 'p.model-ASC', |
226
|
|
|
'href' => $this->url->link('product/bestseller', 'sort=p.model&order=ASC' . $url) |
227
|
|
|
); |
228
|
|
|
|
229
|
|
|
$data['sorts'][] = array( |
230
|
|
|
'text' => $this->language->get('text_model_desc'), |
231
|
|
|
'value' => 'p.model-DESC', |
232
|
|
|
'href' => $this->url->link('product/bestseller', 'sort=p.model&order=DESC' . $url) |
233
|
|
|
); |
234
|
|
|
|
235
|
|
|
$url = ''; |
236
|
|
|
|
237
|
|
|
if (isset($this->request->get['sort'])) { |
238
|
|
|
$url .= '&sort=' . $this->request->get['sort']; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
if (isset($this->request->get['order'])) { |
242
|
|
|
$url .= '&order=' . $this->request->get['order']; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
$data['limits'] = array(); |
246
|
|
|
|
247
|
|
|
$limits = array_unique(array($this->config->get('config_limit_store'), 25, 50, 75, 100)); |
248
|
|
|
|
249
|
|
|
sort($limits); |
250
|
|
|
|
251
|
|
|
foreach ($limits as $value) { |
252
|
|
|
$data['limits'][] = array( |
253
|
|
|
'text' => $value, |
254
|
|
|
'value' => $value, |
255
|
|
|
'href' => $this->url->link('product/bestseller', $url . '&limit=' . $value) |
256
|
|
|
); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
$url = ''; |
260
|
|
|
|
261
|
|
|
if (isset($this->request->get['sort'])) { |
262
|
|
|
$url .= '&sort=' . $this->request->get['sort']; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
if (isset($this->request->get['order'])) { |
266
|
|
|
$url .= '&order=' . $this->request->get['order']; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
if (isset($this->request->get['limit'])) { |
270
|
|
|
$url .= '&limit=' . $this->request->get['limit']; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
$pagination = new \Divine\Engine\Library\Pagination(); |
274
|
|
|
$pagination->total = $product_total; |
275
|
|
|
$pagination->page = $page; |
276
|
|
|
$pagination->limit = $limit; |
277
|
|
|
$pagination->url = $this->url->link('product/bestseller', $url . '&page={page}'); |
278
|
|
|
|
279
|
|
|
$data['pagination'] = $pagination->render(); |
280
|
|
|
|
281
|
|
|
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit)); |
282
|
|
|
|
283
|
|
|
// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html |
284
|
|
|
if ($page == 1) { |
285
|
|
|
$this->document->addLink($this->url->link('product/bestseller', '', true), 'canonical'); |
286
|
|
|
} elseif ($page == 2) { |
287
|
|
|
$this->document->addLink($this->url->link('product/bestseller', '', true), 'prev'); |
288
|
|
|
} else { |
289
|
|
|
$this->document->addLink($this->url->link('product/bestseller', 'page=' . ($page - 1), true), 'prev'); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
if ($limit && ceil($product_total / $limit) > $page) { |
293
|
|
|
$this->document->addLink($this->url->link('product/bestseller', 'page=' . ($page + 1), true), 'next'); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
$data['sort'] = $sort; |
297
|
|
|
$data['order'] = $order; |
298
|
|
|
$data['limit'] = $limit; |
299
|
|
|
|
300
|
|
|
$data['continue'] = $this->url->link('common/home'); |
301
|
|
|
|
302
|
|
|
$data['column'] = $this->load->controller('common/column'); |
303
|
|
|
|
304
|
|
|
$data['content_top'] = $this->load->controller('common/content_top'); |
305
|
|
|
$data['content_bottom'] = $this->load->controller('common/content_bottom'); |
306
|
|
|
$data['footer'] = $this->load->controller('common/footer'); |
307
|
|
|
$data['header'] = $this->load->controller('common/header'); |
308
|
|
|
|
309
|
|
|
$this->response->setOutput($this->load->view('product/special', $data)); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
private function getStickers($product_id) |
313
|
|
|
{ |
314
|
|
|
$stickers = $this->model_catalog_product->getProductStickerbyProductId($product_id); |
315
|
|
|
|
316
|
|
|
if (!$stickers) { |
317
|
|
|
return; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
$data['stickers'] = array(); |
|
|
|
|
321
|
|
|
|
322
|
|
|
foreach ($stickers as $sticker) { |
323
|
|
|
$data['stickers'][] = array( |
324
|
|
|
'position' => $sticker['position'], |
325
|
|
|
'image' => '/public_html/assets/images/' . $sticker['image'] |
326
|
|
|
); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
return $this->load->view('product/stickers', $data); |
330
|
|
|
} |
331
|
|
|
} |
332
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.