first commit
This commit is contained in:
70
catalog/model/setting/api.php
Normal file
70
catalog/model/setting/api.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Api
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Api extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $username
|
||||
* @param string $key
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function login(string $username, string $key): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api` a LEFT JOIN `" . DB_PREFIX . "api_ip` ai ON (a.`api_id` = ai.`api_id`) WHERE a.`username` = '" . $this->db->escape($username) . "' AND a.`key` = '" . $this->db->escape($key) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $token
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getApiByToken(string $token): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "api` a LEFT JOIN `" . DB_PREFIX . "api_session` `as` ON (a.`api_id` = `as`.`api_id`) LEFT JOIN `" . DB_PREFIX . "api_ip` ai ON (a.`api_id` = ai.`api_id`) WHERE a.`status` = '1' AND `as`.`session_id` = '" . $this->db->escape((string)$token) . "' AND ai.`ip` = '" . $this->db->escape((string)$this->request->server['REMOTE_ADDR']) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSessions(int $api_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, `date_modified`) < NOW() AND `api_id` = '" . (int)$api_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function deleteSessions(int $api_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, `date_modified`) < NOW() AND `api_id` = '" . (int)$api_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $api_session_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateSession(string $api_session_id): void {
|
||||
// keep the session alive
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "api_session` SET `date_modified` = NOW() WHERE `api_session_id` = '" . (int)$api_session_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function cleanSessions(): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, `date_modified`) < NOW()");
|
||||
}
|
||||
}
|
67
catalog/model/setting/cron.php
Normal file
67
catalog/model/setting/cron.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Cron
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Cron extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $cron_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCron(int $cron_id): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "cron` SET `date_modified` = NOW() WHERE `cron_id` = '" . (int)$cron_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cron_id
|
||||
* @param bool $status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editStatus(int $cron_id, bool $status): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "cron` SET `status` = '" . (bool)$status . "' WHERE `cron_id` = '" . (int)$cron_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cron_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCron(int $cron_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "cron` WHERE `cron_id` = '" . (int)$cron_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCronByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "cron` WHERE `code` = '" . $this->db->escape($code) . "' LIMIT 1");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCrons(): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "cron` ORDER BY `date_modified` DESC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCrons(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "cron`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
17
catalog/model/setting/event.php
Normal file
17
catalog/model/setting/event.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Event
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Event extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getEvents(): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "event` WHERE `status` = '1' ORDER BY `sort_order` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
}
|
40
catalog/model/setting/extension.php
Normal file
40
catalog/model/setting/extension.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Extension
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Extension extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensions(): array {
|
||||
$query = $this->db->query("SELECT DISTINCT `extension` FROM `" . DB_PREFIX . "extension`");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensionsByType(string $type): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension` WHERE `type` = '" . $this->db->escape($type) . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensionByCode(string $type, string $code): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension` WHERE `type` = '" . $this->db->escape($type) . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
}
|
23
catalog/model/setting/module.php
Normal file
23
catalog/model/setting/module.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Module
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Module extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $module_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModule(int $module_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'");
|
||||
|
||||
if ($query->row) {
|
||||
return json_decode($query->row['setting'], true);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
57
catalog/model/setting/setting.php
Normal file
57
catalog/model/setting/setting.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Setting
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Setting extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSettings(int $store_id = 0): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' OR `store_id` = 0 ORDER BY `store_id` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSetting(string $code, int $store_id = 0): array {
|
||||
$setting_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
if (!$result['serialized']) {
|
||||
$setting_data[$result['key']] = $result['value'];
|
||||
} else {
|
||||
$setting_data[$result['key']] = json_decode($result['value'], true);
|
||||
}
|
||||
}
|
||||
|
||||
return $setting_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue(string $key, int $store_id = 0): string {
|
||||
$query = $this->db->query("SELECT `value` FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' AND `key` = '" . $this->db->escape($key) . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return $query->row['value'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
17
catalog/model/setting/startup.php
Normal file
17
catalog/model/setting/startup.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class Startup
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Startup extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
function getStartups() {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "startup` WHERE `status` = '1' ORDER BY `sort_order` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
}
|
180
catalog/model/setting/store.php
Normal file
180
catalog/model/setting/store.php
Normal file
@ -0,0 +1,180 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Setting;
|
||||
/**
|
||||
* Class StoreStore
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Setting
|
||||
*/
|
||||
class Store extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStore(int $store_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "store` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStoreByHostname(string $url): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "store` WHERE REPLACE(`url`, 'www.', '') = '" . $this->db->escape($url) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getStores(): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "store` ORDER BY `url`";
|
||||
|
||||
$store_data = $this->cache->get('store.' . md5($sql));
|
||||
|
||||
if (!$store_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$store_data = $query->rows;
|
||||
|
||||
$this->cache->set('store.' . md5($sql), $store_data);
|
||||
}
|
||||
|
||||
return $store_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $store_id
|
||||
* @param string $language
|
||||
* @param string $session_id
|
||||
*
|
||||
* @return \Opencart\System\Engine\Registry
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createStoreInstance(int $store_id = 0, string $language = '', string $session_id = ''): object {
|
||||
// Autoloader
|
||||
$this->autoloader->register('Opencart\Catalog', DIR_CATALOG);
|
||||
|
||||
// Registry
|
||||
$registry = new \Opencart\System\Engine\Registry();
|
||||
$registry->set('autoloader', $this->autoloader);
|
||||
|
||||
// Config
|
||||
$config = new \Opencart\System\Engine\Config();
|
||||
$registry->set('config', $config);
|
||||
|
||||
// Load the default config
|
||||
$config->addPath(DIR_CONFIG);
|
||||
$config->load('default');
|
||||
$config->set('application', 'Catalog');
|
||||
|
||||
// Store
|
||||
$config->set('config_store_id', $store_id);
|
||||
|
||||
// Logging
|
||||
$registry->set('log', $this->log);
|
||||
|
||||
// Event
|
||||
$event = new \Opencart\System\Engine\Event($registry);
|
||||
$registry->set('event', $event);
|
||||
|
||||
// Event Register
|
||||
if ($config->has('action_event')) {
|
||||
foreach ($config->get('action_event') as $key => $value) {
|
||||
foreach ($value as $priority => $action) {
|
||||
$event->register($key, new \Opencart\System\Engine\Action($action), $priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loader
|
||||
$loader = new \Opencart\System\Engine\Loader($registry);
|
||||
$registry->set('load', $loader);
|
||||
|
||||
// Create a dummy request class so we can feed the data to the order editor
|
||||
$request = new \stdClass();
|
||||
$request->get = [];
|
||||
$request->post = [];
|
||||
$request->server = $this->request->server;
|
||||
$request->cookie = [];
|
||||
|
||||
// Request
|
||||
$registry->set('request', $request);
|
||||
|
||||
// Response
|
||||
$response = new \Opencart\System\Library\Response();
|
||||
$registry->set('response', $response);
|
||||
|
||||
// Database
|
||||
$registry->set('db', $this->db);
|
||||
|
||||
// Cache
|
||||
$registry->set('cache', $this->cache);
|
||||
|
||||
// Session
|
||||
$session = new \Opencart\System\Library\Session($config->get('session_engine'), $registry);
|
||||
$registry->set('session', $session);
|
||||
|
||||
// Start session
|
||||
$session->start($session_id);
|
||||
|
||||
// Template
|
||||
$template = new \Opencart\System\Library\Template($config->get('template_engine'));
|
||||
$template->addPath(DIR_TEMPLATE);
|
||||
$registry->set('template', $template);
|
||||
|
||||
// Language
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguageByCode($language);
|
||||
|
||||
if ($language_info) {
|
||||
$config->set('config_language_id', $language_info['language_id']);
|
||||
$config->set('config_language', $language_info['code']);
|
||||
} else {
|
||||
$config->set('config_language_id', $this->config->get('config_language_id'));
|
||||
$config->set('config_language', $this->config->get('config_language'));
|
||||
}
|
||||
|
||||
$language = new \Opencart\System\Library\Language($this->config->get('config_language'));
|
||||
$registry->set('language', $language);
|
||||
|
||||
if (!$language_info['extension']) {
|
||||
$language->addPath(DIR_LANGUAGE);
|
||||
} else {
|
||||
$language->addPath(DIR_EXTENSION . $language_info['extension'] . '/catalog/language/');
|
||||
}
|
||||
|
||||
// Load default language file
|
||||
$language->load('default');
|
||||
|
||||
// Url
|
||||
$registry->set('url', new \Opencart\System\Library\Url($config->get('site_url')));
|
||||
|
||||
// Document
|
||||
$registry->set('document', new \Opencart\System\Library\Document());
|
||||
|
||||
// Run pre actions to load key settings and classes.
|
||||
$pre_actions = [
|
||||
'startup/setting',
|
||||
'startup/extension',
|
||||
'startup/customer',
|
||||
'startup/tax',
|
||||
'startup/currency',
|
||||
'startup/application',
|
||||
'startup/startup',
|
||||
'startup/event'
|
||||
];
|
||||
|
||||
// Pre Actions
|
||||
foreach ($pre_actions as $pre_action) {
|
||||
$loader->controller($pre_action);
|
||||
}
|
||||
|
||||
return $registry;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user