first commit
This commit is contained in:
85
admininistrator/model/localisation/address_format.php
Normal file
85
admininistrator/model/localisation/address_format.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Address Format
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class AddressFormat extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addAddressFormat(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "address_format` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `address_format` = '" . $this->db->escape((string)$data['address_format']) . "'");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $address_format_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editAddressFormat(int $address_format_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "address_format` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `address_format` = '" . $this->db->escape((string)$data['address_format']) . "' WHERE `address_format_id` = '" . (int)$address_format_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $address_format_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAddressFormat(int $address_format_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "address_format` WHERE `address_format_id` = '" . (int)$address_format_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $address_format_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressFormat(int $address_format_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "address_format` WHERE `address_format_id` = '" . (int)$address_format_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressFormats(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "address_format`";
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAddressFormats(array $data = []): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "address_format`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
188
admininistrator/model/localisation/country.php
Normal file
188
admininistrator/model/localisation/country.php
Normal file
@ -0,0 +1,188 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Country
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class Country extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addCountry(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "country` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `iso_code_2` = '" . $this->db->escape((string)$data['iso_code_2']) . "', `iso_code_3` = '" . $this->db->escape((string)$data['iso_code_3']) . "', `address_format_id` = '" . (int)$data['address_format_id'] . "', `postcode_required` = '" . (int)$data['postcode_required'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "'");
|
||||
|
||||
$this->cache->delete('country');
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCountry(int $country_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "country` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `iso_code_2` = '" . $this->db->escape((string)$data['iso_code_2']) . "', `iso_code_3` = '" . $this->db->escape((string)$data['iso_code_3']) . "', `address_format_id` = '" . (int)$data['address_format_id'] . "', `postcode_required` = '" . (int)$data['postcode_required'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `country_id` = '" . (int)$country_id . "'");
|
||||
|
||||
$this->cache->delete('country');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCountry(int $country_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "country` WHERE `country_id` = '" . (int)$country_id . "'");
|
||||
|
||||
$this->cache->delete('country');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountry(int $country_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "country` WHERE `country_id` = '" . (int)$country_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $iso_code_2
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountryByIsoCode2($iso_code_2): array {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "country WHERE `iso_code_2` = '" . $this->db->escape($iso_code_2) . "' AND `status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $iso_code_3
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountryByIsoCode3($iso_code_3): array {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "country WHERE `iso_code_3` = '" . $this->db->escape($iso_code_3) . "' AND `status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountries(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "country`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_iso_code_2'])) {
|
||||
$implode[] = "`iso_code_2` LIKE '" . $this->db->escape((string)$data['filter_iso_code_2'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_iso_code_3'])) {
|
||||
$implode[] = "`iso_code_3` LIKE '" . $this->db->escape((string)$data['filter_iso_code_3'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'iso_code_2',
|
||||
'iso_code_3'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " 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'];
|
||||
}
|
||||
|
||||
$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 array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCountries(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "country`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_iso_code_2'])) {
|
||||
$implode[] = "`iso_code_2` LIKE '" . $this->db->escape((string)$data['filter_iso_code_2'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_iso_code_3'])) {
|
||||
$implode[] = "`iso_code_3` LIKE '" . $this->db->escape((string)$data['filter_iso_code_3'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $address_format_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCountriesByAddressFormatId(int $address_format_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "country` WHERE `address_format_id` = '" . (int)$address_format_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
155
admininistrator/model/localisation/currency.php
Normal file
155
admininistrator/model/localisation/currency.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Currency
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class Currency extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addCurrency(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "currency` SET `title` = '" . $this->db->escape((string)$data['title']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `symbol_left` = '" . $this->db->escape((string)$data['symbol_left']) . "', `symbol_right` = '" . $this->db->escape((string)$data['symbol_right']) . "', `decimal_place` = '" . (int)$data['decimal_place'] . "', `value` = '" . (float)$data['value'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_modified` = NOW()");
|
||||
|
||||
$this->cache->delete('currency');
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $currency_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCurrency(int $currency_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "currency` SET `title` = '" . $this->db->escape((string)$data['title']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `symbol_left` = '" . $this->db->escape((string)$data['symbol_left']) . "', `symbol_right` = '" . $this->db->escape((string)$data['symbol_right']) . "', `decimal_place` = '" . (int)$data['decimal_place'] . "', `value` = '" . (float)$data['value'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_modified` = NOW() WHERE `currency_id` = '" . (int)$currency_id . "'");
|
||||
|
||||
$this->cache->delete('currency');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 void
|
||||
*/
|
||||
public function deleteCurrency(int $currency_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "currency` WHERE `currency_id` = '" . (int)$currency_id . "'");
|
||||
|
||||
$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` = '" . (int)$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) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrencies(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "currency`";
|
||||
|
||||
$sort_data = [
|
||||
'title',
|
||||
'code',
|
||||
'value',
|
||||
'date_modified'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `title`";
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$results = (array)$this->cache->get('currency.' . md5($sql));
|
||||
|
||||
if (!$results) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$results = $query->rows;
|
||||
|
||||
$this->cache->set('currency.' . md5($sql), $results);
|
||||
}
|
||||
|
||||
$currency_data = [];
|
||||
|
||||
foreach ($results 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']
|
||||
];
|
||||
}
|
||||
|
||||
return $currency_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCurrencies(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "currency`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
179
admininistrator/model/localisation/geo_zone.php
Normal file
179
admininistrator/model/localisation/geo_zone.php
Normal file
@ -0,0 +1,179 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class GeoZone
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class GeoZone extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addGeoZone(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "geo_zone` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `description` = '" . $this->db->escape((string)$data['description']) . "', `date_added` = NOW()");
|
||||
|
||||
$geo_zone_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['zone_to_geo_zone'])) {
|
||||
foreach ($data['zone_to_geo_zone'] as $value) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "' AND `country_id` = '" . (int)$value['country_id'] . "' AND `zone_id` = '" . (int)$value['zone_id'] . "'");
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "zone_to_geo_zone` SET `country_id` = '" . (int)$value['country_id'] . "', `zone_id` = '" . (int)$value['zone_id'] . "', `geo_zone_id` = '" . (int)$geo_zone_id . "', `date_added` = NOW()");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('geo_zone');
|
||||
|
||||
return $geo_zone_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editGeoZone(int $geo_zone_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "geo_zone` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `description` = '" . $this->db->escape((string)$data['description']) . "', `date_modified` = NOW() WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
if (isset($data['zone_to_geo_zone'])) {
|
||||
foreach ($data['zone_to_geo_zone'] as $value) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "' AND `country_id` = '" . (int)$value['country_id'] . "' AND `zone_id` = '" . (int)$value['zone_id'] . "'");
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "zone_to_geo_zone` SET `country_id` = '" . (int)$value['country_id'] . "', `zone_id` = '" . (int)$value['zone_id'] . "', `geo_zone_id` = '" . (int)$geo_zone_id . "', `date_added` = NOW()");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('geo_zone');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteGeoZone(int $geo_zone_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
$this->cache->delete('geo_zone');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGeoZone(int $geo_zone_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGeoZones(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "geo_zone`";
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'description'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " 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'];
|
||||
}
|
||||
|
||||
$geo_zone_data = $this->cache->get('geo_zone.' . md5($sql));
|
||||
|
||||
if (!$geo_zone_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$geo_zone_data = $query->rows;
|
||||
|
||||
$this->cache->set('geo_zone.' . md5($sql), $geo_zone_data);
|
||||
}
|
||||
|
||||
return $geo_zone_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalGeoZones(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "geo_zone`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZoneToGeoZones(int $geo_zone_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalZoneToGeoZoneByGeoZoneId(int $geo_zone_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalZoneToGeoZoneByCountryId(int $country_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `country_id` = '" . (int)$country_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $zone_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalZoneToGeoZoneByZoneId(int $zone_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `zone_id` = '" . (int)$zone_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
428
admininistrator/model/localisation/language.php
Normal file
428
admininistrator/model/localisation/language.php
Normal file
@ -0,0 +1,428 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Language
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class Language extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addLanguage(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "language` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `locale` = '" . $this->db->escape((string)$data['locale']) . "', `extension` = '" . $this->db->escape((string)$data['extension']) . "', `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "'");
|
||||
|
||||
$this->cache->delete('language');
|
||||
|
||||
$language_id = $this->db->getLastId();
|
||||
|
||||
// Attribute
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "attribute_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $attribute) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute_description` SET `attribute_id` = '" . (int)$attribute['attribute_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($attribute['name']) . "'");
|
||||
}
|
||||
|
||||
// Attribute Group
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "attribute_group_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $attribute_group) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute_group_description` SET `attribute_group_id` = '" . (int)$attribute_group['attribute_group_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($attribute_group['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('attribute');
|
||||
|
||||
// Banner
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "banner_image` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $banner_image) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "banner_image` SET `banner_id` = '" . (int)$banner_image['banner_id'] . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($banner_image['title']) . "', `link` = '" . $this->db->escape($banner_image['link']) . "', `image` = '" . $this->db->escape($banner_image['image']) . "', `sort_order` = '" . (int)$banner_image['sort_order'] . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('banner');
|
||||
|
||||
// Category
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $category) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_description` SET `category_id` = '" . (int)$category['category_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($category['name']) . "', `description` = '" . $this->db->escape($category['description']) . "', `meta_title` = '" . $this->db->escape($category['meta_title']) . "', `meta_description` = '" . $this->db->escape($category['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($category['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
// Customer Group
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_group_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $customer_group) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_group_description` SET `customer_group_id` = '" . (int)$customer_group['customer_group_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($customer_group['name']) . "', `description` = '" . $this->db->escape($customer_group['description']) . "'");
|
||||
}
|
||||
|
||||
// Custom Field
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $custom_field) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_description` SET `custom_field_id` = '" . (int)$custom_field['custom_field_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($custom_field['name']) . "'");
|
||||
}
|
||||
|
||||
// Custom Field Value
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $custom_field_value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value_description` SET `custom_field_value_id` = '" . (int)$custom_field_value['custom_field_value_id'] . "', `language_id` = '" . (int)$language_id . "', `custom_field_id` = '" . (int)$custom_field_value['custom_field_id'] . "', `name` = '" . $this->db->escape($custom_field_value['name']) . "'");
|
||||
}
|
||||
|
||||
// Download
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "download_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $download) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "download_description` SET `download_id` = '" . (int)$download['download_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($download['name']) . "'");
|
||||
}
|
||||
|
||||
// Filter
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "filter_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $filter) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter_description` SET `filter_id` = '" . (int)$filter['filter_id'] . "', `language_id` = '" . (int)$language_id . "', `filter_group_id` = '" . (int)$filter['filter_group_id'] . "', `name` = '" . $this->db->escape($filter['name']) . "'");
|
||||
}
|
||||
|
||||
// Filter Group
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "filter_group_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $filter_group) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter_group_description` SET `filter_group_id` = '" . (int)$filter_group['filter_group_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($filter_group['name']) . "'");
|
||||
}
|
||||
|
||||
// Information
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "information_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $information) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "information_description` SET `information_id` = '" . (int)$information['information_id'] . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($information['title']) . "', `description` = '" . $this->db->escape($information['description']) . "', `meta_title` = '" . $this->db->escape($information['meta_title']) . "', `meta_description` = '" . $this->db->escape($information['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($information['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('information');
|
||||
|
||||
// Length
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "length_class_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $length) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "length_class_description` SET `length_class_id` = '" . (int)$length['length_class_id'] . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($length['title']) . "', `unit` = '" . $this->db->escape($length['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('length_class');
|
||||
|
||||
// Option
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $option) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option_description` SET `option_id` = '" . (int)$option['option_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($option['name']) . "'");
|
||||
}
|
||||
|
||||
// Option Value
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_value_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $option_value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option_value_description` SET `option_value_id` = '" . (int)$option_value['option_value_id'] . "', `language_id` = '" . (int)$language_id . "', `option_id` = '" . (int)$option_value['option_id'] . "', `name` = '" . $this->db->escape($option_value['name']) . "'");
|
||||
}
|
||||
|
||||
// Order Status
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $order_status) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_status` SET `order_status_id` = '" . (int)$order_status['order_status_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($order_status['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('order_status');
|
||||
|
||||
// Product
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $product) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_description` SET `product_id` = '" . (int)$product['product_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($product['name']) . "', `description` = '" . $this->db->escape($product['description']) . "', `tag` = '" . $this->db->escape($product['tag']) . "', `meta_title` = '" . $this->db->escape($product['meta_title']) . "', `meta_description` = '" . $this->db->escape($product['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($product['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('product');
|
||||
|
||||
// Product Attribute
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_attribute` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $product_attribute) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_attribute` SET `product_id` = '" . (int)$product_attribute['product_id'] . "', `attribute_id` = '" . (int)$product_attribute['attribute_id'] . "', `language_id` = '" . (int)$language_id . "', `text` = '" . $this->db->escape($product_attribute['text']) . "'");
|
||||
}
|
||||
|
||||
// Return Action
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_action` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $return_action) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_action` SET `return_action_id` = '" . (int)$return_action['return_action_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($return_action['name']) . "'");
|
||||
}
|
||||
|
||||
// Return Reason
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_reason` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $return_reason) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_reason` SET `return_reason_id` = '" . (int)$return_reason['return_reason_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($return_reason['name']) . "'");
|
||||
}
|
||||
|
||||
// Return Status
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $return_status) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_status` SET `return_status_id` = '" . (int)$return_status['return_status_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($return_status['name']) . "'");
|
||||
}
|
||||
|
||||
// Stock Status
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "stock_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $stock_status) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "stock_status` SET `stock_status_id` = '" . (int)$stock_status['stock_status_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($stock_status['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('stock_status');
|
||||
|
||||
// Voucher Theme
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "voucher_theme_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $voucher_theme) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "voucher_theme_description` SET `voucher_theme_id` = '" . (int)$voucher_theme['voucher_theme_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($voucher_theme['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('voucher_theme');
|
||||
|
||||
// Weight Class
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "weight_class_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $weight_class) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "weight_class_description` SET `weight_class_id` = '" . (int)$weight_class['weight_class_id'] . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($weight_class['title']) . "', `unit` = '" . $this->db->escape($weight_class['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('weight_class');
|
||||
|
||||
// Subscription
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $subscription) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_status` SET `subscription_status_id` = '" . (int)$subscription['subscription_status_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($subscription['name']) . "'");
|
||||
}
|
||||
|
||||
// SEO URL
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $seo_url) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$seo_url['store_id'] . "', `language_id` = '" . (int)$language_id . "', `key` = '" . $this->db->escape($seo_url['key']) . "', `value` = '" . $this->db->escape($seo_url['value']) . "', `keyword` = '" . $this->db->escape($seo_url['keyword']) . "', `sort_order` = '" . (int)$seo_url['sort_order'] . "'");
|
||||
}
|
||||
|
||||
return $language_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $language_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editLanguage(int $language_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "language` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `locale` = '" . $this->db->escape((string)$data['locale']) . "', `extension` = '" . $this->db->escape((string)$data['extension']) . "', `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('language');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $language_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteLanguage(int $language_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "language` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('language');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute_group_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('attribute');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "banner_image` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('banner');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_group_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_value_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "download_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "filter_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "filter_group_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('information');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "length_class_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('length_class');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "option_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "option_value_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_status` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('order_status');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('product');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_attribute` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_action` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_reason` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_status` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "stock_status` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('stock_status');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "voucher_theme_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('voucher_theme');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "weight_class_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('weight_class');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "subscription_status` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('subscription_status');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $language_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguage(int $language_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "language` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$language = $query->row;
|
||||
|
||||
if ($language) {
|
||||
$language['image'] = HTTP_CATALOG;
|
||||
|
||||
if (!$language['extension']) {
|
||||
$language['image'] .= 'catalog/';
|
||||
} else {
|
||||
$language['image'] .= 'extension/' . $language['extension'] . '/catalog/';
|
||||
}
|
||||
|
||||
$language['image'] .= 'language/' . $language['code'] . '/' . $language['code'] . '.png';
|
||||
}
|
||||
|
||||
return $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
$language = $query->row;
|
||||
|
||||
if ($language) {
|
||||
$language['image'] = HTTP_CATALOG;
|
||||
|
||||
if (!$language['extension']) {
|
||||
$language['image'] .= 'catalog/';
|
||||
} else {
|
||||
$language['image'] .= 'extension/' . $language['extension'] . '/catalog/';
|
||||
}
|
||||
|
||||
$language['image'] .= 'language/' . $language['code'] . '/' . $language['code'] . '.png';
|
||||
}
|
||||
|
||||
return $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguages(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "language`";
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'code',
|
||||
'sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `sort_order`, `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'];
|
||||
}
|
||||
|
||||
$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_CATALOG;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalLanguages(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "language`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
159
admininistrator/model/localisation/length_class.php
Normal file
159
admininistrator/model/localisation/length_class.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Length Class
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class LengthClass extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addLengthClass(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "length_class` SET `value` = '" . (float)$data['value'] . "'");
|
||||
|
||||
$length_class_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['length_class_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "length_class_description` SET `length_class_id` = '" . (int)$length_class_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($value['title']) . "', `unit` = '" . $this->db->escape($value['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('length_class');
|
||||
|
||||
return $length_class_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $length_class_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editLengthClass(int $length_class_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "length_class` SET `value` = '" . (float)$data['value'] . "' WHERE `length_class_id` = '" . (int)$length_class_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "length_class_description` WHERE `length_class_id` = '" . (int)$length_class_id . "'");
|
||||
|
||||
foreach ($data['length_class_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "length_class_description` SET `length_class_id` = '" . (int)$length_class_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($value['title']) . "', `unit` = '" . $this->db->escape($value['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('length_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $length_class_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteLengthClass(int $length_class_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "length_class` WHERE `length_class_id` = '" . (int)$length_class_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "length_class_description` WHERE `length_class_id` = '" . (int)$length_class_id . "'");
|
||||
|
||||
$this->cache->delete('length_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLengthClasses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "length_class` lc LEFT JOIN `" . DB_PREFIX . "length_class_description` lcd ON (lc.`length_class_id` = lcd.`length_class_id`) WHERE lcd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$sort_data = [
|
||||
'title',
|
||||
'unit',
|
||||
'value'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `title`";
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$length_class_data = $this->cache->get('length_class.' . md5($sql));
|
||||
|
||||
if (!$length_class_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$length_class_data = $query->rows;
|
||||
|
||||
$this->cache->set('length_class.' . md5($sql), $length_class_data);
|
||||
}
|
||||
|
||||
return $length_class_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $length_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLengthClass(int $length_class_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "length_class` lc LEFT JOIN `" . DB_PREFIX . "length_class_description` lcd ON (lc.`length_class_id` = lcd.`length_class_id`) WHERE lc.`length_class_id` = '" . (int)$length_class_id . "' AND lcd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptionByUnit(string $unit): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "length_class_description` WHERE `unit` = '" . $this->db->escape($unit) . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $length_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $length_class_id): array {
|
||||
$length_class_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "length_class_description` WHERE `length_class_id` = '" . (int)$length_class_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$length_class_data[$result['language_id']] = [
|
||||
'title' => $result['title'],
|
||||
'unit' => $result['unit']
|
||||
];
|
||||
}
|
||||
|
||||
return $length_class_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalLengthClasses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "length_class`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
100
admininistrator/model/localisation/location.php
Normal file
100
admininistrator/model/localisation/location.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Location
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class Location extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addLocation(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "location` SET `name` = '" . $this->db->escape((string)$data['name']) . "', address = '" . $this->db->escape((string)$data['address']) . "', `geocode` = '" . $this->db->escape((string)$data['geocode']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `image` = '" . $this->db->escape((string)$data['image']) . "', `open` = '" . $this->db->escape((string)$data['open']) . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "'");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $location_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editLocation(int $location_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "location` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `address` = '" . $this->db->escape((string)$data['address']) . "', `geocode` = '" . $this->db->escape((string)$data['geocode']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `image` = '" . $this->db->escape((string)$data['image']) . "', `open` = '" . $this->db->escape((string)$data['open']) . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "' WHERE `location_id` = '" . (int)$location_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $location_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteLocation(int $location_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "location` WHERE `location_id` = '" . (int)$location_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $location_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocation(int $location_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "location` WHERE `location_id` = '" . (int)$location_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocations(array $data = []): array {
|
||||
$sql = "SELECT `location_id`, `name`, `address` FROM `" . DB_PREFIX . "location`";
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'address',
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " 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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalLocations(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "location`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/order_status.php
Normal file
132
admininistrator/model/localisation/order_status.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class OrderStatus
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class OrderStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addOrderStatus(array $data): int {
|
||||
foreach ($data['order_status'] as $language_id => $value) {
|
||||
if (isset($order_status_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_status` SET `order_status_id` = '" . (int)$order_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_status` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$order_status_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('order_status');
|
||||
|
||||
return $order_status_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editOrderStatus(int $order_status_id, array $data): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "'");
|
||||
|
||||
foreach ($data['order_status'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_status` SET `order_status_id` = '" . (int)$order_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('order_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteOrderStatus(int $order_status_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "'");
|
||||
|
||||
$this->cache->delete('order_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderStatuses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "order_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'];
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $order_status_id): array {
|
||||
$order_status_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$order_status_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $order_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOrderStatuses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/return_action.php
Normal file
132
admininistrator/model/localisation/return_action.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class ReturnAction
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class ReturnAction extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addReturnAction(array $data): int {
|
||||
foreach ($data['return_action'] as $language_id => $value) {
|
||||
if (isset($return_action_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_action` SET `return_action_id` = '" . (int)$return_action_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_action` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$return_action_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('return_action');
|
||||
|
||||
return $return_action_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_action_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editReturnAction(int $return_action_id, array $data): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_action` WHERE `return_action_id` = '" . (int)$return_action_id . "'");
|
||||
|
||||
foreach ($data['return_action'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_action` SET `return_action_id` = '" . (int)$return_action_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('return_action');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_action_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReturnAction(int $return_action_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_action` WHERE `return_action_id` = '" . (int)$return_action_id . "'");
|
||||
|
||||
$this->cache->delete('return_action');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_action_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnAction(int $return_action_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_action` WHERE `return_action_id` = '" . (int)$return_action_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnActions(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "return_action` 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'];
|
||||
}
|
||||
|
||||
$return_action_data = $this->cache->get('return_action.' . md5($sql));
|
||||
|
||||
if (!$return_action_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$return_action_data = $query->rows;
|
||||
|
||||
$this->cache->set('return_action.' . md5($sql), $return_action_data);
|
||||
}
|
||||
|
||||
return $return_action_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_action_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $return_action_id): array {
|
||||
$return_action_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_action` WHERE `return_action_id` = '" . (int)$return_action_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$return_action_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $return_action_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReturnActions(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return_action` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/return_reason.php
Normal file
132
admininistrator/model/localisation/return_reason.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class ReturnReason
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class ReturnReason extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addReturnReason(array $data): int {
|
||||
foreach ($data['return_reason'] as $language_id => $value) {
|
||||
if (isset($return_reason_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_reason` SET `return_reason_id` = '" . (int)$return_reason_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_reason` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$return_reason_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('return_reason');
|
||||
|
||||
return $return_reason_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_reason_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editReturnReason(int $return_reason_id, array $data): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_reason` WHERE `return_reason_id` = '" . (int)$return_reason_id . "'");
|
||||
|
||||
foreach ($data['return_reason'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_reason` SET `return_reason_id` = '" . (int)$return_reason_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('return_reason');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_reason_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReturnReason(int $return_reason_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_reason` WHERE `return_reason_id` = '" . (int)$return_reason_id . "'");
|
||||
|
||||
$this->cache->delete('return_reason');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_reason_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnReason(int $return_reason_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_reason` WHERE `return_reason_id` = '" . (int)$return_reason_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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['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'];
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_reason_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $return_reason_id): array {
|
||||
$return_reason_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_reason` WHERE `return_reason_id` = '" . (int)$return_reason_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$return_reason_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $return_reason_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReturnReasons(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return_reason` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/return_status.php
Normal file
132
admininistrator/model/localisation/return_status.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class ReturnStatus
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class ReturnStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addReturnStatus(array $data): int {
|
||||
foreach ($data['return_status'] as $language_id => $value) {
|
||||
if (isset($return_status_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_status` SET `return_status_id` = '" . (int)$return_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_status` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$return_status_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('return_status');
|
||||
|
||||
return $return_status_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_status_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editReturnStatus(int $return_status_id, array $data) : void{
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_status` WHERE `return_status_id` = '" . (int)$return_status_id . "'");
|
||||
|
||||
foreach ($data['return_status'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_status` SET `return_status_id` = '" . (int)$return_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('return_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_status_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReturnStatus(int $return_status_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_status` WHERE `return_status_id` = '" . (int)$return_status_id . "'");
|
||||
|
||||
$this->cache->delete('return_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnStatus(int $return_status_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_status` WHERE `return_status_id` = '" . (int)$return_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnStatuses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "return_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'];
|
||||
}
|
||||
|
||||
$return_status_data = $this->cache->get('return_status.' . md5($sql));
|
||||
|
||||
if (!$return_status_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$return_status_data = $query->rows;
|
||||
|
||||
$this->cache->set('return_status.' . md5($sql), $return_status_data);
|
||||
}
|
||||
|
||||
return $return_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $return_status_id): array {
|
||||
$return_status_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_status` WHERE `return_status_id` = '" . (int)$return_status_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$return_status_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $return_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReturnStatuses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/stock_status.php
Normal file
132
admininistrator/model/localisation/stock_status.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class StockStatus
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class StockStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addStockStatus(array $data): int {
|
||||
foreach ($data['stock_status'] as $language_id => $value) {
|
||||
if (isset($stock_status_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "stock_status` SET `stock_status_id` = '" . (int)$stock_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "stock_status` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$stock_status_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('stock_status');
|
||||
|
||||
return $stock_status_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $stock_status_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editStockStatus(int $stock_status_id, array $data): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "stock_status` WHERE `stock_status_id` = '" . (int)$stock_status_id . "'");
|
||||
|
||||
foreach ($data['stock_status'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "stock_status` SET `stock_status_id` = '" . (int)$stock_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('stock_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $stock_status_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteStockStatus(int $stock_status_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "stock_status` WHERE `stock_status_id` = '" . (int)$stock_status_id . "'");
|
||||
|
||||
$this->cache->delete('stock_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $stock_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $stock_status_id): array {
|
||||
$stock_status_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "stock_status` WHERE `stock_status_id` = '" . (int)$stock_status_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$stock_status_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $stock_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStockStatuses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "stock_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/subscription_status.php
Normal file
132
admininistrator/model/localisation/subscription_status.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class SubscriptionStatus
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class SubscriptionStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addSubscriptionStatus(array $data): int {
|
||||
foreach ($data['subscription_status'] as $language_id => $value) {
|
||||
if (isset($subscription_status_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_status` SET `subscription_status_id` = '" . (int)$subscription_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_status` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$subscription_status_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('subscription_status');
|
||||
|
||||
return $subscription_status_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_status_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editSubscriptionStatus(int $subscription_status_id, array $data): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "subscription_status` WHERE `subscription_status_id` = '" . (int)$subscription_status_id . "'");
|
||||
|
||||
foreach ($data['subscription_status'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_status` SET `subscription_status_id` = '" . (int)$subscription_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('subscription_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_status_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteSubscriptionStatus(int $subscription_status_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "subscription_status` WHERE `subscription_status_id` = '" . (int)$subscription_status_id . "'");
|
||||
|
||||
$this->cache->delete('subscription_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionStatuses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "subscription_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'];
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $subscription_status_id): array {
|
||||
$subscription_status_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_status` WHERE `subscription_status_id` = '" . (int)$subscription_status_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$subscription_status_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $subscription_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalSubscriptionStatuses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
142
admininistrator/model/localisation/tax_class.php
Normal file
142
admininistrator/model/localisation/tax_class.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class TaxClass
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class TaxClass extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addTaxClass(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_class` SET `title` = '" . $this->db->escape((string)$data['title']) . "', `description` = '" . $this->db->escape((string)$data['description']) . "', `date_added` = NOW()");
|
||||
|
||||
$tax_class_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['tax_rule'])) {
|
||||
foreach ($data['tax_rule'] as $tax_rule) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_rule` SET `tax_class_id` = '" . (int)$tax_class_id . "', `tax_rate_id` = '" . (int)$tax_rule['tax_rate_id'] . "', `based` = '" . $this->db->escape($tax_rule['based']) . "', `priority` = '" . (int)$tax_rule['priority'] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('tax_class');
|
||||
|
||||
return $tax_class_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_class_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editTaxClass(int $tax_class_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "tax_class` SET `title` = '" . $this->db->escape((string)$data['title']) . "', `description` = '" . $this->db->escape((string)$data['description']) . "', `date_modified` = NOW() WHERE `tax_class_id` = '" . (int)$tax_class_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rule` WHERE `tax_class_id` = '" . (int)$tax_class_id . "'");
|
||||
|
||||
if (isset($data['tax_rule'])) {
|
||||
foreach ($data['tax_rule'] as $tax_rule) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_rule` SET `tax_class_id` = '" . (int)$tax_class_id . "', `tax_rate_id` = '" . (int)$tax_rule['tax_rate_id'] . "', `based` = '" . $this->db->escape($tax_rule['based']) . "', `priority` = '" . (int)$tax_rule['priority'] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('tax_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_class_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTaxClass(int $tax_class_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_class` WHERE `tax_class_id` = '" . (int)$tax_class_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rule` WHERE `tax_class_id` = '" . (int)$tax_class_id . "'");
|
||||
|
||||
$this->cache->delete('tax_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTaxClass(int $tax_class_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "tax_class` WHERE `tax_class_id` = '" . (int)$tax_class_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTaxClasses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "tax_class` ORDER BY `title`";
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$tax_class_data = $this->cache->get('tax_class.'. md5($sql));
|
||||
|
||||
if (!$tax_class_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$tax_class_data = $query->rows;
|
||||
|
||||
$this->cache->set('tax_class.'. md5($sql), $tax_class_data);
|
||||
}
|
||||
|
||||
return $tax_class_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTaxClasses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "tax_class`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTaxRules(int $tax_class_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "tax_rule` WHERE `tax_class_id` = '" . (int)$tax_class_id . "' ORDER BY `priority` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_rate_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTaxRulesByTaxRateId(int $tax_rate_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(DISTINCT `tax_class_id`) AS `total` FROM `" . DB_PREFIX . "tax_rule` WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
149
admininistrator/model/localisation/tax_rate.php
Normal file
149
admininistrator/model/localisation/tax_rate.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class TaxRate
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class TaxRate extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addTaxRate(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_rate` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `rate` = '" . (float)$data['rate'] . "', `type` = '" . $this->db->escape((string)$data['type']) . "', `geo_zone_id` = '" . (int)$data['geo_zone_id'] . "', `date_added` = NOW(), `date_modified` = NOW()");
|
||||
|
||||
$tax_rate_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['tax_rate_customer_group'])) {
|
||||
foreach ($data['tax_rate_customer_group'] as $customer_group_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_rate_to_customer_group` SET `tax_rate_id` = '" . (int)$tax_rate_id . "', `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
return $tax_rate_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_rate_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editTaxRate(int $tax_rate_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "tax_rate` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `rate` = '" . (float)$data['rate'] . "', `type` = '" . $this->db->escape((string)$data['type']) . "', `geo_zone_id` = '" . (int)$data['geo_zone_id'] . "', `date_modified` = NOW() WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rate_to_customer_group` WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
if (isset($data['tax_rate_customer_group'])) {
|
||||
foreach ($data['tax_rate_customer_group'] as $customer_group_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_rate_to_customer_group` SET `tax_rate_id` = '" . (int)$tax_rate_id . "', `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_rate_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTaxRate(int $tax_rate_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rate` WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rate_to_customer_group` WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_rate_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTaxRate(int $tax_rate_id): array {
|
||||
$query = $this->db->query("SELECT tr.`tax_rate_id`, tr.`name` AS name, tr.`rate`, tr.`type`, tr.`geo_zone_id`, gz.`name` AS geo_zone, tr.`date_added`, tr.`date_modified` FROM `" . DB_PREFIX . "tax_rate` tr LEFT JOIN `" . DB_PREFIX . "geo_zone` gz ON (tr.`geo_zone_id` = gz.`geo_zone_id`) WHERE tr.`tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTaxRates(array $data = []): array {
|
||||
$sql = "SELECT tr.`tax_rate_id`, tr.`name` AS name, tr.`rate`, tr.`type`, gz.`name` AS geo_zone, tr.`date_added`, tr.`date_modified` FROM `" . DB_PREFIX . "tax_rate` tr LEFT JOIN `" . DB_PREFIX . "geo_zone` gz ON (tr.`geo_zone_id` = gz.`geo_zone_id`)";
|
||||
|
||||
$sort_data = [
|
||||
'tr.name',
|
||||
'tr.rate',
|
||||
'tr.type',
|
||||
'gz.name',
|
||||
'tr.date_added',
|
||||
'tr.date_modified'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY tr.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_rate_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomerGroups(int $tax_rate_id): array {
|
||||
$tax_customer_group_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "tax_rate_to_customer_group` WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$tax_customer_group_data[] = $result['customer_group_id'];
|
||||
}
|
||||
|
||||
return $tax_customer_group_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTaxRates(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "tax_rate`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTaxRatesByGeoZoneId(int $geo_zone_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "tax_rate` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
159
admininistrator/model/localisation/weight_class.php
Normal file
159
admininistrator/model/localisation/weight_class.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class WeightClass
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class WeightClass extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addWeightClass(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "weight_class` SET `value` = '" . (float)$data['value'] . "'");
|
||||
|
||||
$weight_class_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['weight_class_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "weight_class_description` SET `weight_class_id` = '" . (int)$weight_class_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($value['title']) . "', `unit` = '" . $this->db->escape($value['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('weight_class');
|
||||
|
||||
return $weight_class_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $weight_class_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editWeightClass(int $weight_class_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "weight_class` SET `value` = '" . (float)$data['value'] . "' WHERE `weight_class_id` = '" . (int)$weight_class_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "weight_class_description` WHERE `weight_class_id` = '" . (int)$weight_class_id . "'");
|
||||
|
||||
foreach ($data['weight_class_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "weight_class_description` SET `weight_class_id` = '" . (int)$weight_class_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($value['title']) . "', `unit` = '" . $this->db->escape($value['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('weight_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $weight_class_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteWeightClass(int $weight_class_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "weight_class` WHERE `weight_class_id` = '" . (int)$weight_class_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "weight_class_description` WHERE `weight_class_id` = '" . (int)$weight_class_id . "'");
|
||||
|
||||
$this->cache->delete('weight_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getWeightClasses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "weight_class` wc LEFT JOIN `" . DB_PREFIX . "weight_class_description` wcd ON (wc.`weight_class_id` = wcd.`weight_class_id`) WHERE wcd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$sort_data = [
|
||||
'title',
|
||||
'unit',
|
||||
'value'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `title`";
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$weight_class_data = $this->cache->get('weight_class.' . md5($sql));
|
||||
|
||||
if (!$weight_class_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$weight_class_data = $query->rows;
|
||||
|
||||
$this->cache->set('weight_class.' . md5($sql), $weight_class_data);
|
||||
}
|
||||
|
||||
return $weight_class_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $weight_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getWeightClass(int $weight_class_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "weight_class` wc LEFT JOIN `" . DB_PREFIX . "weight_class_description` wcd ON (wc.`weight_class_id` = wcd.`weight_class_id`) WHERE wc.`weight_class_id` = '" . (int)$weight_class_id . "' AND wcd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptionByUnit(string $unit): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "weight_class_description` WHERE `unit` = '" . $this->db->escape($unit) . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $weight_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $weight_class_id): array {
|
||||
$weight_class_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "weight_class_description` WHERE `weight_class_id` = '" . (int)$weight_class_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$weight_class_data[$result['language_id']] = [
|
||||
'title' => $result['title'],
|
||||
'unit' => $result['unit']
|
||||
];
|
||||
}
|
||||
|
||||
return $weight_class_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalWeightClasses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "weight_class`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
183
admininistrator/model/localisation/zone.php
Normal file
183
admininistrator/model/localisation/zone.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Zone
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class Zone extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addZone(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "zone` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `country_id` = '" . (int)$data['country_id'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "'");
|
||||
|
||||
$this->cache->delete('zone');
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $zone_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editZone(int $zone_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "zone` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `country_id` = '" . (int)$data['country_id'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `zone_id` = '" . (int)$zone_id . "'");
|
||||
|
||||
$this->cache->delete('zone');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $zone_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteZone(int $zone_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$zone_id . "'");
|
||||
|
||||
$this->cache->delete('zone');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $zone_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZone(int $zone_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$zone_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZones(array $data = []): array {
|
||||
$sql = "SELECT *, z.`name`, c.`name` AS country FROM `" . DB_PREFIX . "zone` z LEFT JOIN `" . DB_PREFIX . "country` c ON (z.`country_id` = c.`country_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "z.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_country'])) {
|
||||
$implode[] = "c.`name` LIKE '" . $this->db->escape((string)$data['filter_country'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_code'])) {
|
||||
$implode[] = "z.`code` LIKE '" . $this->db->escape((string)$data['filter_code'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'c.name',
|
||||
'z.name',
|
||||
'z.code'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY c.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalZones(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "zone` z";
|
||||
|
||||
if (!empty($data['filter_country'])) {
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "country` c ON (z.`country_id` = c.`country_id`)";
|
||||
}
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "z.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_country'])) {
|
||||
$implode[] = "c.`name` LIKE '" . $this->db->escape((string)$data['filter_country'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_code'])) {
|
||||
$implode[] = "z.`code` LIKE '" . $this->db->escape((string)$data['filter_code'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalZonesByCountryId(int $country_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "zone` WHERE `country_id` = '" . (int)$country_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user