1: | <?php
2: | namespace Opencart\Catalog\Model\Catalog;
3: | /**
4: | * Class Category
5: | *
6: | * @package Opencart\Catalog\Model\Catalog
7: | */
8: | class Category extends \Opencart\System\Engine\Model {
9: | /**
10: | * Get Category
11: | *
12: | * @param int $category_id
13: | *
14: | * @return array<string, mixed>
15: | */
16: | public function getCategory(int $category_id): array {
17: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "category` `c` LEFT JOIN `" . DB_PREFIX . "category_description` `cd` ON (`c`.`category_id` = `cd`.`category_id`) LEFT JOIN `" . DB_PREFIX . "category_to_store` `c2s` ON (`c`.`category_id` = `c2s`.`category_id`) WHERE `c`.`category_id` = '" . (int)$category_id . "' AND `cd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND `c2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND `c`.`status` = '1'");
18: |
19: | return $query->row;
20: | }
21: |
22: | /**
23: | * Get Categories
24: | *
25: | * @param int $parent_id
26: | *
27: | * @return array<int, array<string, mixed>>
28: | */
29: | public function getCategories(int $parent_id = 0): array {
30: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category` `c` LEFT JOIN `" . DB_PREFIX . "category_description` `cd` ON (`c`.`category_id` = `cd`.`category_id`) LEFT JOIN `" . DB_PREFIX . "category_to_store` `c2s` ON (`c`.`category_id` = `c2s`.`category_id`) WHERE `c`.`parent_id` = '" . (int)$parent_id . "' AND `cd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND `c2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND `c`.`status` = '1' ORDER BY `c`.`sort_order`, LCASE(`cd`.`name`)");
31: |
32: | return $query->rows;
33: | }
34: |
35: | /**
36: | * Get Filters
37: | *
38: | * @param int $category_id
39: | *
40: | * @return array<int, array<string, mixed>>
41: | */
42: | public function getFilters(int $category_id): array {
43: | $implode = [];
44: |
45: | $query = $this->db->query("SELECT `filter_id` FROM `" . DB_PREFIX . "category_filter` WHERE `category_id` = '" . (int)$category_id . "'");
46: |
47: | foreach ($query->rows as $result) {
48: | $implode[] = (int)$result['filter_id'];
49: | }
50: |
51: | $filter_group_data = [];
52: |
53: | if ($implode) {
54: | $filter_group_query = $this->db->query("SELECT DISTINCT `f`.`filter_group_id`, `fgd`.`name`, `fg`.`sort_order` FROM `" . DB_PREFIX . "filter` `f` LEFT JOIN `" . DB_PREFIX . "filter_group` `fg` ON (`f`.`filter_group_id` = `fg`.`filter_group_id`) LEFT JOIN `" . DB_PREFIX . "filter_group_description` `fgd` ON (`fg`.`filter_group_id` = `fgd`.`filter_group_id`) WHERE `f`.`filter_id` IN (" . implode(',', $implode) . ") AND `fgd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' GROUP BY `f`.`filter_group_id` ORDER BY `fg`.`sort_order`, LCASE(`fgd`.`name`)");
55: |
56: | foreach ($filter_group_query->rows as $filter_group) {
57: | $filter_data = [];
58: |
59: | $filter_query = $this->db->query("SELECT DISTINCT `f`.`filter_id`, `fd`.`name` FROM `" . DB_PREFIX . "filter` `f` LEFT JOIN `" . DB_PREFIX . "filter_description` `fd` ON (`f`.`filter_id` = `fd`.`filter_id`) WHERE `f`.`filter_id` IN (" . implode(',', $implode) . ") AND `f`.`filter_group_id` = '" . (int)$filter_group['filter_group_id'] . "' AND `fd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `f`.`sort_order`, LCASE(`fd`.`name`)");
60: |
61: | foreach ($filter_query->rows as $filter) {
62: | $filter_data[] = [
63: | 'filter_id' => $filter['filter_id'],
64: | 'name' => $filter['name']
65: | ];
66: | }
67: |
68: | if ($filter_data) {
69: | $filter_group_data[] = [
70: | 'filter_group_id' => $filter_group['filter_group_id'],
71: | 'name' => $filter_group['name'],
72: | 'filter' => $filter_data
73: | ];
74: | }
75: | }
76: | }
77: |
78: | return $filter_group_data;
79: | }
80: |
81: | /**
82: | * Get Layout ID
83: | *
84: | * @param int $category_id
85: | *
86: | * @return int
87: | */
88: | public function getLayoutId(int $category_id): int {
89: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_to_layout` WHERE `category_id` = '" . (int)$category_id . "' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "'");
90: |
91: | if ($query->num_rows) {
92: | return (int)$query->row['layout_id'];
93: | } else {
94: | return 0;
95: | }
96: | }
97: | }
98: |

OpenCart API API documentation generated by ApiGen dev-master