Back to Opencart

File catalog\model\setting\store.php

docs/api/source-catalog.model.setting.store.html

4.1.0.310.6 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Catalog\Model\Setting; | | 3: | /** | | 4: | * Class StoreStore | | 5: | * | | 6: | * @package Opencart\Catalog\Model\Setting | | 7: | */ | | 8: | class Store extends \Opencart\System\Engine\Model { | | 9: | /** | | 10: | * Get Store | | 11: | * | | 12: | * @param int $store_id | | 13: | * | | 14: | * @return array<string, mixed> | | 15: | */ | | 16: | public function getStore(int $store_id): array { | | 17: | $query = $this->db->query("SELECT DISTINCT * FROM " . DB\_PREFIX . "store WHERE store\_id = '" . (int)$store_id . "'"); | | 18: | | | 19: | return $query->row; | | 20: | } | | 21: | | | 22: | /** | | 23: | * Get Store By Hostname | | 24: | * | | 25: | * @param string $url | | 26: | * | | 27: | * @return array<string, mixed> | | 28: | */ | | 29: | public function getStoreByHostname(string $url): array { | | 30: | $query = $this->db->query("SELECT * FROM " . DB\_PREFIX . "store WHERE REPLACE(url, 'www.', '') = '" . $this->db->escape($url) . "'"); | | 31: | | | 32: | return $query->row; | | 33: | } | | 34: | | | 35: | /** | | 36: | * Get Stores | | 37: | * | | 38: | * @return array<int, array<string, mixed>> | | 39: | */ | | 40: | public function getStores(): array { | | 41: | $sql = "SELECT * FROM " . DB\_PREFIX . "store ORDER BY url"; | | 42: | | | 43: | $key = md5($sql); | | 44: | | | 45: | $store_data = $this->cache->get('store.' . $key); | | 46: | | | 47: | if (!$store_data) { | | 48: | $query = $this->db->query($sql); | | 49: | | | 50: | $store_data = $query->rows; | | 51: | | | 52: | $this->cache->set('store.' . $key, $store_data); | | 53: | } | | 54: | | | 55: | return $store_data; | | 56: | } | | 57: | | | 58: | /** | | 59: | * Create Store Instance | | 60: | * | | 61: | * @param int $store_id | | 62: | * @param string $language | | 63: | * @param string $session_id | | 64: | * | | 65: | * @throws \Exception | | 66: | * | | 67: | * @return \Opencart\System\Engine\Registry | | 68: | */ | | 69: | public function createStoreInstance(int $store_id = 0, string $language = '', string $session_id = ''): \Opencart\System\Engine\Registry { | | 70: | // Autoloader | | 71: | $this->autoloader->register('Opencart\Catalog', DIR_CATALOG); | | 72: | | | 73: | // Registry | | 74: | $registry = new \Opencart\System\Engine\Registry(); | | 75: | $registry->set('autoloader', $this->autoloader); | | 76: | | | 77: | // Config | | 78: | $config = new \Opencart\System\Engine\Config(); | | 79: | $registry->set('config', $config); | | 80: | | | 81: | // Load the default config | | 82: | $config->addPath(DIR_CONFIG); | | 83: | $config->load('default'); | | 84: | $config->set('application', 'Catalog'); | | 85: | | | 86: | // Store | | 87: | $config->set('config_store_id', $store_id); | | 88: | | | 89: | // Logging | | 90: | $registry->set('log', $this->log); | | 91: | | | 92: | // Event | | 93: | $event = new \Opencart\System\Engine\Event($registry); | | 94: | $registry->set('event', $event); | | 95: | | | 96: | // Event Register | | 97: | if ($config->has('action_event')) { | | 98: | foreach ($config->get('action_event') as $key => $value) { | | 99: | foreach ($value as $priority => $action) { | | 100: | $event->register($key, new \Opencart\System\Engine\Action($action), $priority); | | 101: | } | | 102: | } | | 103: | } | | 104: | | | 105: | // Loader | | 106: | $loader = new \Opencart\System\Engine\Loader($registry); | | 107: | $registry->set('load', $loader); | | 108: | | | 109: | // Create a dummy request class so we can feed the data to the order editor | | 110: | $request = new \stdClass(); | | 111: | $request->get = []; | | 112: | $request->post = []; | | 113: | $request->server = $this->request->server; | | 114: | $request->cookie = []; | | 115: | | | 116: | // Request | | 117: | $registry->set('request', $request); | | 118: | | | 119: | // Response | | 120: | $response = new \Opencart\System\Library\Response(); | | 121: | $registry->set('response', $response); | | 122: | | | 123: | // Database | | 124: | $registry->set('db', $this->db); | | 125: | | | 126: | // Cache | | 127: | $registry->set('cache', $this->cache); | | 128: | | | 129: | // Session | | 130: | $session = new \Opencart\System\Library\Session($config->get('session_engine'), $registry); | | 131: | $registry->set('session', $session); | | 132: | | | 133: | // Start session | | 134: | $session->start($session_id); | | 135: | | | 136: | // Template | | 137: | $template = new \Opencart\System\Library\Template($config->get('template_engine')); | | 138: | $template->addPath(DIR_TEMPLATE); | | 139: | $registry->set('template', $template); | | 140: | | | 141: | // Language | | 142: | $this->load->model('localisation/language'); | | 143: | | | 144: | $language_info = $this->model_localisation_language->getLanguageByCode($language); | | 145: | | | 146: | if ($language_info) { | | 147: | $config->set('config_language_id', $language_info['language_id']); | | 148: | $config->set('config_language', $language_info['code']); | | 149: | } else { | | 150: | $config->set('config_language_id', $this->config->get('config_language_id')); | | 151: | $config->set('config_language', $this->config->get('config_language')); | | 152: | } | | 153: | | | 154: | $language = new \Opencart\System\Library\Language($this->config->get('config_language')); | | 155: | $registry->set('language', $language); | | 156: | | | 157: | if (!$language_info['extension']) { | | 158: | $language->addPath(DIR_LANGUAGE); | | 159: | } else { | | 160: | $language->addPath(DIR_EXTENSION . $language_info['extension'] . '/catalog/language/'); | | 161: | } | | 162: | | | 163: | // Load default language file | | 164: | $language->load('default'); | | 165: | | | 166: | // Url | | 167: | $registry->set('url', new \Opencart\System\Library\Url($config->get('site_url'))); | | 168: | | | 169: | // Document | | 170: | $registry->set('document', new \Opencart\System\Library\Document()); | | 171: | | | 172: | // Run pre actions to load key settings and classes. | | 173: | $pre_actions = [ | | 174: | 'startup/setting', | | 175: | 'startup/extension', | | 176: | 'startup/customer', | | 177: | 'startup/tax', | | 178: | 'startup/currency', | | 179: | 'startup/application', | | 180: | 'startup/startup', | | 181: | 'startup/event' | | 182: | ]; | | 183: | | | 184: | // Pre Actions | | 185: | foreach ($pre_actions as $pre_action) { | | 186: | $loader->controller($pre_action); | | 187: | } | | 188: | | | 189: | return $registry; | | 190: | } | | 191: | } | | 192: | |

OpenCart API API documentation generated by ApiGen dev-master