diff options
Diffstat (limited to 'public/admin/model/localisation')
-rw-r--r-- | public/admin/model/localisation/country.php | 86 | ||||
-rw-r--r-- | public/admin/model/localisation/currency.php | 159 | ||||
-rw-r--r-- | public/admin/model/localisation/geo_zone.php | 130 | ||||
-rw-r--r-- | public/admin/model/localisation/language.php | 313 | ||||
-rw-r--r-- | public/admin/model/localisation/length_class.php | 120 | ||||
-rw-r--r-- | public/admin/model/localisation/location.php | 65 | ||||
-rw-r--r-- | public/admin/model/localisation/order_status.php | 100 | ||||
-rw-r--r-- | public/admin/model/localisation/return_action.php | 100 | ||||
-rw-r--r-- | public/admin/model/localisation/return_reason.php | 100 | ||||
-rw-r--r-- | public/admin/model/localisation/return_status.php | 100 | ||||
-rw-r--r-- | public/admin/model/localisation/stock_status.php | 100 | ||||
-rw-r--r-- | public/admin/model/localisation/tax_class.php | 105 | ||||
-rw-r--r-- | public/admin/model/localisation/tax_rate.php | 104 | ||||
-rw-r--r-- | public/admin/model/localisation/weight_class.php | 120 | ||||
-rw-r--r-- | public/admin/model/localisation/zone.php | 92 |
15 files changed, 1794 insertions, 0 deletions
diff --git a/public/admin/model/localisation/country.php b/public/admin/model/localisation/country.php new file mode 100644 index 0000000..065ddf0 --- /dev/null +++ b/public/admin/model/localisation/country.php @@ -0,0 +1,86 @@ +<?php +class ModelLocalisationCountry extends Model { + public function addCountry($data) { + $this->db->query("INSERT INTO " . DB_PREFIX . "country SET name = '" . $this->db->escape($data['name']) . "', iso_code_2 = '" . $this->db->escape($data['iso_code_2']) . "', iso_code_3 = '" . $this->db->escape($data['iso_code_3']) . "', address_format = '" . $this->db->escape($data['address_format']) . "', postcode_required = '" . (int)$data['postcode_required'] . "', status = '" . (int)$data['status'] . "'"); + + $this->cache->delete('country'); + + return $this->db->getLastId(); + } + + public function editCountry($country_id, $data) { + $this->db->query("UPDATE " . DB_PREFIX . "country SET name = '" . $this->db->escape($data['name']) . "', iso_code_2 = '" . $this->db->escape($data['iso_code_2']) . "', iso_code_3 = '" . $this->db->escape($data['iso_code_3']) . "', address_format = '" . $this->db->escape($data['address_format']) . "', postcode_required = '" . (int)$data['postcode_required'] . "', status = '" . (int)$data['status'] . "' WHERE country_id = '" . (int)$country_id . "'"); + + $this->cache->delete('country'); + } + + public function deleteCountry($country_id) { + $this->db->query("DELETE FROM " . DB_PREFIX . "country WHERE country_id = '" . (int)$country_id . "'"); + + $this->cache->delete('country'); + } + + public function getCountry($country_id) { + $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "country WHERE country_id = '" . (int)$country_id . "'"); + + return $query->row; + } + + public function getCountries($data = array()) { + if ($data) { + $sql = "SELECT * FROM " . DB_PREFIX . "country"; + + $sort_data = array( + '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']; + } + + $query = $this->db->query($sql); + + return $query->rows; + } else { + $country_data = $this->cache->get('country.admin'); + + if (!$country_data) { + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "country ORDER BY name ASC"); + + $country_data = $query->rows; + + $this->cache->set('country.admin', $country_data); + } + + return $country_data; + } + } + + public function getTotalCountries() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "country"); + + return $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/currency.php b/public/admin/model/localisation/currency.php new file mode 100644 index 0000000..3e478e5 --- /dev/null +++ b/public/admin/model/localisation/currency.php @@ -0,0 +1,159 @@ +<?php +class ModelLocalisationCurrency extends Model { + public function addCurrency($data) { + $this->db->query("INSERT INTO " . DB_PREFIX . "currency SET title = '" . $this->db->escape($data['title']) . "', code = '" . $this->db->escape($data['code']) . "', symbol_left = '" . $this->db->escape($data['symbol_left']) . "', symbol_right = '" . $this->db->escape($data['symbol_right']) . "', decimal_place = '" . $this->db->escape($data['decimal_place']) . "', value = '" . $this->db->escape($data['value']) . "', status = '" . (int)$data['status'] . "', date_modified = NOW()"); + + $currency_id = $this->db->getLastId(); + + if ($this->config->get('config_currency_auto')) { + $this->refresh(true); + } + + $this->cache->delete('currency'); + + return $currency_id; + } + + public function editCurrency($currency_id, $data) { + $this->db->query("UPDATE " . DB_PREFIX . "currency SET title = '" . $this->db->escape($data['title']) . "', code = '" . $this->db->escape($data['code']) . "', symbol_left = '" . $this->db->escape($data['symbol_left']) . "', symbol_right = '" . $this->db->escape($data['symbol_right']) . "', decimal_place = '" . $this->db->escape($data['decimal_place']) . "', value = '" . $this->db->escape($data['value']) . "', status = '" . (int)$data['status'] . "', date_modified = NOW() WHERE currency_id = '" . (int)$currency_id . "'"); + + $this->cache->delete('currency'); + } + + public function deleteCurrency($currency_id) { + $this->db->query("DELETE FROM " . DB_PREFIX . "currency WHERE currency_id = '" . (int)$currency_id . "'"); + + $this->cache->delete('currency'); + } + + public function getCurrency($currency_id) { + $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "currency WHERE currency_id = '" . (int)$currency_id . "'"); + + return $query->row; + } + + public function getCurrencyByCode($currency) { + $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "currency WHERE code = '" . $this->db->escape($currency) . "'"); + + return $query->row; + } + + public function getCurrencies($data = array()) { + if ($data) { + $sql = "SELECT * FROM " . DB_PREFIX . "currency"; + + $sort_data = array( + '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']; + } + + $query = $this->db->query($sql); + + return $query->rows; + } else { + $currency_data = $this->cache->get('currency'); + + if (!$currency_data) { + $currency_data = array(); + + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency ORDER BY title ASC"); + + foreach ($query->rows as $result) { + $currency_data[$result['code']] = array( + 'currency_id' => $result['currency_id'], + 'title' => $result['title'], + 'code' => $result['code'], + 'symbol_left' => $result['symbol_left'], + 'symbol_right' => $result['symbol_right'], + 'decimal_place' => $result['decimal_place'], + 'value' => $result['value'], + 'status' => $result['status'], + 'date_modified' => $result['date_modified'] + ); + } + + $this->cache->set('currency', $currency_data); + } + + return $currency_data; + } + } + + public function refresh($force = false) { + $currency_data = array(); + + if ($force) { + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency WHERE code != '" . $this->db->escape($this->config->get('config_currency')) . "'"); + } else { + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency WHERE code != '" . $this->db->escape($this->config->get('config_currency')) . "' AND date_modified < '" . $this->db->escape(date('Y-m-d H:i:s', strtotime('-1 day'))) . "'"); + } + + foreach ($query->rows as $result) { + $currency_data[] = $this->config->get('config_currency') . $result['code'] . '=X'; + $currency_data[] = $result['code'] . $this->config->get('config_currency') . '=X'; + } + + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_URL, 'http://download.finance.yahoo.com/d/quotes.csv?s=' . implode(',', $currency_data) . '&f=sl1&e=.json'); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); + curl_setopt($curl, CURLOPT_TIMEOUT, 30); + + $content = curl_exec($curl); + + curl_close($curl); + + $line = explode("\n", trim($content)); + + for ($i = 0; $i < count($line); $i = $i + 2) { + $currency = utf8_substr($line[$i], 4, 3); + $value = utf8_substr($line[$i], 11, 6); + + if ((float)$value < 1 && isset($line[$i + 1])) { + $value = (1 / utf8_substr($line[$i + 1], 11, 6)); + } + + if ((float)$value) { + $this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '" . (float)$value . "', date_modified = '" . $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE code = '" . $this->db->escape($currency) . "'"); + } + } + + $this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '1.00000', date_modified = '" . $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE code = '" . $this->db->escape($this->config->get('config_currency')) . "'"); + + $this->cache->delete('currency'); + } + + public function getTotalCurrencies() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "currency"); + + return $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/geo_zone.php b/public/admin/model/localisation/geo_zone.php new file mode 100644 index 0000000..d682641 --- /dev/null +++ b/public/admin/model/localisation/geo_zone.php @@ -0,0 +1,130 @@ +<?php +class ModelLocalisationGeoZone extends Model { + public function addGeoZone($data) { + $this->db->query("INSERT INTO " . DB_PREFIX . "geo_zone SET name = '" . $this->db->escape($data['name']) . "', description = '" . $this->db->escape($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; + } + + public function editGeoZone($geo_zone_id, $data) { + $this->db->query("UPDATE " . DB_PREFIX . "geo_zone SET name = '" . $this->db->escape($data['name']) . "', description = '" . $this->db->escape($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'); + } + + public function deleteGeoZone($geo_zone_id) { + $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'); + } + + public function getGeoZone($geo_zone_id) { + $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "geo_zone WHERE geo_zone_id = '" . (int)$geo_zone_id . "'"); + + return $query->row; + } + + public function getGeoZones($data = array()) { + if ($data) { + $sql = "SELECT * FROM " . DB_PREFIX . "geo_zone"; + + $sort_data = array( + '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']; + } + + $query = $this->db->query($sql); + + return $query->rows; + } else { + $geo_zone_data = $this->cache->get('geo_zone'); + + if (!$geo_zone_data) { + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "geo_zone ORDER BY name ASC"); + + $geo_zone_data = $query->rows; + + $this->cache->set('geo_zone', $geo_zone_data); + } + + return $geo_zone_data; + } + } + + public function getTotalGeoZones() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "geo_zone"); + + return $query->row['total']; + } + + public function getZoneToGeoZones($geo_zone_id) { + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$geo_zone_id . "'"); + + return $query->rows; + } + + public function getTotalZoneToGeoZoneByGeoZoneId($geo_zone_id) { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$geo_zone_id . "'"); + + return $query->row['total']; + } + + public function getTotalZoneToGeoZoneByCountryId($country_id) { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "zone_to_geo_zone WHERE country_id = '" . (int)$country_id . "'"); + + return $query->row['total']; + } + + public function getTotalZoneToGeoZoneByZoneId($zone_id) { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "zone_to_geo_zone WHERE zone_id = '" . (int)$zone_id . "'"); + + return $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/language.php b/public/admin/model/localisation/language.php new file mode 100644 index 0000000..2e48c6c --- /dev/null +++ b/public/admin/model/localisation/language.php @@ -0,0 +1,313 @@ +<?php +class ModelLocalisationLanguage extends Model { + public function addLanguage($data) { + $this->db->query("INSERT INTO " . DB_PREFIX . "language SET name = '" . $this->db->escape($data['name']) . "', code = '" . $this->db->escape($data['code']) . "', locale = '" . $this->db->escape($data['locale']) . "', sort_order = '" . (int)$data['sort_order'] . "', status = '" . (int)$data['status'] . "'"); + + $this->cache->delete('catalog.language'); + $this->cache->delete('admin.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']) . "'"); + } + + $this->cache->delete('category'); + + // 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'); + + // Profiles + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "recurring_description WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + foreach ($query->rows as $recurring) { + $this->db->query("INSERT INTO " . DB_PREFIX . "recurring_description SET recurring_id = '" . (int)$recurring['recurring_id'] . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($recurring['name'])); + } + + return $language_id; + } + + public function editLanguage($language_id, $data) { + $language_query = $this->db->query("SELECT `code` FROM " . DB_PREFIX . "language WHERE language_id = '" . (int)$language_id . "'"); + + $this->db->query("UPDATE " . DB_PREFIX . "language SET name = '" . $this->db->escape($data['name']) . "', code = '" . $this->db->escape($data['code']) . "', locale = '" . $this->db->escape($data['locale']) . "', sort_order = '" . (int)$data['sort_order'] . "', status = '" . (int)$data['status'] . "' WHERE language_id = '" . (int)$language_id . "'"); + + if ($language_query->row['code'] != $data['code']) { + $this->db->query("UPDATE " . DB_PREFIX . "setting SET value = '" . $this->db->escape($data['code']) . "' WHERE `key` = 'config_language' AND value = '" . $this->db->escape($language_query->row['code']) . "'"); + $this->db->query("UPDATE " . DB_PREFIX . "setting SET value = '" . $this->db->escape($data['code']) . "' WHERE `key` = 'config_admin_language' AND value = '" . $this->db->escape($language_query->row['code']) . "'"); + } + + $this->cache->delete('catalog.language'); + $this->cache->delete('admin.language'); + } + + public function deleteLanguage($language_id) { + $this->db->query("DELETE FROM " . DB_PREFIX . "language WHERE language_id = '" . (int)$language_id . "'"); + + $this->cache->delete('catalog.language'); + $this->cache->delete('admin.language'); + + /* + Do not put any delete code for related tables for languages!!!!!!!!! + + It is not required as when ever you re save to a multi language table then the entries for the deleted language will also be deleted! + + Wasting my time with people adding code here! + */ + } + + public function getLanguage($language_id) { + $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "language WHERE language_id = '" . (int)$language_id . "'"); + + return $query->row; + } + + public function getLanguages($data = array()) { + if ($data) { + $sql = "SELECT * FROM " . DB_PREFIX . "language"; + + $sort_data = array( + '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']; + } + + $query = $this->db->query($sql); + + return $query->rows; + } else { + $language_data = $this->cache->get('language'); + + if (!$language_data) { + $language_data = array(); + + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "language ORDER BY sort_order, name"); + + foreach ($query->rows as $result) { + $language_data[$result['code']] = array( + 'language_id' => $result['language_id'], + 'name' => $result['name'], + 'code' => $result['code'], + 'locale' => $result['locale'], + 'image' => $result['image'], + 'directory' => $result['directory'], + 'sort_order' => $result['sort_order'], + 'status' => $result['status'] + ); + } + + $this->cache->set('admin.language', $language_data); + } + + return $language_data; + } + } + + public function getLanguageByCode($code) { + $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE code = '" . $this->db->escape($code) . "'"); + + return $query->row; + } + + public function getTotalLanguages() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "language"); + + return $query->row['total']; + } +} diff --git a/public/admin/model/localisation/length_class.php b/public/admin/model/localisation/length_class.php new file mode 100644 index 0000000..8de3b31 --- /dev/null +++ b/public/admin/model/localisation/length_class.php @@ -0,0 +1,120 @@ +<?php +class ModelLocalisationLengthClass extends Model { + public function addLengthClass($data) { + $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; + } + + public function editLengthClass($length_class_id, $data) { + $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'); + } + + public function deleteLengthClass($length_class_id) { + $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'); + } + + public function getLengthClasses($data = array()) { + if ($data) { + $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 = array( + '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']; + } + + $query = $this->db->query($sql); + + return $query->rows; + } else { + $length_class_data = $this->cache->get('length_class.' . (int)$this->config->get('config_language_id')); + + if (!$length_class_data) { + $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 lcd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + $length_class_data = $query->rows; + + $this->cache->set('length_class.' . (int)$this->config->get('config_language_id'), $length_class_data); + } + + return $length_class_data; + } + } + + public function getLengthClass($length_class_id) { + $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; + } + + public function getLengthClassDescriptionByUnit($unit) { + $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; + } + + public function getLengthClassDescriptions($length_class_id) { + $length_class_data = array(); + + $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']] = array( + 'title' => $result['title'], + 'unit' => $result['unit'] + ); + } + + return $length_class_data; + } + + public function getTotalLengthClasses() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "length_class"); + + return $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/location.php b/public/admin/model/localisation/location.php new file mode 100644 index 0000000..bda96fb --- /dev/null +++ b/public/admin/model/localisation/location.php @@ -0,0 +1,65 @@ +<?php +class ModelLocalisationLocation extends Model { + public function addLocation($data) { + $this->db->query("INSERT INTO " . DB_PREFIX . "location SET name = '" . $this->db->escape($data['name']) . "', address = '" . $this->db->escape($data['address']) . "', geocode = '" . $this->db->escape($data['geocode']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', image = '" . $this->db->escape($data['image']) . "', open = '" . $this->db->escape($data['open']) . "', comment = '" . $this->db->escape($data['comment']) . "'"); + + return $this->db->getLastId(); + } + + public function editLocation($location_id, $data) { + $this->db->query("UPDATE " . DB_PREFIX . "location SET name = '" . $this->db->escape($data['name']) . "', address = '" . $this->db->escape($data['address']) . "', geocode = '" . $this->db->escape($data['geocode']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', image = '" . $this->db->escape($data['image']) . "', open = '" . $this->db->escape($data['open']) . "', comment = '" . $this->db->escape($data['comment']) . "' WHERE location_id = '" . (int)$location_id . "'"); + } + + public function deleteLocation($location_id) { + $this->db->query("DELETE FROM " . DB_PREFIX . "location WHERE location_id = " . (int)$location_id); + } + + public function getLocation($location_id) { + $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "location WHERE location_id = '" . (int)$location_id . "'"); + + return $query->row; + } + + public function getLocations($data = array()) { + $sql = "SELECT location_id, name, address FROM " . DB_PREFIX . "location"; + + $sort_data = array( + '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; + } + + public function getTotalLocations() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "location"); + + return $query->row['total']; + } +} diff --git a/public/admin/model/localisation/order_status.php b/public/admin/model/localisation/order_status.php new file mode 100644 index 0000000..7f98836 --- /dev/null +++ b/public/admin/model/localisation/order_status.php @@ -0,0 +1,100 @@ +<?php +class ModelLocalisationOrderStatus extends Model { + public function addOrderStatus($data) { + 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; + } + + public function editOrderStatus($order_status_id, $data) { + $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'); + } + + public function deleteOrderStatus($order_status_id) { + $this->db->query("DELETE FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int)$order_status_id . "'"); + + $this->cache->delete('order_status'); + } + + public function getOrderStatus($order_status_id) { + $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; + } + + public function getOrderStatuses($data = array()) { + if ($data) { + $sql = "SELECT * FROM " . DB_PREFIX . "order_status WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'"; + + $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; + } else { + $order_status_data = $this->cache->get('order_status.' . (int)$this->config->get('config_language_id')); + + if (!$order_status_data) { + $query = $this->db->query("SELECT order_status_id, name FROM " . DB_PREFIX . "order_status WHERE language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY name"); + + $order_status_data = $query->rows; + + $this->cache->set('order_status.' . (int)$this->config->get('config_language_id'), $order_status_data); + } + + return $order_status_data; + } + } + + public function getOrderStatusDescriptions($order_status_id) { + $order_status_data = array(); + + $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']] = array('name' => $result['name']); + } + + return $order_status_data; + } + + public function getTotalOrderStatuses() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "order_status WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + return $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/return_action.php b/public/admin/model/localisation/return_action.php new file mode 100644 index 0000000..a121217 --- /dev/null +++ b/public/admin/model/localisation/return_action.php @@ -0,0 +1,100 @@ +<?php +class ModelLocalisationReturnAction extends Model { + public function addReturnAction($data) { + 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; + } + + public function editReturnAction($return_action_id, $data) { + $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'); + } + + public function deleteReturnAction($return_action_id) { + $this->db->query("DELETE FROM " . DB_PREFIX . "return_action WHERE return_action_id = '" . (int)$return_action_id . "'"); + + $this->cache->delete('return_action'); + } + + public function getReturnAction($return_action_id) { + $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; + } + + public function getReturnActions($data = array()) { + if ($data) { + $sql = "SELECT * FROM " . DB_PREFIX . "return_action WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'"; + + $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; + } else { + $return_action_data = $this->cache->get('return_action.' . (int)$this->config->get('config_language_id')); + + if (!$return_action_data) { + $query = $this->db->query("SELECT return_action_id, name FROM " . DB_PREFIX . "return_action WHERE language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY name"); + + $return_action_data = $query->rows; + + $this->cache->set('return_action.' . (int)$this->config->get('config_language_id'), $return_action_data); + } + + return $return_action_data; + } + } + + public function getReturnActionDescriptions($return_action_id) { + $return_action_data = array(); + + $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']] = array('name' => $result['name']); + } + + return $return_action_data; + } + + public function getTotalReturnActions() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "return_action WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + return $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/return_reason.php b/public/admin/model/localisation/return_reason.php new file mode 100644 index 0000000..b33ca3c --- /dev/null +++ b/public/admin/model/localisation/return_reason.php @@ -0,0 +1,100 @@ +<?php +class ModelLocalisationReturnReason extends Model { + public function addReturnReason($data) { + 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; + } + + public function editReturnReason($return_reason_id, $data) { + $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'); + } + + public function deleteReturnReason($return_reason_id) { + $this->db->query("DELETE FROM " . DB_PREFIX . "return_reason WHERE return_reason_id = '" . (int)$return_reason_id . "'"); + + $this->cache->delete('return_reason'); + } + + public function getReturnReason($return_reason_id) { + $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; + } + + public function getReturnReasons($data = array()) { + if ($data) { + $sql = "SELECT * FROM " . DB_PREFIX . "return_reason WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'"; + + $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; + } else { + $return_reason_data = $this->cache->get('return_reason.' . (int)$this->config->get('config_language_id')); + + if (!$return_reason_data) { + $query = $this->db->query("SELECT return_reason_id, name FROM " . DB_PREFIX . "return_reason WHERE language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY name"); + + $return_reason_data = $query->rows; + + $this->cache->set('return_reason.' . (int)$this->config->get('config_language_id'), $return_reason_data); + } + + return $return_reason_data; + } + } + + public function getReturnReasonDescriptions($return_reason_id) { + $return_reason_data = array(); + + $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']] = array('name' => $result['name']); + } + + return $return_reason_data; + } + + public function getTotalReturnReasons() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "return_reason WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + return $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/return_status.php b/public/admin/model/localisation/return_status.php new file mode 100644 index 0000000..8f258df --- /dev/null +++ b/public/admin/model/localisation/return_status.php @@ -0,0 +1,100 @@ +<?php +class ModelLocalisationReturnStatus extends Model { + public function addReturnStatus($data) { + 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; + } + + public function editReturnStatus($return_status_id, $data) { + $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'); + } + + public function deleteReturnStatus($return_status_id) { + $this->db->query("DELETE FROM " . DB_PREFIX . "return_status WHERE return_status_id = '" . (int)$return_status_id . "'"); + + $this->cache->delete('return_status'); + } + + public function getReturnStatus($return_status_id) { + $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; + } + + public function getReturnStatuses($data = array()) { + if ($data) { + $sql = "SELECT * FROM " . DB_PREFIX . "return_status WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'"; + + $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; + } else { + $return_status_data = $this->cache->get('return_status.' . (int)$this->config->get('config_language_id')); + + if (!$return_status_data) { + $query = $this->db->query("SELECT return_status_id, name FROM " . DB_PREFIX . "return_status WHERE language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY name"); + + $return_status_data = $query->rows; + + $this->cache->set('return_status.' . (int)$this->config->get('config_language_id'), $return_status_data); + } + + return $return_status_data; + } + } + + public function getReturnStatusDescriptions($return_status_id) { + $return_status_data = array(); + + $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']] = array('name' => $result['name']); + } + + return $return_status_data; + } + + public function getTotalReturnStatuses() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "return_status WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + return $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/stock_status.php b/public/admin/model/localisation/stock_status.php new file mode 100644 index 0000000..dd5a2d6 --- /dev/null +++ b/public/admin/model/localisation/stock_status.php @@ -0,0 +1,100 @@ +<?php +class ModelLocalisationStockStatus extends Model { + public function addStockStatus($data) { + 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; + } + + public function editStockStatus($stock_status_id, $data) { + $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'); + } + + public function deleteStockStatus($stock_status_id) { + $this->db->query("DELETE FROM " . DB_PREFIX . "stock_status WHERE stock_status_id = '" . (int)$stock_status_id . "'"); + + $this->cache->delete('stock_status'); + } + + public function getStockStatus($stock_status_id) { + $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; + } + + public function getStockStatuses($data = array()) { + if ($data) { + $sql = "SELECT * FROM " . DB_PREFIX . "stock_status WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'"; + + $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; + } else { + $stock_status_data = $this->cache->get('stock_status.' . (int)$this->config->get('config_language_id')); + + if (!$stock_status_data) { + $query = $this->db->query("SELECT stock_status_id, name FROM " . DB_PREFIX . "stock_status WHERE language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY name"); + + $stock_status_data = $query->rows; + + $this->cache->set('stock_status.' . (int)$this->config->get('config_language_id'), $stock_status_data); + } + + return $stock_status_data; + } + } + + public function getStockStatusDescriptions($stock_status_id) { + $stock_status_data = array(); + + $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']] = array('name' => $result['name']); + } + + return $stock_status_data; + } + + public function getTotalStockStatuses() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "stock_status WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + return $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/tax_class.php b/public/admin/model/localisation/tax_class.php new file mode 100644 index 0000000..43b2164 --- /dev/null +++ b/public/admin/model/localisation/tax_class.php @@ -0,0 +1,105 @@ +<?php +class ModelLocalisationTaxClass extends Model { + public function addTaxClass($data) { + $this->db->query("INSERT INTO " . DB_PREFIX . "tax_class SET title = '" . $this->db->escape($data['title']) . "', description = '" . $this->db->escape($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; + } + + public function editTaxClass($tax_class_id, $data) { + $this->db->query("UPDATE " . DB_PREFIX . "tax_class SET title = '" . $this->db->escape($data['title']) . "', description = '" . $this->db->escape($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'); + } + + public function deleteTaxClass($tax_class_id) { + $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'); + } + + public function getTaxClass($tax_class_id) { + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "tax_class WHERE tax_class_id = '" . (int)$tax_class_id . "'"); + + return $query->row; + } + + public function getTaxClasses($data = array()) { + if ($data) { + $sql = "SELECT * FROM " . DB_PREFIX . "tax_class"; + + $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']; + } + + $query = $this->db->query($sql); + + return $query->rows; + } else { + $tax_class_data = $this->cache->get('tax_class'); + + if (!$tax_class_data) { + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "tax_class"); + + $tax_class_data = $query->rows; + + $this->cache->set('tax_class', $tax_class_data); + } + + return $tax_class_data; + } + } + + public function getTotalTaxClasses() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "tax_class"); + + return $query->row['total']; + } + + public function getTaxRules($tax_class_id) { + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "tax_rule WHERE tax_class_id = '" . (int)$tax_class_id . "'"); + + return $query->rows; + } + + public function getTotalTaxRulesByTaxRateId($tax_rate_id) { + $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 $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/tax_rate.php b/public/admin/model/localisation/tax_rate.php new file mode 100644 index 0000000..0b049d0 --- /dev/null +++ b/public/admin/model/localisation/tax_rate.php @@ -0,0 +1,104 @@ +<?php +class ModelLocalisationTaxRate extends Model { + public function addTaxRate($data) { + $this->db->query("INSERT INTO " . DB_PREFIX . "tax_rate SET name = '" . $this->db->escape($data['name']) . "', rate = '" . (float)$data['rate'] . "', `type` = '" . $this->db->escape($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; + } + + public function editTaxRate($tax_rate_id, $data) { + $this->db->query("UPDATE " . DB_PREFIX . "tax_rate SET name = '" . $this->db->escape($data['name']) . "', rate = '" . (float)$data['rate'] . "', `type` = '" . $this->db->escape($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 . "'"); + } + } + } + + public function deleteTaxRate($tax_rate_id) { + $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 . "'"); + } + + public function getTaxRate($tax_rate_id) { + $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; + } + + public function getTaxRates($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 = array( + '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; + } + + public function getTaxRateCustomerGroups($tax_rate_id) { + $tax_customer_group_data = array(); + + $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; + } + + public function getTotalTaxRates() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "tax_rate"); + + return $query->row['total']; + } + + public function getTotalTaxRatesByGeoZoneId($geo_zone_id) { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "tax_rate WHERE geo_zone_id = '" . (int)$geo_zone_id . "'"); + + return $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/weight_class.php b/public/admin/model/localisation/weight_class.php new file mode 100644 index 0000000..6e131ec --- /dev/null +++ b/public/admin/model/localisation/weight_class.php @@ -0,0 +1,120 @@ +<?php +class ModelLocalisationWeightClass extends Model { + public function addWeightClass($data) { + $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; + } + + public function editWeightClass($weight_class_id, $data) { + $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'); + } + + public function deleteWeightClass($weight_class_id) { + $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'); + } + + public function getWeightClasses($data = array()) { + if ($data) { + $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 = array( + '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']; + } + + $query = $this->db->query($sql); + + return $query->rows; + } else { + $weight_class_data = $this->cache->get('weight_class.' . (int)$this->config->get('config_language_id')); + + if (!$weight_class_data) { + $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 wcd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + $weight_class_data = $query->rows; + + $this->cache->set('weight_class.' . (int)$this->config->get('config_language_id'), $weight_class_data); + } + + return $weight_class_data; + } + } + + public function getWeightClass($weight_class_id) { + $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; + } + + public function getWeightClassDescriptionByUnit($unit) { + $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; + } + + public function getWeightClassDescriptions($weight_class_id) { + $weight_class_data = array(); + + $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']] = array( + 'title' => $result['title'], + 'unit' => $result['unit'] + ); + } + + return $weight_class_data; + } + + public function getTotalWeightClasses() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "weight_class"); + + return $query->row['total']; + } +}
\ No newline at end of file diff --git a/public/admin/model/localisation/zone.php b/public/admin/model/localisation/zone.php new file mode 100644 index 0000000..362c90d --- /dev/null +++ b/public/admin/model/localisation/zone.php @@ -0,0 +1,92 @@ +<?php +class ModelLocalisationZone extends Model { + public function addZone($data) { + $this->db->query("INSERT INTO " . DB_PREFIX . "zone SET status = '" . (int)$data['status'] . "', name = '" . $this->db->escape($data['name']) . "', code = '" . $this->db->escape($data['code']) . "', country_id = '" . (int)$data['country_id'] . "'"); + + $this->cache->delete('zone'); + + return $this->db->getLastId(); + } + + public function editZone($zone_id, $data) { + $this->db->query("UPDATE " . DB_PREFIX . "zone SET status = '" . (int)$data['status'] . "', name = '" . $this->db->escape($data['name']) . "', code = '" . $this->db->escape($data['code']) . "', country_id = '" . (int)$data['country_id'] . "' WHERE zone_id = '" . (int)$zone_id . "'"); + + $this->cache->delete('zone'); + } + + public function deleteZone($zone_id) { + $this->db->query("DELETE FROM " . DB_PREFIX . "zone WHERE zone_id = '" . (int)$zone_id . "'"); + + $this->cache->delete('zone'); + } + + public function getZone($zone_id) { + $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "zone WHERE zone_id = '" . (int)$zone_id . "'"); + + return $query->row; + } + + public function getZones($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)"; + + $sort_data = array( + '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; + } + + public function getZonesByCountryId($country_id) { + $zone_data = $this->cache->get('zone.' . (int)$country_id); + + if (!$zone_data) { + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone WHERE country_id = '" . (int)$country_id . "' AND status = '1' ORDER BY name"); + + $zone_data = $query->rows; + + $this->cache->set('zone.' . (int)$country_id, $zone_data); + } + + return $zone_data; + } + + public function getTotalZones() { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "zone"); + + return $query->row['total']; + } + + public function getTotalZonesByCountryId($country_id) { + $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "zone WHERE country_id = '" . (int)$country_id . "'"); + + return $query->row['total']; + } +}
\ No newline at end of file |