1: | <?php
2: | namespace Opencart\Catalog\Controller\Product;
3: | /**
4: | * Class Special
5: | *
6: | * @package Opencart\Catalog\Controller\Product
7: | */
8: | class Special extends \Opencart\System\Engine\Controller {
9: | /**
10: | * @return void
11: | */
12: | public function index(): void {
13: | $this->load->language('product/special');
14: |
15: | if (isset($this->request->get['sort'])) {
16: | $sort = $this->request->get['sort'];
17: | } else {
18: | $sort = 'p.sort_order';
19: | }
20: |
21: | if (isset($this->request->get['order'])) {
22: | $order = $this->request->get['order'];
23: | } else {
24: | $order = 'ASC';
25: | }
26: |
27: | if (isset($this->request->get['page'])) {
28: | $page = (int)$this->request->get['page'];
29: | } else {
30: | $page = 1;
31: | }
32: |
33: | if (isset($this->request->get['limit']) && (int)$this->request->get['limit']) {
34: | $limit = (int)$this->request->get['limit'];
35: | } else {
36: | $limit = $this->config->get('config_pagination');
37: | }
38: |
39: | $this->document->setTitle($this->language->get('heading_title'));
40: |
41: | $data['breadcrumbs'] = [];
42: |
43: | $data['breadcrumbs'][] = [
44: | 'text' => $this->language->get('text_home'),
45: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
46: | ];
47: |
48: | $url = '';
49: |
50: | if (isset($this->request->get['sort'])) {
51: | $url .= '&sort=' . $this->request->get['sort'];
52: | }
53: |
54: | if (isset($this->request->get['order'])) {
55: | $url .= '&order=' . $this->request->get['order'];
56: | }
57: |
58: | if (isset($this->request->get['page'])) {
59: | $url .= '&page=' . $this->request->get['page'];
60: | }
61: |
62: | if (isset($this->request->get['limit'])) {
63: | $url .= '&limit=' . $this->request->get['limit'];
64: | }
65: |
66: | $data['breadcrumbs'][] = [
67: | 'text' => $this->language->get('heading_title'),
68: | 'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . $url)
69: | ];
70: |
71: | $data['text_compare'] = sprintf($this->language->get('text_compare'), isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0);
72: |
73: | $data['compare'] = $this->url->link('product/compare', 'language=' . $this->config->get('config_language'));
74: |
75: | $data['products'] = [];
76: |
77: | $filter_data = [
78: | 'sort' => $sort,
79: | 'order' => $order,
80: | 'start' => ($page - 1) * $limit,
81: | 'limit' => $limit
82: | ];
83: |
84: | $this->load->model('catalog/product');
85: | $this->load->model('tool/image');
86: |
87: | $results = $this->model_catalog_product->getSpecials($filter_data);
88: |
89: | foreach ($results as $result) {
90: | $description = trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')));
91: |
92: | if (oc_strlen($description) > $this->config->get('config_product_description_length')) {
93: | $description = oc_substr($description, 0, $this->config->get('config_product_description_length')) . '..';
94: | }
95: |
96: | if ($result['image'] && is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
97: | $image = $result['image'];
98: | } else {
99: | $image = 'placeholder.png';
100: | }
101: |
102: | if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
103: | $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
104: | } else {
105: | $price = false;
106: | }
107: |
108: | if ((float)$result['special']) {
109: | $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
110: | } else {
111: | $special = false;
112: | }
113: |
114: | if ($this->config->get('config_tax')) {
115: | $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
116: | } else {
117: | $tax = false;
118: | }
119: |
120: | $product_data = [
121: | 'product_id' => $result['product_id'],
122: | 'thumb' => $this->model_tool_image->resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),
123: | 'name' => $result['name'],
124: | 'description' => $description,
125: | 'price' => $price,
126: | 'special' => $special,
127: | 'tax' => $tax,
128: | 'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
129: | 'rating' => $result['rating'],
130: | 'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'] . $url)
131: | ];
132: |
133: | $data['products'][] = $this->load->controller('product/thumb', $product_data);
134: | }
135: |
136: | $url = '';
137: |
138: | if (isset($this->request->get['limit'])) {
139: | $url .= '&limit=' . $this->request->get['limit'];
140: | }
141: |
142: | $data['sorts'] = [];
143: |
144: | $data['sorts'][] = [
145: | 'text' => $this->language->get('text_default'),
146: | 'value' => 'p.sort_order-ASC',
147: | 'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=p.sort_order&order=ASC' . $url)
148: | ];
149: |
150: | $data['sorts'][] = [
151: | 'text' => $this->language->get('text_name_asc'),
152: | 'value' => 'pd.name-ASC',
153: | 'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=ASC' . $url)
154: | ];
155: |
156: | $data['sorts'][] = [
157: | 'text' => $this->language->get('text_name_desc'),
158: | 'value' => 'pd.name-DESC',
159: | 'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=pd.name&order=DESC' . $url)
160: | ];
161: |
162: | $data['sorts'][] = [
163: | 'text' => $this->language->get('text_price_asc'),
164: | 'value' => 'ps.price-ASC',
165: | 'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=ps.price&order=ASC' . $url)
166: | ];
167: |
168: | $data['sorts'][] = [
169: | 'text' => $this->language->get('text_price_desc'),
170: | 'value' => 'ps.price-DESC',
171: | 'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=ps.price&order=DESC' . $url)
172: | ];
173: |
174: | if ($this->config->get('config_review_status')) {
175: | $data['sorts'][] = [
176: | 'text' => $this->language->get('text_rating_desc'),
177: | 'value' => 'rating-DESC',
178: | 'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=rating&order=DESC' . $url)
179: | ];
180: |
181: | $data['sorts'][] = [
182: | 'text' => $this->language->get('text_rating_asc'),
183: | 'value' => 'rating-ASC',
184: | 'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=rating&order=ASC' . $url)
185: | ];
186: | }
187: |
188: | $data['sorts'][] = [
189: | 'text' => $this->language->get('text_model_asc'),
190: | 'value' => 'p.model-ASC',
191: | 'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=ASC' . $url)
192: | ];
193: |
194: | $data['sorts'][] = [
195: | 'text' => $this->language->get('text_model_desc'),
196: | 'value' => 'p.model-DESC',
197: | 'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&sort=p.model&order=DESC' . $url)
198: | ];
199: |
200: | $url = '';
201: |
202: | if (isset($this->request->get['sort'])) {
203: | $url .= '&sort=' . $this->request->get['sort'];
204: | }
205: |
206: | if (isset($this->request->get['order'])) {
207: | $url .= '&order=' . $this->request->get['order'];
208: | }
209: |
210: | $data['limits'] = [];
211: |
212: | $limits = array_unique([$this->config->get('config_pagination'), 25, 50, 75, 100]);
213: |
214: | sort($limits);
215: |
216: | foreach ($limits as $value) {
217: | $data['limits'][] = [
218: | 'text' => $value,
219: | 'value' => $value,
220: | 'href' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . $url . '&limit=' . $value)
221: | ];
222: | }
223: |
224: | $url = '';
225: |
226: | if (isset($this->request->get['sort'])) {
227: | $url .= '&sort=' . $this->request->get['sort'];
228: | }
229: |
230: | if (isset($this->request->get['order'])) {
231: | $url .= '&order=' . $this->request->get['order'];
232: | }
233: |
234: | if (isset($this->request->get['limit'])) {
235: | $url .= '&limit=' . $this->request->get['limit'];
236: | }
237: |
238: | $product_total = $this->model_catalog_product->getTotalSpecials();
239: |
240: | $data['pagination'] = $this->load->controller('common/pagination', [
241: | 'total' => $product_total,
242: | 'page' => $page,
243: | 'limit' => $limit,
244: | 'url' => $this->url->link('product/special', 'language=' . $this->config->get('config_language') . $url . '&page={page}')
245: | ]);
246: |
247: | $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));
248: |
249: | // https://developers.google.com/search/blog/2011/09/pagination-with-relnext-and-relprev
250: | if ($page == 1) {
251: | $this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language')), 'canonical');
252: | } else {
253: | $this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&page=' . $page), 'canonical');
254: | }
255: |
256: | if ($page > 1) {
257: | $this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language') . (($page - 2) ? '&page=' . ($page - 1) : '')), 'prev');
258: | }
259: |
260: | if ($limit && ceil($product_total / $limit) > $page) {
261: | $this->document->addLink($this->url->link('product/special', 'language=' . $this->config->get('config_language') . '&page=' . ($page + 1)), 'next');
262: | }
263: |
264: | $data['sort'] = $sort;
265: | $data['order'] = $order;
266: | $data['limit'] = $limit;
267: |
268: | $data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
269: |
270: | $data['column_left'] = $this->load->controller('common/column_left');
271: | $data['column_right'] = $this->load->controller('common/column_right');
272: | $data['content_top'] = $this->load->controller('common/content_top');
273: | $data['content_bottom'] = $this->load->controller('common/content_bottom');
274: | $data['footer'] = $this->load->controller('common/footer');
275: | $data['header'] = $this->load->controller('common/header');
276: |
277: | $this->response->setOutput($this->load->view('product/special', $data));
278: | }
279: | }
280: |

OpenCart API API documentation generated by ApiGen dev-master