first commit
This commit is contained in:
80
catalog/model/localisation/country.php
Normal file
80
catalog/model/localisation/country.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class Country
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class Country extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountry(int $country_id): array {
|
||||
$query = $this->db->query("SELECT *, `c`.`name` FROM `" . DB_PREFIX . "country` `c` LEFT JOIN `" . DB_PREFIX . "address_format` af ON (`c`.`address_format_id` = `af`.`address_format_id`) WHERE `c`.`country_id` = '" . (int)$country_id . "' AND `c`.`status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $iso_code_2
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountryByIsoCode2($iso_code_2): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "country` WHERE `iso_code_2` = '" . $this->db->escape($iso_code_2) . "' AND `status` = '1'";
|
||||
|
||||
$country_data = $this->cache->get('country.'. md5($sql));
|
||||
|
||||
if (!$country_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$country_data = $query->rows;
|
||||
|
||||
$this->cache->set('country.'. md5($sql), $country_data);
|
||||
}
|
||||
|
||||
return $country_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $iso_code_3
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountryByIsoCode3($iso_code_3): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "country` WHERE `iso_code_3` = '" . $this->db->escape($iso_code_3) . "' AND `status` = '1'";
|
||||
|
||||
$country_data = $this->cache->get('country.'. md5($sql));
|
||||
|
||||
if (!$country_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$country_data = $query->rows;
|
||||
|
||||
$this->cache->set('country.'. md5($sql), $country_data);
|
||||
}
|
||||
|
||||
return $country_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCountries(): array {
|
||||
$sql = "SELECT *, c.`name` FROM `" . DB_PREFIX . "country` c LEFT JOIN `" . DB_PREFIX . "address_format` `af` ON (c.`address_format_id` = af.`address_format_id`) WHERE `c`.`status` = '1' ORDER BY `c`.`name` ASC";
|
||||
|
||||
$country_data = $this->cache->get('country.'. md5($sql));
|
||||
|
||||
if (!$country_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$country_data = $query->rows;
|
||||
|
||||
$this->cache->set('country.'. md5($sql), $country_data);
|
||||
}
|
||||
|
||||
return $country_data;
|
||||
}
|
||||
}
|
75
catalog/model/localisation/currency.php
Normal file
75
catalog/model/localisation/currency.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class Currency
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class Currency extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editValueByCode(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "currency` SET `value` = '" . (float)$value . "', `date_modified` = NOW() WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
$this->cache->delete('currency');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $currency_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrency(int $currency_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "currency` WHERE `currency_id` = '" . $this->db->escape($currency_id) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrencyByCode(string $currency): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "currency` WHERE `code` = '" . $this->db->escape($currency) . "' AND `status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrencies(): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "currency` WHERE `status` = '1' ORDER BY `title` ASC";
|
||||
|
||||
$currency_data = $this->cache->get('currency.' . md5($sql));
|
||||
|
||||
if (!$currency_data) {
|
||||
$currency_data = [];
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$currency_data[$result['code']] = [
|
||||
'currency_id' => $result['currency_id'],
|
||||
'title' => $result['title'],
|
||||
'code' => $result['code'],
|
||||
'symbol_left' => $result['symbol_left'],
|
||||
'symbol_right' => $result['symbol_right'],
|
||||
'decimal_place' => $result['decimal_place'],
|
||||
'value' => $result['value'],
|
||||
'status' => $result['status'],
|
||||
'date_modified' => $result['date_modified']
|
||||
];
|
||||
}
|
||||
|
||||
$this->cache->set('currency.' . md5($sql), $currency_data);
|
||||
}
|
||||
|
||||
return $currency_data;
|
||||
}
|
||||
}
|
117
catalog/model/localisation/language.php
Normal file
117
catalog/model/localisation/language.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class Language
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class Language extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private array $data = [];
|
||||
|
||||
/**
|
||||
* @param int $language_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguage(int $language_id): array {
|
||||
if (isset($this->data[$language_id])) {
|
||||
return $this->data[$language_id];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$language = $query->row;
|
||||
|
||||
if ($language) {
|
||||
$language['image'] = HTTP_SERVER;
|
||||
|
||||
if (!$language['extension']) {
|
||||
$language['image'] .= 'catalog/';
|
||||
} else {
|
||||
$language['image'] .= 'extension/' . $language['extension'] . '/catalog/';
|
||||
}
|
||||
|
||||
$language['image'] .= 'language/' . $language['code'] . '/' . $language['code'] . '.png';
|
||||
}
|
||||
|
||||
$this->data[$language_id] = $language;
|
||||
|
||||
return $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageByCode(string $code): array {
|
||||
if (isset($this->data[$code])) {
|
||||
return $this->data[$code];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
$language = $query->row;
|
||||
|
||||
if ($language) {
|
||||
$language['image'] = HTTP_SERVER;
|
||||
|
||||
if (!$language['extension']) {
|
||||
$language['image'] .= 'catalog/';
|
||||
} else {
|
||||
$language['image'] .= 'extension/' . $language['extension'] . '/catalog/';
|
||||
}
|
||||
|
||||
$language['image'] .= 'language/' . $language['code'] . '/' . $language['code'] . '.png';
|
||||
}
|
||||
|
||||
$this->data[$code] = $language;
|
||||
|
||||
return $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguages(): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "language` WHERE `status` = '1' ORDER BY `sort_order`, `name`";
|
||||
|
||||
$results = (array)$this->cache->get('language.' . md5($sql));
|
||||
|
||||
if (!$results) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$results = $query->rows;
|
||||
|
||||
$this->cache->set('language.' . md5($sql), $results);
|
||||
}
|
||||
|
||||
$language_data = [];
|
||||
|
||||
foreach ($results as $result) {
|
||||
$image = HTTP_SERVER;
|
||||
|
||||
if (!$result['extension']) {
|
||||
$image .= 'catalog/';
|
||||
} else {
|
||||
$image .= 'extension/' . $result['extension'] . '/catalog/';
|
||||
}
|
||||
|
||||
$language_data[$result['code']] = [
|
||||
'language_id' => $result['language_id'],
|
||||
'name' => $result['name'],
|
||||
'code' => $result['code'],
|
||||
'image' => $image . 'language/' . $result['code'] . '/' . $result['code'] . '.png',
|
||||
'locale' => $result['locale'],
|
||||
'extension' => $result['extension'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'status' => $result['status']
|
||||
];
|
||||
}
|
||||
|
||||
return $language_data;
|
||||
}
|
||||
}
|
19
catalog/model/localisation/location.php
Normal file
19
catalog/model/localisation/location.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class Location
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class Location extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $location_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocation(int $location_id): array {
|
||||
$query = $this->db->query("SELECT `location_id`, `name`, `address`, `geocode`, `telephone`, `image`, `open`, `comment` FROM `" . DB_PREFIX . "location` WHERE `location_id` = '" . (int)$location_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
}
|
38
catalog/model/localisation/order_status.php
Normal file
38
catalog/model/localisation/order_status.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class OrderStatus
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class OrderStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderStatus(int $order_status_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderStatuses(): array {
|
||||
$sql = "SELECT `order_status_id`, `name` FROM `" . DB_PREFIX . "order_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `name`";
|
||||
|
||||
$order_status_data = $this->cache->get('order_status.' . md5($sql));
|
||||
|
||||
if (!$order_status_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$order_status_data = $query->rows;
|
||||
|
||||
$this->cache->set('order_status.' . md5($sql), $order_status_data);
|
||||
}
|
||||
|
||||
return $order_status_data;
|
||||
}
|
||||
}
|
47
catalog/model/localisation/return_reason.php
Normal file
47
catalog/model/localisation/return_reason.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class ReturnReason
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class ReturnReason extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnReasons(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "return_reason` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `name`";
|
||||
|
||||
if (isset($data['return']) && ($data['return'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$return_reason_data = $this->cache->get('return_reason.' . md5($sql));
|
||||
|
||||
if (!$return_reason_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$return_reason_data = $query->rows;
|
||||
|
||||
$this->cache->set('return_reason.' . md5($sql), $return_reason_data);
|
||||
}
|
||||
|
||||
return $return_reason_data;
|
||||
}
|
||||
}
|
58
catalog/model/localisation/stock_status.php
Normal file
58
catalog/model/localisation/stock_status.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class StockStatus
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class StockStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $stock_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStockStatus(int $stock_status_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "stock_status` WHERE `stock_status_id` = '" . (int)$stock_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStockStatuses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "stock_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `name`";
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$stock_status_data = $this->cache->get('stock_status.'. md5($sql));
|
||||
|
||||
if (!$stock_status_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$stock_status_data = $query->rows;
|
||||
|
||||
$this->cache->set('stock_status.'. md5($sql), $stock_status_data);
|
||||
}
|
||||
|
||||
return $stock_status_data;
|
||||
}
|
||||
}
|
38
catalog/model/localisation/subscription_status.php
Normal file
38
catalog/model/localisation/subscription_status.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class SubscriptionStatus
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class SubscriptionStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $subscription_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionStatus(int $subscription_status_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_status` WHERE `subscription_status_id` = '" . (int)$subscription_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionStatuses(): array {
|
||||
$sql = "SELECT `subscription_status_id`, `name` FROM `" . DB_PREFIX . "subscription_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `name`";
|
||||
|
||||
$subscription_status_data = $this->cache->get('subscription_status.'. md5($sql));
|
||||
|
||||
if (!$subscription_status_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$subscription_status_data = $query->rows;
|
||||
|
||||
$this->cache->set('subscription_status.'. md5($sql), $subscription_status_data);
|
||||
}
|
||||
|
||||
return $subscription_status_data;
|
||||
}
|
||||
}
|
40
catalog/model/localisation/zone.php
Normal file
40
catalog/model/localisation/zone.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Model\Localisation;
|
||||
/**
|
||||
* Class Zone
|
||||
*
|
||||
* @package Opencart\Catalog\Model\Localisation
|
||||
*/
|
||||
class Zone extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $zone_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZone(int $zone_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$zone_id . "' AND `status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZonesByCountryId(int $country_id): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "zone` WHERE `country_id` = '" . (int)$country_id . "' AND `status` = '1' ORDER BY `name`";
|
||||
|
||||
$zone_data = $this->cache->get('zone.' . md5($sql));
|
||||
|
||||
if (!$zone_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$zone_data = $query->rows;
|
||||
|
||||
$this->cache->set('zone.' . md5($sql), $zone_data);
|
||||
}
|
||||
|
||||
return $zone_data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user