db->query("SELECT * FROM " . DB_PREFIX . "zone WHERE zone_id = '" . (int)$zone_id . "' AND status = '1'"); return $query->row; } 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 getZoneBySlug($slug, $country_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone WHERE slug = '" . $this->db->escape($slug) . "' AND country_id = '" . (int)$country_id . "' AND status = '1' LIMIT 1"); return $query->row; } public function getZoneUrl($zone_id, $url) { $zone = $this->getZone($zone_id); if (!$zone) { return $url; } $url_info = parse_url(str_replace('&', '&', $url)); $secure = isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] === 'on') || ($this->request->server['HTTPS'] === '1')); $store_url = $secure ? $this->config->get('config_ssl') : $this->config->get('config_url'); $store_info = parse_url($store_url); if (!$url_info || !$store_info || !isset($store_info['scheme']) || !isset($store_info['host'])) { return $store_url; } $parts = array_values(array_filter(explode('/', trim(isset($url_info['path']) ? $url_info['path'] : '', '/')), 'strlen')); $base_parts = array_values(array_filter(explode('/', trim(isset($store_info['path']) ? $store_info['path'] : '', '/')), 'strlen')); if ($base_parts && array_slice($parts, 0, count($base_parts)) === $base_parts) { $parts = array_slice($parts, count($base_parts)); } $zones = $this->getZonesByCountryId($zone['country_id']); foreach ($zones as $item) { if (!empty($item['slug']) && isset($parts[0]) && $parts[0] === $item['slug']) { array_shift($parts); break; } } if ((int)$zone['zone_id'] !== (int)$this->config->get('config_zone_id') && $zone['slug'] !== '') { array_unshift($parts, $zone['slug']); } $redirect = $store_info['scheme'] . '://' . $store_info['host'] . (isset($store_info['port']) ? ':' . $store_info['port'] : '') . '/' . implode('/', array_merge($base_parts, $parts)); if (isset($url_info['query'])) { $redirect .= '?' . $url_info['query']; } return $redirect; } }