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

OpenCart API API documentation generated by ApiGen dev-master