Автозамены регионов

This commit is contained in:
Konstantin
2026-05-30 17:43:37 +03:00
parent df8cf22112
commit 6c8a012702
16 changed files with 317 additions and 18 deletions
@@ -270,6 +270,17 @@ class ControllerLocalisationZone extends Controller {
$data['error_slug'] = '';
}
if (isset($this->error['contact_email'])) {
$data['error_contact_email'] = $this->error['contact_email'];
} else {
$data['error_contact_email'] = '';
}
foreach (array('gorod', 'gorodu', 'gorodom', 'strana', 'stranu', 'stranoi', 'strane', 'strany') as $replacement_field) {
$key = 'replacement_' . $replacement_field;
$data['error_' . $key] = isset($this->error[$key]) ? $this->error[$key] : '';
}
$url = '';
if (isset($this->request->get['sort'])) {
@@ -340,6 +351,42 @@ class ControllerLocalisationZone extends Controller {
$data['slug'] = '';
}
foreach (array('telephone', 'email', 'address', 'geocode', 'fax', 'open', 'comment') as $contact_field) {
$key = 'contact_' . $contact_field;
if (isset($this->request->post[$key])) {
$data[$key] = $this->request->post[$key];
} elseif (!empty($zone_info)) {
$data[$key] = $zone_info[$key];
} else {
$data[$key] = '';
}
}
foreach (array('gorod', 'gorodu', 'gorodom', 'strana', 'stranu', 'stranoi', 'strane', 'strany') as $replacement_field) {
$key = 'replacement_' . $replacement_field;
if (isset($this->request->post[$key])) {
$data[$key] = $this->request->post[$key];
} elseif (!empty($zone_info)) {
$data[$key] = $zone_info[$key];
} else {
$data[$key] = '';
}
}
$data['replacement_fields'] = array();
foreach (array('gorod', 'gorodu', 'gorodom', 'strana', 'stranu', 'stranoi', 'strane', 'strany') as $replacement_field) {
$key = 'replacement_' . $replacement_field;
$data['replacement_fields'][] = array(
'name' => $key,
'label' => $this->language->get('entry_' . $key),
'value' => $data[$key],
'error' => $data['error_' . $key]
);
}
if (isset($this->request->post['country_id'])) {
$data['country_id'] = $this->request->post['country_id'];
} elseif (!empty($zone_info)) {
@@ -378,6 +425,18 @@ class ControllerLocalisationZone extends Controller {
$this->error['slug'] = $this->language->get('error_slug_exists');
}
if ($this->request->post['contact_email'] !== '' && !filter_var($this->request->post['contact_email'], FILTER_VALIDATE_EMAIL)) {
$this->error['contact_email'] = $this->language->get('error_contact_email');
}
foreach (array('gorod', 'gorodu', 'gorodom', 'strana', 'stranu', 'stranoi', 'strane', 'strany') as $replacement_field) {
$key = 'replacement_' . $replacement_field;
if ((utf8_strlen(trim($this->request->post[$key])) < 1) || (utf8_strlen($this->request->post[$key]) > 128)) {
$this->error[$key] = $this->language->get('error_replacement');
}
}
return !$this->error;
}
@@ -10,6 +10,8 @@ $_['text_success'] = 'Настройки успешно изменен
$_['text_list'] = 'Список регионов';
$_['text_add'] = 'Добавить';
$_['text_edit'] = 'Редактирование';
$_['text_contacts'] = 'Контакты региона';
$_['text_replacements'] = 'Автозамены';
// Column
$_['column_name'] = 'Название региона';
@@ -24,12 +26,33 @@ $_['entry_code'] = 'Код региона';
$_['entry_slug'] = 'Slug для URL';
$_['entry_country'] = 'Страна';
$_['entry_status'] = 'Статус';
$_['entry_contact_telephone'] = 'Телефон';
$_['entry_contact_email'] = 'Email';
$_['entry_contact_address'] = 'Адрес';
$_['entry_contact_geocode'] = 'Геокод';
$_['entry_contact_fax'] = 'Факс';
$_['entry_contact_open'] = 'Режим работы';
$_['entry_contact_comment'] = 'Комментарий';
$_['entry_replacement_gorod'] = '{_GOROD_}: в городе';
$_['entry_replacement_gorodu'] = '{_GORODU_}: к городу';
$_['entry_replacement_gorodom'] = '{_GORODOM_}: городом';
$_['entry_replacement_strana'] = '{_STRANA_}: страна';
$_['entry_replacement_stranu'] = '{_STRANU_}: в страну';
$_['entry_replacement_stranoi'] = '{_STRANOI_}: страной';
$_['entry_replacement_strane'] = '{_STRANE_}: в стране';
$_['entry_replacement_strany'] = '{_STRANY_}: из страны';
// Help
$_['help_contacts'] = 'Заполните только отличающиеся контакты. Для пустых полей будут использоваться общие настройки магазина.';
$_['help_replacements'] = 'Название региона используется для тега {_REGION_}. Остальные словоформы обязательны и подставляются в текст витрины автоматически.';
// Error
$_['error_permission'] = 'У вас недостаточно прав для внесения изменений!';
$_['error_name'] = 'Название должно содержать от 3 до 128 символов!';
$_['error_slug'] = 'Slug обязателен для всех регионов, кроме региона по умолчанию, и может содержать только строчные латинские буквы, цифры и дефисы!';
$_['error_slug_exists'] = 'Такой slug уже используется другим регионом!';
$_['error_contact_email'] = 'Введите корректный email или оставьте поле пустым!';
$_['error_replacement'] = 'Словоформа обязательна и не должна быть длиннее 128 символов!';
$_['error_default'] = 'Этот Регион нельзя удалить, поскольку он используется по умолчанию!';
$_['error_store'] = 'Этот Регион нельзя удалить, поскольку он используется в %s магазинах!';
$_['error_address'] = 'Этот Регион нельзя удалить, поскольку он используется в %s адресах!';
+2 -2
View File
@@ -1,7 +1,7 @@
<?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']) . "', slug = '" . $this->db->escape($data['slug']) . "', country_id = '" . (int)$data['country_id'] . "'");
$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']) . "', slug = '" . $this->db->escape($data['slug']) . "', contact_telephone = '" . $this->db->escape($data['contact_telephone']) . "', contact_email = '" . $this->db->escape($data['contact_email']) . "', contact_address = '" . $this->db->escape($data['contact_address']) . "', contact_geocode = '" . $this->db->escape($data['contact_geocode']) . "', contact_fax = '" . $this->db->escape($data['contact_fax']) . "', contact_open = '" . $this->db->escape($data['contact_open']) . "', contact_comment = '" . $this->db->escape($data['contact_comment']) . "', replacement_gorod = '" . $this->db->escape($data['replacement_gorod']) . "', replacement_gorodu = '" . $this->db->escape($data['replacement_gorodu']) . "', replacement_gorodom = '" . $this->db->escape($data['replacement_gorodom']) . "', replacement_strana = '" . $this->db->escape($data['replacement_strana']) . "', replacement_stranu = '" . $this->db->escape($data['replacement_stranu']) . "', replacement_stranoi = '" . $this->db->escape($data['replacement_stranoi']) . "', replacement_strane = '" . $this->db->escape($data['replacement_strane']) . "', replacement_strany = '" . $this->db->escape($data['replacement_strany']) . "', country_id = '" . (int)$data['country_id'] . "'");
$this->cache->delete('zone');
@@ -9,7 +9,7 @@ class ModelLocalisationZone extends Model {
}
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']) . "', slug = '" . $this->db->escape($data['slug']) . "', country_id = '" . (int)$data['country_id'] . "' WHERE zone_id = '" . (int)$zone_id . "'");
$this->db->query("UPDATE " . DB_PREFIX . "zone SET status = '" . (int)$data['status'] . "', name = '" . $this->db->escape($data['name']) . "', code = '" . $this->db->escape($data['code']) . "', slug = '" . $this->db->escape($data['slug']) . "', contact_telephone = '" . $this->db->escape($data['contact_telephone']) . "', contact_email = '" . $this->db->escape($data['contact_email']) . "', contact_address = '" . $this->db->escape($data['contact_address']) . "', contact_geocode = '" . $this->db->escape($data['contact_geocode']) . "', contact_fax = '" . $this->db->escape($data['contact_fax']) . "', contact_open = '" . $this->db->escape($data['contact_open']) . "', contact_comment = '" . $this->db->escape($data['contact_comment']) . "', replacement_gorod = '" . $this->db->escape($data['replacement_gorod']) . "', replacement_gorodu = '" . $this->db->escape($data['replacement_gorodu']) . "', replacement_gorodom = '" . $this->db->escape($data['replacement_gorodom']) . "', replacement_strana = '" . $this->db->escape($data['replacement_strana']) . "', replacement_stranu = '" . $this->db->escape($data['replacement_stranu']) . "', replacement_stranoi = '" . $this->db->escape($data['replacement_stranoi']) . "', replacement_strane = '" . $this->db->escape($data['replacement_strane']) . "', replacement_strany = '" . $this->db->escape($data['replacement_strany']) . "', country_id = '" . (int)$data['country_id'] . "' WHERE zone_id = '" . (int)$zone_id . "'");
$this->cache->delete('zone');
}
@@ -77,6 +77,70 @@
</select>
</div>
</div>
<fieldset>
<legend>{{ text_replacements }}</legend>
<p class="text-muted">{{ help_replacements }}</p>
{% for replacement_field in replacement_fields %}
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-{{ replacement_field.name }}">{{ replacement_field.label }}</label>
<div class="col-sm-10">
<input type="text" name="{{ replacement_field.name }}" value="{{ replacement_field.value }}" placeholder="{{ replacement_field.label }}" id="input-{{ replacement_field.name }}" class="form-control" />
{% if replacement_field.error %}
<div class="text-danger">{{ replacement_field.error }}</div>
{% endif %}
</div>
</div>
{% endfor %}
</fieldset>
<fieldset>
<legend>{{ text_contacts }}</legend>
<p class="text-muted">{{ help_contacts }}</p>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-contact-telephone">{{ entry_contact_telephone }}</label>
<div class="col-sm-10">
<input type="text" name="contact_telephone" value="{{ contact_telephone }}" placeholder="{{ entry_contact_telephone }}" id="input-contact-telephone" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-contact-email">{{ entry_contact_email }}</label>
<div class="col-sm-10">
<input type="text" name="contact_email" value="{{ contact_email }}" placeholder="{{ entry_contact_email }}" id="input-contact-email" class="form-control" />
{% if error_contact_email %}
<div class="text-danger">{{ error_contact_email }}</div>
{% endif %}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-contact-address">{{ entry_contact_address }}</label>
<div class="col-sm-10">
<textarea name="contact_address" rows="3" placeholder="{{ entry_contact_address }}" id="input-contact-address" class="form-control">{{ contact_address }}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-contact-geocode">{{ entry_contact_geocode }}</label>
<div class="col-sm-10">
<input type="text" name="contact_geocode" value="{{ contact_geocode }}" placeholder="{{ entry_contact_geocode }}" id="input-contact-geocode" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-contact-fax">{{ entry_contact_fax }}</label>
<div class="col-sm-10">
<input type="text" name="contact_fax" value="{{ contact_fax }}" placeholder="{{ entry_contact_fax }}" id="input-contact-fax" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-contact-open">{{ entry_contact_open }}</label>
<div class="col-sm-10">
<textarea name="contact_open" rows="3" placeholder="{{ entry_contact_open }}" id="input-contact-open" class="form-control">{{ contact_open }}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-contact-comment">{{ entry_contact_comment }}</label>
<div class="col-sm-10">
<textarea name="contact_comment" rows="3" placeholder="{{ entry_contact_comment }}" id="input-contact-comment" class="form-control">{{ contact_comment }}</textarea>
</div>
</div>
</fieldset>
</form>
</div>
</div>
+8 -1
View File
@@ -16,7 +16,7 @@ class ControllerCommonFooter extends Controller {
}
}
$data['contact'] = $this->url->link('information/contact');
$data['contact'] = $this->url->link('information/contact', '', true);
$data['return'] = $this->url->link('account/return/add', '', true);
$data['sitemap'] = $this->url->link('information/sitemap');
$data['tracking'] = $this->url->link('information/tracking');
@@ -28,6 +28,7 @@ class ControllerCommonFooter extends Controller {
$data['order'] = $this->url->link('account/order', '', true);
$data['wishlist'] = $this->url->link('account/wishlist', '', true);
$data['newsletter'] = $this->url->link('account/newsletter', '', true);
$data['text_contacts'] = $this->language->get('text_contacts');
$data['powered'] = sprintf($this->language->get('text_powered'), $this->config->get('config_name'), date('Y', time()));
@@ -60,6 +61,12 @@ foreach(['name','email','telephone','address','open', 'comment'] as $item){
$data['config_' . $item] = $this->config->get('config_' . $item);
}
$this->load->model('localisation/zone');
foreach ($this->model_localisation_zone->getContacts() as $field => $value) {
$data['config_' . $field] = $value;
}
$data['scripts'] = $this->document->getScripts('footer');
$data['styles'] = $this->document->getStyles('footer');
@@ -109,6 +109,13 @@ foreach(['name','email','telephone','address','open', 'comment'] as $item){
$zones = $this->model_localisation_zone->getZonesByCountryId($country_id);
$current_zone_id = isset($this->session->data['city_id']) ? (int)$this->session->data['city_id'] : (int)$this->config->get('config_zone_id');
$contacts = $this->model_localisation_zone->getContacts($current_zone_id);
foreach ($contacts as $field => $value) {
$data['config_' . $field] = $value;
}
$data['telephone'] = $contacts['telephone'];
$data['current_city_name'] = '';
foreach ($zones as $zone) {
@@ -4,6 +4,9 @@ class ControllerInformationContact extends Controller {
public function index() {
$this->load->language('information/contact');
$this->load->model('localisation/zone');
$contacts = $this->model_localisation_zone->getContacts();
$this->document->setTitle($this->language->get('heading_title'));
@@ -18,7 +21,7 @@ class ControllerInformationContact extends Controller {
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setTo($contacts['email']);
$mail->setFrom($this->request->post['email']);
$mail->setReplyTo($this->request->post['email']);
$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
@@ -89,13 +92,13 @@ class ControllerInformationContact extends Controller {
}
$data['store'] = $this->config->get('config_name');
$data['address'] = nl2br($this->config->get('config_address'));
$data['geocode'] = $this->config->get('config_geocode');
$data['address'] = nl2br($contacts['address']);
$data['geocode'] = $contacts['geocode'];
$data['geocode_hl'] = $this->config->get('config_language');
$data['telephone'] = $this->config->get('config_telephone');
$data['fax'] = $this->config->get('config_fax');
$data['open'] = nl2br($this->config->get('config_open'));
$data['comment'] = $this->config->get('config_comment');
$data['telephone'] = $contacts['telephone'];
$data['fax'] = $contacts['fax'];
$data['open'] = nl2br($contacts['open']);
$data['comment'] = $contacts['comment'];
$data['locations'] = array();
@@ -0,0 +1,8 @@
<?php
class ControllerStartupRegionReplacement extends Controller {
public function index() {
$this->load->model('localisation/zone');
$this->response->setReplacements($this->model_localisation_zone->getReplacements());
}
}
@@ -7,6 +7,7 @@ $_['text_information'] = 'Информация';
$_['text_service'] = 'Служба поддержки';
$_['text_extra'] = 'Дополнительно';
$_['text_contact'] = 'Связаться с нами';
$_['text_contacts'] = 'Контакты';
$_['text_return'] = 'Возврат товара';
$_['text_sitemap'] = 'Карта сайта';
$_['text_manufacturer'] = 'Производители';
@@ -20,4 +21,4 @@ $_['text_account'] = 'Личный кабинет';
$_['text_order'] = 'История заказов';
$_['text_wishlist'] = 'Закладки';
$_['text_newsletter'] = 'Рассылка';
$_['text_powered'] = 'Работает на <a target="_blank" href="https://ocstore.com/?utm_source=ocstore3_install">ocStore</a><br /> %s &copy; %s';
$_['text_powered'] = 'Работает на <a target="_blank" href="https://ocstore.com/?utm_source=ocstore3_install">ocStore</a><br /> %s &copy; %s';
+61
View File
@@ -26,6 +26,67 @@ class ModelLocalisationZone extends Model {
return $query->row;
}
public function getContacts($zone_id = 0) {
if (!$zone_id) {
$zone_id = isset($this->session->data['city_id']) ? (int)$this->session->data['city_id'] : (int)$this->config->get('config_zone_id');
}
$zone = $this->getZone($zone_id);
$contacts = array();
foreach (array('telephone', 'email', 'address', 'geocode', 'fax', 'open', 'comment') as $field) {
$key = 'contact_' . $field;
if (isset($zone[$key]) && trim((string)$zone[$key]) !== '') {
$contacts[$field] = $zone[$key];
} else {
$contacts[$field] = $this->config->get('config_' . $field);
}
}
return $contacts;
}
public function getReplacements($zone_id = 0) {
if (!$zone_id) {
$zone_id = isset($this->session->data['city_id']) ? (int)$this->session->data['city_id'] : (int)$this->config->get('config_zone_id');
}
$zone = $this->getZone($zone_id);
if (!$zone) {
$zone = $this->getZone((int)$this->config->get('config_zone_id'));
}
if (!$zone) {
return array();
}
$country_query = $this->db->query("SELECT name FROM " . DB_PREFIX . "country WHERE country_id = '" . (int)$zone['country_id'] . "' LIMIT 1");
$country = $country_query->num_rows ? $country_query->row['name'] : '';
$replacements = array(
'{_REGION_}' => $zone['name'],
'{_GOROD_}' => $zone['name'],
'{_GORODU_}' => $zone['name'],
'{_GORODOM_}' => $zone['name'],
'{_STRANA_}' => $country,
'{_STRANU_}' => $country,
'{_STRANOI_}' => $country,
'{_STRANE_}' => $country,
'{_STRANY_}' => $country
);
foreach (array('gorod', 'gorodu', 'gorodom', 'strana', 'stranu', 'stranoi', 'strane', 'strany') as $field) {
$key = 'replacement_' . $field;
if (isset($zone[$key]) && trim((string)$zone[$key]) !== '') {
$replacements['{_' . strtoupper($field) . '_}'] = $zone[$key];
}
}
return $replacements;
}
public function getZoneUrl($zone_id, $url) {
$zone = $this->getZone($zone_id);
@@ -11,16 +11,14 @@
<div><a href="mailto:{{ config_email }}">{{ config_email }}</a></div>
<div>{{ config_address }}</div>
</div>
{% if informations %}
<div class="col-12">
<div class="row g-3 justify-content-center">
<div class="col-auto"><a href="{{ contact }}">{{ text_contacts }}</a></div>
{% for information in informations %}
<div class="col-auto"><a href="{{ information.href }}">{{ information.title }}</a></div>
{% endfor %}
</div>
</div>
{% endif %}
</div>
</div>
</footer>
@@ -33,4 +31,4 @@
<script src="{{ script }}" type="text/javascript"></script>
{% endfor %}
<script src="store/view/theme/dominik/assets/js/script.js"></script>
</body></html>
</body></html>
+3 -2
View File
@@ -35,7 +35,8 @@ $_['action_pre_action'] = array(
'startup/error',
'startup/event',
'startup/maintenance',
'startup/seo_url'
'startup/seo_url',
'startup/region_replacement'
);
// Action Events
@@ -59,4 +60,4 @@ $_['action_event'] = array(
//'controller/*/after' => array(
// 'event/debug/after'
// )
);
);
+7 -1
View File
@@ -14,6 +14,7 @@ class Response {
private $headers = array();
private $level = 0;
private $output;
private $replacements = array();
/**
* Constructor
@@ -63,6 +64,10 @@ class Response {
public function setOutput($output) {
$this->output = $output;
}
public function setReplacements($replacements) {
$this->replacements = is_array($replacements) ? $replacements : array();
}
/**
*
@@ -107,7 +112,8 @@ class Response {
*/
public function output() {
if ($this->output) {
$output = $this->level ? $this->compress($this->output, $this->level) : $this->output;
$output = $this->replacements ? strtr($this->output, $this->replacements) : $this->output;
$output = $this->level ? $this->compress($output, $this->level) : $output;
if (!headers_sent()) {
foreach ($this->headers as $header) {