1: | <?php
2: | namespace Opencart\Catalog\Model\Catalog;
3: | /**
4: | * Class Manufacturer
5: | *
6: | * @package Opencart\Catalog\Model\Catalog
7: | */
8: | class Manufacturer extends \Opencart\System\Engine\Model {
9: | /**
10: | * Get Manufacturer
11: | *
12: | * @param int $manufacturer_id
13: | *
14: | * @return array<string, mixed>
15: | */
16: | public function getManufacturer(int $manufacturer_id): array {
17: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "manufacturer` `m` LEFT JOIN `" . DB_PREFIX . "manufacturer_to_store` `m2s` ON (`m`.`manufacturer_id` = `m2s`.`manufacturer_id`) WHERE `m`.`manufacturer_id` = '" . (int)$manufacturer_id . "' AND `m2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "'");
18: |
19: | return $query->row;
20: | }
21: |
22: | /**
23: | * Get Manufacturer(s)
24: | *
25: | * @param array<string, mixed> $data
26: | *
27: | * @return array<int, array<string, mixed>>
28: | */
29: | public function getManufacturers(array $data = []): array {
30: | $sql = "SELECT * 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') . "'";
31: |
32: | $sort_data = [
33: | 'name',
34: | 'sort_order'
35: | ];
36: |
37: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
38: | $sql .= " ORDER BY `" . $data['sort'] . "`";
39: | } else {
40: | $sql .= " ORDER BY `name`";
41: | }
42: |
43: | if (isset($data['order']) && ($data['order'] == 'DESC')) {
44: | $sql .= " DESC";
45: | } else {
46: | $sql .= " ASC";
47: | }
48: |
49: | if (isset($data['start']) || isset($data['limit'])) {
50: | if ($data['start'] < 0) {
51: | $data['start'] = 0;
52: | }
53: |
54: | if ($data['limit'] < 1) {
55: | $data['limit'] = 20;
56: | }
57: |
58: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
59: | }
60: |
61: | $key = md5($sql);
62: |
63: | $manufacturer_data = $this->cache->get('manufacturer.' . $key);
64: |
65: | if (!$manufacturer_data) {
66: | $query = $this->db->query($sql);
67: |
68: | $manufacturer_data = $query->rows;
69: |
70: | $this->cache->set('manufacturer.' . $key, $manufacturer_data);
71: | }
72: |
73: | return $manufacturer_data;
74: | }
75: |
76: | /**
77: | * Get Layout ID
78: | *
79: | * @param int $manufacturer_id
80: | *
81: | * @return int
82: | */
83: | public function getLayoutId(int $manufacturer_id): int {
84: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "manufacturer_to_layout` WHERE `manufacturer_id` = '" . (int)$manufacturer_id . "' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "'");
85: |
86: | if ($query->num_rows) {
87: | return (int)$query->row['layout_id'];
88: | } else {
89: | return 0;
90: | }
91: | }
92: | }
93: |

OpenCart API API documentation generated by ApiGen dev-master