Система регионов
This commit is contained in:
@@ -19,7 +19,7 @@ class ControllerCommonCity extends Controller {
|
||||
);
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('common/city/save');
|
||||
$data['action'] = $this->url->link('common/city/save', '', true);
|
||||
|
||||
$this->response->setOutput($this->load->view('common/city_list', $data));
|
||||
}
|
||||
@@ -28,12 +28,23 @@ class ControllerCommonCity extends Controller {
|
||||
$json = array();
|
||||
|
||||
if (isset($this->request->post['city_id'])) {
|
||||
$this->session->data['city_id'] = (int)$this->request->post['city_id'];
|
||||
$json['success'] = true;
|
||||
|
||||
$this->load->model('localisation/zone');
|
||||
$zone = $this->model_localisation_zone->getZone($this->session->data['city_id']);
|
||||
$json['name'] = $zone ? $zone['name'] : '';
|
||||
|
||||
$zone = $this->model_localisation_zone->getZone((int)$this->request->post['city_id']);
|
||||
|
||||
if (!$zone || (int)$zone['country_id'] !== (int)$this->config->get('config_country_id')) {
|
||||
$json['success'] = false;
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->session->data['city_id'] = (int)$zone['zone_id'];
|
||||
$json['success'] = true;
|
||||
$json['name'] = $zone['name'];
|
||||
$json['redirect'] = $this->model_localisation_zone->getZoneUrl($zone['zone_id'], isset($this->request->post['redirect']) ? $this->request->post['redirect'] : $this->url->link('common/home'));
|
||||
} else {
|
||||
$json['success'] = false;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ foreach(['name','email','telephone','address','open', 'comment'] as $item){
|
||||
}
|
||||
}
|
||||
|
||||
$data['city_list_url'] = $this->url->link('common/city');
|
||||
$data['city_list_url'] = $this->url->link('common/city', '', true);
|
||||
|
||||
return $this->load->view('common/header', $data);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ class ControllerProductManufacturer extends Controller {
|
||||
}
|
||||
|
||||
$data['continue'] = $this->url->link('common/home');
|
||||
$data['manufacturer'] = $this->url->link('product/manufacturer');
|
||||
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['column_right'] = $this->load->controller('common/column_right');
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ControllerStartupSeoUrl extends Controller {
|
||||
private $region_slug = '';
|
||||
|
||||
//seopro start
|
||||
private $seo_pro;
|
||||
@@ -13,25 +14,20 @@ class ControllerStartupSeoUrl extends Controller {
|
||||
//seopro end
|
||||
|
||||
public function index() {
|
||||
|
||||
// Add rewrite to url class
|
||||
if ($this->config->get('config_seo_url')) {
|
||||
$this->url->addRewrite($this);
|
||||
}
|
||||
|
||||
|
||||
// Decode URL
|
||||
if (isset($this->request->get['_route_'])) {
|
||||
$parts = explode('/', $this->request->get['_route_']);
|
||||
|
||||
$this->prepareRegion($parts);
|
||||
|
||||
//seopro prepare route
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$parts = $this->seo_pro->prepareRoute($parts);
|
||||
}
|
||||
//seopro prepare route end
|
||||
//seopro prepare route
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$parts = $this->seo_pro->prepareRoute($parts);
|
||||
}
|
||||
//seopro prepare route end
|
||||
|
||||
// remove any empty arrays from trailing
|
||||
if (utf8_strlen(end($parts)) == 0) {
|
||||
if ($parts && utf8_strlen(end($parts)) == 0) {
|
||||
array_pop($parts);
|
||||
}
|
||||
|
||||
@@ -85,6 +81,15 @@ class ControllerStartupSeoUrl extends Controller {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->request->get['_route_']) && parse_url($this->request->server['REQUEST_URI'], PHP_URL_PATH) === '/') {
|
||||
$this->setRegion((int)$this->config->get('config_zone_id'));
|
||||
} elseif ($this->region_slug === '') {
|
||||
$this->loadRegionFromSession();
|
||||
}
|
||||
|
||||
// Add rewrite to url class
|
||||
$this->url->addRewrite($this);
|
||||
|
||||
//seopro validate
|
||||
if($this->config->get('config_seo_pro')){
|
||||
@@ -95,6 +100,10 @@ class ControllerStartupSeoUrl extends Controller {
|
||||
}
|
||||
|
||||
public function rewrite($link) {
|
||||
if (!$this->config->get('config_seo_url')) {
|
||||
return $this->addRegionPrefix($link);
|
||||
}
|
||||
|
||||
$url_info = parse_url(str_replace('&', '&', $link));
|
||||
|
||||
if($this->config->get('config_seo_pro')){
|
||||
@@ -177,9 +186,96 @@ class ControllerStartupSeoUrl extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;
|
||||
return $this->addRegionPrefix($url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query);
|
||||
} else {
|
||||
return $link;
|
||||
return $this->addRegionPrefix($link);
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareRegion(&$parts) {
|
||||
$parts = array_values(array_filter($parts, 'strlen'));
|
||||
$zone = array();
|
||||
|
||||
if (isset($parts[0])) {
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$zone = $this->model_localisation_zone->getZoneBySlug($parts[0], $this->config->get('config_country_id'));
|
||||
}
|
||||
|
||||
if ($zone) {
|
||||
array_shift($parts);
|
||||
$this->setRegion((int)$zone['zone_id'], $zone['slug']);
|
||||
} else {
|
||||
$this->setRegion((int)$this->config->get('config_zone_id'));
|
||||
}
|
||||
|
||||
if ($parts) {
|
||||
$this->request->get['_route_'] = implode('/', $parts);
|
||||
} else {
|
||||
unset($this->request->get['_route_']);
|
||||
}
|
||||
}
|
||||
|
||||
private function loadRegionFromSession() {
|
||||
if (!isset($this->session->data['city_id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$zone = $this->model_localisation_zone->getZone($this->session->data['city_id']);
|
||||
|
||||
if ($zone && (int)$zone['country_id'] === (int)$this->config->get('config_country_id')) {
|
||||
$this->setRegion((int)$zone['zone_id'], $zone['slug']);
|
||||
}
|
||||
}
|
||||
|
||||
private function setRegion($zone_id, $slug = '') {
|
||||
$this->session->data['city_id'] = (int)$zone_id;
|
||||
$this->region_slug = ((int)$zone_id === (int)$this->config->get('config_zone_id')) ? '' : $slug;
|
||||
}
|
||||
|
||||
private function addRegionPrefix($link) {
|
||||
if ($this->region_slug === '') {
|
||||
return $link;
|
||||
}
|
||||
|
||||
$url_info = parse_url(str_replace('&', '&', $link));
|
||||
|
||||
if (!$url_info || !isset($url_info['scheme']) || !isset($url_info['host'])) {
|
||||
return $link;
|
||||
}
|
||||
|
||||
$path = isset($url_info['path']) ? preg_replace('#/index\.php$#', '', $url_info['path']) : '';
|
||||
$base_path = parse_url($this->config->get('config_url'), PHP_URL_PATH);
|
||||
$base_path = '/' . trim((string)$base_path, '/');
|
||||
|
||||
if ($base_path === '/') {
|
||||
$base_path = '';
|
||||
}
|
||||
|
||||
if ($base_path !== '' && ($path === $base_path || strpos($path, $base_path . '/') === 0)) {
|
||||
$relative_path = substr($path, strlen($base_path));
|
||||
} else {
|
||||
$relative_path = $path;
|
||||
}
|
||||
|
||||
$parts = array_values(array_filter(explode('/', trim($relative_path, '/')), 'strlen'));
|
||||
|
||||
if (!isset($parts[0]) || $parts[0] !== $this->region_slug) {
|
||||
array_unshift($parts, $this->region_slug);
|
||||
}
|
||||
|
||||
$link = $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . $base_path . '/' . implode('/', $parts);
|
||||
|
||||
if (isset($url_info['query'])) {
|
||||
$link .= '?' . str_replace('&', '&', $url_info['query']);
|
||||
}
|
||||
|
||||
if (isset($url_info['fragment'])) {
|
||||
$link .= '#' . $url_info['fragment'];
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,55 @@ class ModelLocalisationZone extends Model {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,9 +42,16 @@ a:hover path{
|
||||
}
|
||||
|
||||
.logo {
|
||||
|
||||
|
||||
font-size: 30px;
|
||||
|
||||
|
||||
}
|
||||
.logo img {
|
||||
display: block;
|
||||
width: auto;
|
||||
height: auto;
|
||||
max-width: 100%;
|
||||
max-height: 48px;
|
||||
}
|
||||
|
||||
header .menu {
|
||||
@@ -102,9 +109,12 @@ header .menu>li:last-child {
|
||||
padding: 13px 8px;
|
||||
}
|
||||
.logo {
|
||||
|
||||
|
||||
font-size: 20px;
|
||||
|
||||
|
||||
}
|
||||
.logo img {
|
||||
max-height: 32px;
|
||||
}
|
||||
}
|
||||
.btn {
|
||||
|
||||
@@ -454,16 +454,15 @@ function citySelect(el){
|
||||
width: 400,
|
||||
});
|
||||
|
||||
$('.city-item').click(function(e){
|
||||
e.preventDefault();
|
||||
var cityId = $(this).data('city-id');
|
||||
var cityName = $(this).text();
|
||||
send.post('index.php?route=common/city/save', {city_id: cityId}, function(json){
|
||||
if (json.success) {
|
||||
$('.current-city-name').text(json.name);
|
||||
$('.modal').modal('hide');
|
||||
}
|
||||
});
|
||||
$('.city-item').click(function(e){
|
||||
e.preventDefault();
|
||||
var cityId = $(this).data('city-id');
|
||||
var saveUrl = $('.city-grid').data('save-url');
|
||||
send.post(saveUrl, {city_id: cityId, redirect: window.location.href}, function(json){
|
||||
if (json.success) {
|
||||
window.location.href = json.redirect;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -597,4 +596,4 @@ function UpdatePage(elem, data = false, callback = false, url = '', anim = true)
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{{ text_empty }}</p>
|
||||
<a href="/" class="btn btn-dark">{{ button_continue }}</a>
|
||||
<a href="{{ continue }}" class="btn btn-dark">{{ button_continue }}</a>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
@@ -29,4 +29,4 @@
|
||||
|
||||
{{ content_bottom }}
|
||||
|
||||
{{ footer }}
|
||||
{{ footer }}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="city-grid">
|
||||
<div class="city-grid" data-save-url="{{ action }}">
|
||||
{% for zone in zones %}
|
||||
<button type="button" class="city-item{% if zone.active %} active{% endif %}" data-city-id="{{ zone.zone_id }}">{{ zone.name }}</button>
|
||||
{% endfor %}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<h1>{{ heading_title }}</h1>
|
||||
{% if categories %}
|
||||
<p><strong>{{ text_index }}</strong> {% for category in categories %}
|
||||
<a href="index.php?route=product/manufacturer#{{ category.name }}">{{ category.name }}</a> {% endfor %} </p>
|
||||
<a href="{{ manufacturer }}#{{ category.name }}">{{ category.name }}</a> {% endfor %} </p>
|
||||
{% for category in categories %}
|
||||
<h2 id="{{ category.name }}">{{ category.name }}</h2>
|
||||
{% if category.manufacturer %}
|
||||
@@ -53,7 +53,7 @@
|
||||
<h1>{{ heading_title }}</h1>
|
||||
{% if categories %}
|
||||
<p><strong>{{ text_index }}</strong> {% for category in categories %}
|
||||
<a href="index.php?route=product/manufacturer#{{ category.name }}">{{ category.name }}</a> {% endfor %} </p>
|
||||
<a href="{{ manufacturer }}#{{ category.name }}">{{ category.name }}</a> {% endfor %} </p>
|
||||
{% for category in categories %}
|
||||
<h2 id="{{ category.name }}">{{ category.name }}</h2>
|
||||
{% if category.manufacturer %}
|
||||
@@ -75,4 +75,4 @@
|
||||
</div>
|
||||
{{ footer }}
|
||||
|
||||
#}
|
||||
#}
|
||||
|
||||
Reference in New Issue
Block a user