Back to Opencart

File admin\model\catalog\manufacturer.php

docs/api/source-admin.model.catalog.manufacturer.html

4.1.0.317.3 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Admin\Model\Catalog; | | 3: | /** | | 4: | * Class Manufacturer | | 5: | * | | 6: | * @package Opencart\Admin\Model\Catalog | | 7: | */ | | 8: | class Manufacturer extends \Opencart\System\Engine\Model { | | 9: | /** | | 10: | * Add Manufacturer | | 11: | * | | 12: | * @param array<string, mixed> $data | | 13: | * | | 14: | * @return int | | 15: | */ | | 16: | public function addManufacturer(array $data): int { | | 17: | $this->db->query("INSERT INTO " . DB\_PREFIX . "manufacturer SET name = '" . $this->db->escape((string)$data['name']) . "', image = '" . $this->db->escape((string)$data['image']) . "', sort_order = '" . (int)$data['sort_order'] . "'"); | | 18: | | | 19: | $manufacturer_id = $this->db->getLastId(); | | 20: | | | 21: | // Store | | 22: | if (isset($data['manufacturer_store'])) { | | 23: | foreach ($data['manufacturer_store'] as $store_id) { | | 24: | $this->model_catalog_manufacturer->addStore($manufacturer_id, $store_id); | | 25: | } | | 26: | } | | 27: | | | 28: | // SEO URL | | 29: | $this->load->model('design/seo_url'); | | 30: | | | 31: | foreach ($data['manufacturer_seo_url'] as $store_id => $language) { | | 32: | foreach ($language as $language_id => $keyword) { | | 33: | $this->model_design_seo_url->addSeoUrl('manufacturer_id', $manufacturer_id, $keyword, $store_id, $language_id); | | 34: | } | | 35: | } | | 36: | | | 37: | // Layouts | | 38: | if (isset($data['manufacturer_layout'])) { | | 39: | foreach ($data['manufacturer_layout'] as $store_id => $layout_id) { | | 40: | if ($layout_id) { | | 41: | $this->model_catalog_manufacturer->addLayout($manufacturer_id, $store_id, $layout_id); | | 42: | } | | 43: | } | | 44: | } | | 45: | | | 46: | $this->cache->delete('manufacturer'); | | 47: | | | 48: | return $manufacturer_id; | | 49: | } | | 50: | | | 51: | /** | | 52: | * Edit Manufacturer | | 53: | * | | 54: | * @param int $manufacturer_id | | 55: | * @param array<string, mixed> $data | | 56: | * | | 57: | * @return void | | 58: | */ | | 59: | public function editManufacturer(int $manufacturer_id, array $data): void { | | 60: | $this->db->query("UPDATE " . DB\_PREFIX . "manufacturer SET name = '" . $this->db->escape((string)$data['name']) . "', image = '" . $this->db->escape((string)$data['image']) . "', sort_order = '" . (int)$data['sort_order'] . "' WHERE manufacturer_id = '" . (int)$manufacturer_id . "'"); | | 61: | | | 62: | // Store | | 63: | $this->deleteStores($manufacturer_id); | | 64: | | | 65: | if (isset($data['manufacturer_store'])) { | | 66: | foreach ($data['manufacturer_store'] as $store_id) { | | 67: | $this->model_catalog_manufacturer->addStore($manufacturer_id, $store_id); | | 68: | } | | 69: | } | | 70: | | | 71: | // SEO URL | | 72: | $this->load->model('design/seo_url'); | | 73: | | | 74: | $this->model_design_seo_url->deleteSeoUrlsByKeyValue('manufacturer_id', $manufacturer_id); | | 75: | | | 76: | if (isset($data['manufacturer_seo_url'])) { | | 77: | foreach ($data['manufacturer_seo_url'] as $store_id => $language) { | | 78: | foreach ($language as $language_id => $keyword) { | | 79: | $this->model_design_seo_url->addSeoUrl('manufacturer_id', $manufacturer_id, $keyword, $store_id, $language_id); | | 80: | } | | 81: | } | | 82: | } | | 83: | | | 84: | // Layouts | | 85: | $this->model_catalog_manufacturer->deleteLayouts($manufacturer_id); | | 86: | | | 87: | if (isset($data['manufacturer_layout'])) { | | 88: | foreach ($data['manufacturer_layout'] as $store_id => $layout_id) { | | 89: | if ($layout_id) { | | 90: | $this->model_catalog_manufacturer->addLayout($manufacturer_id, $store_id, $layout_id); | | 91: | } | | 92: | } | | 93: | } | | 94: | | | 95: | $this->cache->delete('manufacturer'); | | 96: | } | | 97: | | | 98: | /** | | 99: | * Delete Manufacturer | | 100: | * | | 101: | * @param int $manufacturer_id | | 102: | * | | 103: | * @return void | | 104: | */ | | 105: | public function deleteManufacturer(int $manufacturer_id): void { | | 106: | $this->db->query("DELETE FROM " . DB\_PREFIX . "manufacturer WHERE manufacturer\_id = '" . (int)$manufacturer_id . "'"); | | 107: | | | 108: | $this->model_catalog_manufacturer->deleteStores($manufacturer_id); | | 109: | $this->model_catalog_manufacturer->deleteLayouts($manufacturer_id); | | 110: | | | 111: | $this->load->model('design/seo_url'); | | 112: | | | 113: | $this->model_design_seo_url->deleteSeoUrlsByKeyValue('manufacturer_id', $manufacturer_id); | | 114: | | | 115: | $this->cache->delete('manufacturer'); | | 116: | } | | 117: | | | 118: | /** | | 119: | * Get Manufacturer | | 120: | * | | 121: | * @param int $manufacturer_id | | 122: | * | | 123: | * @return array<string, mixed> | | 124: | */ | | 125: | public function getManufacturer(int $manufacturer_id): array { | | 126: | $query = $this->db->query("SELECT DISTINCT * FROM " . DB\_PREFIX . "manufacturer WHERE manufacturer\_id = '" . (int)$manufacturer_id . "'"); | | 127: | | | 128: | return $query->row; | | 129: | } | | 130: | | | 131: | /** | | 132: | * Get Manufacturers | | 133: | * | | 134: | * @param array<string, mixed> $data | | 135: | * | | 136: | * @return array<int, array<string, mixed>> | | 137: | */ | | 138: | public function getManufacturers(array $data = []): array { | | 139: | $sql = "SELECT * FROM " . DB\_PREFIX . "manufacturer"; | | 140: | | | 141: | if (!empty($data['filter_name'])) { | | 142: | $sql .= " WHERE LCASE(name) LIKE '" . $this->db->escape(oc_strtolower($data['filter_name']) . '%') . "'"; | | 143: | } | | 144: | | | 145: | $sort_data = [ | | 146: | 'name', | | 147: | 'sort_order' | | 148: | ]; | | 149: | | | 150: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { | | 151: | $sql .= " ORDER BY " . $data['sort']; | | 152: | } else { | | 153: | $sql .= " ORDER BY name"; | | 154: | } | | 155: | | | 156: | if (isset($data['order']) && ($data['order'] == 'DESC')) { | | 157: | $sql .= " DESC"; | | 158: | } else { | | 159: | $sql .= " ASC"; | | 160: | } | | 161: | | | 162: | if (isset($data['start']) || isset($data['limit'])) { | | 163: | if ($data['start'] < 0) { | | 164: | $data['start'] = 0; | | 165: | } | | 166: | | | 167: | if ($data['limit'] < 1) { | | 168: | $data['limit'] = 20; | | 169: | } | | 170: | | | 171: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; | | 172: | } | | 173: | | | 174: | $query = $this->db->query($sql); | | 175: | | | 176: | return $query->rows; | | 177: | } | | 178: | | | 179: | /** | | 180: | * Get Total Manufacturers | | 181: | * | | 182: | * @return int | | 183: | */ | | 184: | public function getTotalManufacturers(): int { | | 185: | $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB\_PREFIX . "manufacturer"); | | 186: | | | 187: | return (int)$query->row['total']; | | 188: | } | | 189: | | | 190: | /** | | 191: | * Add Store | | 192: | * | | 193: | * @param int $manufacturer_id | | 194: | * @param int $store_id | | 195: | * | | 196: | * @return void | | 197: | */ | | 198: | public function addStore(int $manufacturer_id, int $store_id): void { | | 199: | $this->db->query("INSERT INTO " . DB\_PREFIX . "manufacturer\_to\_store SET manufacturer\_id = '" . (int)$manufacturer_id . "', store_id = '" . (int)$store_id . "'"); | | 200: | } | | 201: | | | 202: | /** | | 203: | * Delete Stores | | 204: | * | | 205: | * @param int $manufacturer_id | | 206: | * | | 207: | * @return void | | 208: | */ | | 209: | public function deleteStores(int $manufacturer_id): void { | | 210: | $this->db->query("DELETE FROM " . DB\_PREFIX . "manufacturer\_to\_store WHERE manufacturer\_id = '" . (int)$manufacturer_id . "'"); | | 211: | } | | 212: | | | 213: | /** | | 214: | * Delete Stores By Store ID | | 215: | * | | 216: | * @param int $store_id | | 217: | * | | 218: | * @return void | | 219: | */ | | 220: | public function deleteStoresByStoreId(int $store_id): void { | | 221: | $this->db->query("DELETE FROM " . DB\_PREFIX . "manufacturer\_to\_store WHERE store\_id = '" . (int)$store_id . "'"); | | 222: | } | | 223: | | | 224: | /** | | 225: | * Get Stores | | 226: | * | | 227: | * @param int $manufacturer_id | | 228: | * | | 229: | * @return array<int, int> | | 230: | */ | | 231: | public function getStores(int $manufacturer_id): array { | | 232: | $manufacturer_store_data = []; | | 233: | | | 234: | $query = $this->db->query("SELECT * FROM " . DB\_PREFIX . "manufacturer\_to\_store WHERE manufacturer\_id = '" . (int)$manufacturer_id . "'"); | | 235: | | | 236: | foreach ($query->rows as $result) { | | 237: | $manufacturer_store_data[] = $result['store_id']; | | 238: | } | | 239: | | | 240: | return $manufacturer_store_data; | | 241: | } | | 242: | | | 243: | /** | | 244: | * Add Layout | | 245: | * | | 246: | * @param int $manufacturer_id | | 247: | * @param int $store_id | | 248: | * @param int $layout_id | | 249: | * | | 250: | * @return void | | 251: | */ | | 252: | public function addLayout(int $manufacturer_id, int $store_id, int $layout_id): void { | | 253: | $this->db->query("INSERT INTO " . DB\_PREFIX . "manufacturer\_to\_layout SET manufacturer\_id = '" . (int)$manufacturer_id . "', store_id = '" . (int)$store_id . "', layout_id = '" . (int)$layout_id . "'"); | | 254: | } | | 255: | | | 256: | /** | | 257: | * Delete Layouts | | 258: | * | | 259: | * @param int $manufacturer_id | | 260: | * | | 261: | * @return void | | 262: | */ | | 263: | public function deleteLayouts(int $manufacturer_id): void { | | 264: | $this->db->query("DELETE FROM " . DB\_PREFIX . "manufacturer\_to\_layout WHERE manufacturer\_id = '" . (int)$manufacturer_id . "'"); | | 265: | } | | 266: | | | 267: | /** | | 268: | * Delete Layouts By Layout ID | | 269: | * | | 270: | * @param int $layout_id | | 271: | * | | 272: | * @return void | | 273: | */ | | 274: | public function deleteLayoutsByLayoutId(int $layout_id): void { | | 275: | $this->db->query("DELETE FROM " . DB\_PREFIX . "manufacturer\_to\_layout WHERE layout\_id = '" . (int)$layout_id . "'"); | | 276: | } | | 277: | | | 278: | /** | | 279: | * Delete Layouts By Store ID | | 280: | * | | 281: | * @param int $store_id | | 282: | * | | 283: | * @return void | | 284: | */ | | 285: | public function deleteLayoutsByStoreId(int $store_id): void { | | 286: | $this->db->query("DELETE FROM " . DB\_PREFIX . "manufacturer\_to\_layout WHERE store\_id = '" . (int)$store_id . "'"); | | 287: | } | | 288: | | | 289: | /** | | 290: | * Get Layouts | | 291: | * | | 292: | * @param int $manufacturer_id | | 293: | * | | 294: | * @return array<int, int> | | 295: | */ | | 296: | public function getLayouts(int $manufacturer_id): array { | | 297: | $manufacturer_layout_data = []; | | 298: | | | 299: | $query = $this->db->query("SELECT * FROM " . DB\_PREFIX . "manufacturer\_to\_layout WHERE manufacturer\_id = '" . (int)$manufacturer_id . "'"); | | 300: | | | 301: | foreach ($query->rows as $result) { | | 302: | $manufacturer_layout_data[$result['store_id']] = $result['layout_id']; | | 303: | } | | 304: | | | 305: | return $manufacturer_layout_data; | | 306: | } | | 307: | | | 308: | /** | | 309: | * Get Total Layouts By Layout ID | | 310: | * | | 311: | * @param int $layout_id | | 312: | * | | 313: | * @return int | | 314: | */ | | 315: | public function getTotalLayoutsByLayoutId(int $layout_id): int { | | 316: | $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB\_PREFIX . "manufacturer\_to\_layout WHERE layout\_id = '" . (int)$layout_id . "'"); | | 317: | | | 318: | return (int)$query->row['total']; | | 319: | } | | 320: | } | | 321: | |

OpenCart API API documentation generated by ApiGen dev-master