| 1: | <?php
|
| 2: | namespace Opencart\Admin\Model\Setting;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Store extends \Opencart\System\Engine\Model {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: |
|
| 16: | public function addStore(array $data): int {
|
| 17: | $this->db->query("INSERT INTO `" . DB_PREFIX . "store` SET `name` = '" . $this->db->escape((string)$data['config_name']) . "', `url` = '" . $this->db->escape((string)$data['config_url']) . "'");
|
| 18: |
|
| 19: | $store_id = $this->db->getLastId();
|
| 20: |
|
| 21: |
|
| 22: | $this->load->model('design/layout');
|
| 23: |
|
| 24: | $results = $this->model_design_layout->getRoutesByStoreId(0);
|
| 25: |
|
| 26: | foreach ($results as $result) {
|
| 27: | $this->model_design_layout->addRoute($result['layout_id'], $result + ['store_id' => $store_id]);
|
| 28: | }
|
| 29: |
|
| 30: |
|
| 31: | $this->load->model('design/seo_url');
|
| 32: |
|
| 33: | $results = $this->model_design_seo_url->getSeoUrlsByStoreId(0);
|
| 34: |
|
| 35: | foreach ($results as $result) {
|
| 36: | $this->model_design_seo_url->addSeoUrl($result['key'], $result['value'], $result['keyword'], $store_id, $result['language_id'], $result['sort_order']);
|
| 37: | }
|
| 38: |
|
| 39: | $this->cache->delete('store');
|
| 40: |
|
| 41: | return $store_id;
|
| 42: | }
|
| 43: |
|
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: |
|
| 52: | public function editStore(int $store_id, array $data): void {
|
| 53: | $this->db->query("UPDATE `" . DB_PREFIX . "store` SET `name` = '" . $this->db->escape((string)$data['config_name']) . "', `url` = '" . $this->db->escape((string)$data['config_url']) . "' WHERE `store_id` = '" . (int)$store_id . "'");
|
| 54: |
|
| 55: | $this->cache->delete('store');
|
| 56: | }
|
| 57: |
|
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: |
|
| 65: | public function deleteStore(int $store_id): void {
|
| 66: | $this->db->query("DELETE FROM `" . DB_PREFIX . "store` WHERE `store_id` = '" . (int)$store_id . "'");
|
| 67: |
|
| 68: |
|
| 69: | $this->load->model('catalog/category');
|
| 70: |
|
| 71: | $this->model_catalog_category->deleteLayoutsByStoreId($store_id);
|
| 72: | $this->model_catalog_category->deleteStoresByStoreId($store_id);
|
| 73: |
|
| 74: | $this->load->model('catalog/information');
|
| 75: |
|
| 76: | $this->model_catalog_information->deleteLayoutsByStoreId($store_id);
|
| 77: | $this->model_catalog_information->deleteStoresByStoreId($store_id);
|
| 78: |
|
| 79: | $this->load->model('catalog/manufacturer');
|
| 80: |
|
| 81: | $this->model_catalog_manufacturer->deleteLayoutsByStoreId($store_id);
|
| 82: | $this->model_catalog_manufacturer->deleteStoresByStoreId($store_id);
|
| 83: |
|
| 84: | $this->load->model('catalog/product');
|
| 85: |
|
| 86: | $this->model_catalog_product->deleteLayoutsByStoreId($store_id);
|
| 87: | $this->model_catalog_product->deleteStoresByStoreId($store_id);
|
| 88: |
|
| 89: | $this->load->model('customer/gdpr');
|
| 90: |
|
| 91: | $this->model_customer_gdpr->deleteGdprsByStoreId($store_id);
|
| 92: |
|
| 93: | $this->load->model('design/theme');
|
| 94: |
|
| 95: | $this->model_design_theme->deleteThemesByStoreId($store_id);
|
| 96: |
|
| 97: | $this->load->model('design/translation');
|
| 98: |
|
| 99: | $this->model_design_translation->deleteTranslationsByStoreId($store_id);
|
| 100: |
|
| 101: | $this->load->model('design/seo_url');
|
| 102: |
|
| 103: | $this->model_design_seo_url->deleteSeoUrlsByStoreId($store_id);
|
| 104: |
|
| 105: | $this->load->model('setting/setting');
|
| 106: |
|
| 107: | $this->model_setting_setting->deleteSettingsByStoreId($store_id);
|
| 108: |
|
| 109: | $this->cache->delete('store');
|
| 110: | }
|
| 111: |
|
| 112: | |
| 113: | |
| 114: | |
| 115: | |
| 116: | |
| 117: | |
| 118: |
|
| 119: | public function getStore(int $store_id): array {
|
| 120: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "store` WHERE `store_id` = '" . (int)$store_id . "'");
|
| 121: |
|
| 122: | return $query->row;
|
| 123: | }
|
| 124: |
|
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: |
|
| 132: | public function getStores(array $data = []): array {
|
| 133: | $sql = "SELECT * FROM `" . DB_PREFIX . "store` ORDER BY `url`";
|
| 134: |
|
| 135: | $key = md5($sql);
|
| 136: |
|
| 137: | $store_data = $this->cache->get('store.' . $key);
|
| 138: |
|
| 139: | if (!$store_data) {
|
| 140: | $query = $this->db->query($sql);
|
| 141: |
|
| 142: | $store_data = $query->rows;
|
| 143: |
|
| 144: | $this->cache->set('store.' . $key, $store_data);
|
| 145: | }
|
| 146: |
|
| 147: | return $store_data;
|
| 148: | }
|
| 149: |
|
| 150: | |
| 151: | |
| 152: | |
| 153: | |
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: | |
| 159: | |
| 160: |
|
| 161: | public function createStoreInstance(int $store_id = 0, string $language = '', string $session_id = ''): \Opencart\System\Engine\Registry {
|
| 162: |
|
| 163: | $this->autoloader->register('Opencart\Catalog', DIR_CATALOG);
|
| 164: |
|
| 165: |
|
| 166: | $registry = new \Opencart\System\Engine\Registry();
|
| 167: | $registry->set('autoloader', $this->autoloader);
|
| 168: |
|
| 169: | $config = new \Opencart\System\Engine\Config();
|
| 170: | $registry->set('config', $config);
|
| 171: |
|
| 172: |
|
| 173: | $config->addPath(DIR_CONFIG);
|
| 174: | $config->load('default');
|
| 175: | $config->load('catalog');
|
| 176: | $config->set('application', 'Catalog');
|
| 177: |
|
| 178: |
|
| 179: | $config->set('config_store_id', $store_id);
|
| 180: |
|
| 181: |
|
| 182: | $registry->set('log', $this->log);
|
| 183: |
|
| 184: |
|
| 185: | $event = new \Opencart\System\Engine\Event($registry);
|
| 186: | $registry->set('event', $event);
|
| 187: |
|
| 188: |
|
| 189: | if ($config->has('action_event')) {
|
| 190: | foreach ($config->get('action_event') as $key => $value) {
|
| 191: | foreach ($value as $priority => $action) {
|
| 192: | $event->register($key, new \Opencart\System\Engine\Action($action), $priority);
|
| 193: | }
|
| 194: | }
|
| 195: | }
|
| 196: |
|
| 197: |
|
| 198: | $registry->set('factory', new \Opencart\System\Engine\Factory($registry));
|
| 199: |
|
| 200: |
|
| 201: | $loader = new \Opencart\System\Engine\Loader($registry);
|
| 202: | $registry->set('load', $loader);
|
| 203: |
|
| 204: |
|
| 205: | $request = new \stdClass();
|
| 206: | $request->get = [];
|
| 207: | $request->post = [];
|
| 208: | $request->server = $this->request->server;
|
| 209: | $request->cookie = [];
|
| 210: |
|
| 211: |
|
| 212: | $registry->set('request', $request);
|
| 213: |
|
| 214: |
|
| 215: | $response = new \Opencart\System\Library\Response();
|
| 216: | $registry->set('response', $response);
|
| 217: |
|
| 218: |
|
| 219: | $registry->set('db', $this->db);
|
| 220: |
|
| 221: |
|
| 222: | $registry->set('cache', $this->cache);
|
| 223: |
|
| 224: |
|
| 225: | $session = new \Opencart\System\Library\Session($config->get('session_engine'), $registry);
|
| 226: | $registry->set('session', $session);
|
| 227: |
|
| 228: |
|
| 229: | $session->start($session_id);
|
| 230: |
|
| 231: |
|
| 232: | $template = new \Opencart\System\Library\Template($config->get('template_engine'));
|
| 233: | $template->addPath(DIR_CATALOG . 'view/template/');
|
| 234: | $registry->set('template', $template);
|
| 235: |
|
| 236: |
|
| 237: | $request->get['language'] = $language;
|
| 238: |
|
| 239: |
|
| 240: | $language = new \Opencart\System\Library\Language($config->get('language_code'));
|
| 241: | $language->addPath(DIR_CATALOG . 'language/');
|
| 242: | $language->load('default');
|
| 243: | $registry->set('language', $language);
|
| 244: |
|
| 245: |
|
| 246: | $registry->set('url', new \Opencart\System\Library\Url($config->get('site_url')));
|
| 247: |
|
| 248: |
|
| 249: | $registry->set('document', new \Opencart\System\Library\Document());
|
| 250: |
|
| 251: |
|
| 252: | $pre_actions = [
|
| 253: | 'startup/setting',
|
| 254: | 'startup/language',
|
| 255: | 'startup/extension',
|
| 256: | 'startup/customer',
|
| 257: | 'startup/tax',
|
| 258: | 'startup/currency',
|
| 259: | 'startup/application',
|
| 260: | 'startup/startup',
|
| 261: | 'startup/event'
|
| 262: | ];
|
| 263: |
|
| 264: |
|
| 265: | foreach ($pre_actions as $pre_action) {
|
| 266: | $loader->controller($pre_action);
|
| 267: | }
|
| 268: |
|
| 269: | return $registry;
|
| 270: | }
|
| 271: |
|
| 272: | |
| 273: | |
| 274: | |
| 275: | |
| 276: |
|
| 277: | public function getTotalStores(): int {
|
| 278: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "store`");
|
| 279: |
|
| 280: | return (int)$query->row['total'];
|
| 281: | }
|
| 282: |
|
| 283: | |
| 284: | |
| 285: | |
| 286: | |
| 287: | |
| 288: | |
| 289: |
|
| 290: | public function getTotalStoresByLayoutId(int $layout_id): int {
|
| 291: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_layout_id' AND `value` = '" . (int)$layout_id . "' AND `store_id` != '0'");
|
| 292: |
|
| 293: | return (int)$query->row['total'];
|
| 294: | }
|
| 295: |
|
| 296: | |
| 297: | |
| 298: | |
| 299: | |
| 300: | |
| 301: | |
| 302: |
|
| 303: | public function getTotalStoresByLanguage(string $language): int {
|
| 304: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_language' AND `value` = '" . $this->db->escape($language) . "' AND `store_id` != '0'");
|
| 305: |
|
| 306: | return (int)$query->row['total'];
|
| 307: | }
|
| 308: |
|
| 309: | |
| 310: | |
| 311: | |
| 312: | |
| 313: | |
| 314: | |
| 315: |
|
| 316: | public function getTotalStoresByCurrency(string $currency): int {
|
| 317: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_currency' AND `value` = '" . $this->db->escape($currency) . "' AND `store_id` != '0'");
|
| 318: |
|
| 319: | return (int)$query->row['total'];
|
| 320: | }
|
| 321: |
|
| 322: | |
| 323: | |
| 324: | |
| 325: | |
| 326: | |
| 327: | |
| 328: |
|
| 329: | public function getTotalStoresByCountryId(int $country_id): int {
|
| 330: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_country_id' AND `value` = '" . (int)$country_id . "' AND `store_id` != '0'");
|
| 331: |
|
| 332: | return (int)$query->row['total'];
|
| 333: | }
|
| 334: |
|
| 335: | |
| 336: | |
| 337: | |
| 338: | |
| 339: | |
| 340: | |
| 341: |
|
| 342: | public function getTotalStoresByZoneId(int $zone_id): int {
|
| 343: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_zone_id' AND `value` = '" . (int)$zone_id . "' AND `store_id` != '0'");
|
| 344: |
|
| 345: | return (int)$query->row['total'];
|
| 346: | }
|
| 347: |
|
| 348: | |
| 349: | |
| 350: | |
| 351: | |
| 352: | |
| 353: | |
| 354: |
|
| 355: | public function getTotalStoresByCustomerGroupId(int $customer_group_id): int {
|
| 356: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_customer_group_id' AND `value` = '" . (int)$customer_group_id . "' AND `store_id` != '0'");
|
| 357: |
|
| 358: | return (int)$query->row['total'];
|
| 359: | }
|
| 360: |
|
| 361: | |
| 362: | |
| 363: | |
| 364: | |
| 365: | |
| 366: | |
| 367: |
|
| 368: | public function getTotalStoresByInformationId(int $information_id): int {
|
| 369: | $account_query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_account_id' AND `value` = '" . (int)$information_id . "' AND `store_id` != '0'");
|
| 370: |
|
| 371: | $checkout_query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_checkout_id' AND `value` = '" . (int)$information_id . "' AND `store_id` != '0'");
|
| 372: |
|
| 373: | return $account_query->row['total'] + $checkout_query->row['total'];
|
| 374: | }
|
| 375: |
|
| 376: | |
| 377: | |
| 378: | |
| 379: | |
| 380: | |
| 381: | |
| 382: |
|
| 383: | public function getTotalStoresByOrderStatusId(int $order_status_id): int {
|
| 384: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_order_status_id' AND `value` = '" . (int)$order_status_id . "' AND `store_id` != '0'");
|
| 385: |
|
| 386: | return (int)$query->row['total'];
|
| 387: | }
|
| 388: | }
|
| 389: | |