Здравствуйте! Реализовал в дефолтном шаблоне отображение статей в шапке (header) 1. В БД в таблице information создал столбец top по аналогии с bottom. Код: ALTER TABLE `prefix_information` ADD `top` INT(1) NOT NULL DEFAULT '0' AFTER `information_id`; 2. В файле admin/controller/catalog/information.php перед if (isset($this->request->post['bottom'])) { добавил Код: if (isset($this->request->post['top'])) { $data['top'] = $this->request->post['top']; } elseif (!empty($information_info)) { $data['top'] = $information_info['top']; } else { $data['top'] = 0; } 3. В файле admin/language/ru-ru/catalog/information.php добавил Код: $_['entry_top'] = 'Показывать в хедере'; $_['help_top'] = 'Показывать в хедере \ шапке магазина'; 4. В файле admin/model/catalog/information.php добавил перед $this->db->query("INSERT INTO " . DB_PREFIX . "information SET sort_order = '" . (int)$data['sort_order'] . "', bottom = '" Код: $this->db->query("INSERT INTO " . DB_PREFIX . "information SET sort_order = '" . (int)$data['sort_order'] . "', top = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', status = '" . (int)$data['status'] . "', noindex = '" . (int)$data['noindex'] . "'"); Перед $this->db->query("UPDATE " . DB_PREFIX . "information SET sort_order = '" . (int)$data['sort_order'] . "', bottom = '" Код: $this->db->query("UPDATE " . DB_PREFIX . "information SET sort_order = '" . (int)$data['sort_order'] . "', top = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', status = '" . (int)$data['status'] . "', noindex = '" . (int)$data['noindex'] . "' WHERE information_id = '" . (int)$information_id . "'"); 5. В файле admin/view/template/catalog/information_form.twig перед <label class="col-sm-2 control-label" for="input-bottom"><span data-toggle="tooltip" title="{{ help_bottom }}">{{ entry_bottom }}</span></label> добавил Код: <label class="col-sm-2 control-label" for="input-top"><span data-toggle="tooltip" title="{{ help_top }}">{{ entry_top }}</span></label> <div class="col-sm-10"> <div class="checkbox"> <label>{% if top %} <input type="checkbox" name="top" value="1" checked="checked" id="input-top" /> {% else %} <input type="checkbox" name="top" value="1" id="input-top" /> {% endif %} </label> </div> </div> </div> <div class="form-group"> 6. В файле catalog/controller/common/header.php после $this->load->language('common/header'); Код: $this->load->model('catalog/information'); $data['informations'] = array(); foreach ($this->model_catalog_information->getInformations() as $result) { if ($result['top']) { $data['informations'][] = array( 'title' => $result['title'], 'href' => $this->url->link('information/information', 'information_id=' . $result['information_id']) ); } } 7. В файле catalog/language/ru-ru/common/header.php добавил Код: $_['text_articles'] = 'Статьи'; 8. В файле после {{ blog_menu }} Код: {% if informations %} <div class="pull-left"> <div class="btn-group"> <button class="btn btn-link dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-book"></i> <span class="hidden-xs hidden-sm hidden-md">{{ text_articles }}</span> <i class="fa fa-caret-down"></i> </button> <ul class="dropdown-menu"> {% for information in informations %} <li><a href="{{ information.href }}">{{ information.title }}</a></li> {% endfor %} </ul> </div> </div> {% endif %} Отображается отлично, но проблема в том, что когда добавляешь новую статью и ставишь в админке галочку на Показывать в хедере, она почему-то не сохраняется с 1 раза. Не могу понять в чём проблема. Большое спасибо! Opencart/OcStore 3.x
в модель admin/model/catalog/information.php надо не добавлять новый запрос INSERT / UPDATE "перед", а исправить текущий запрос, вписав top = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', перед bottom =
4. В файле admin/model/catalog/information.php заменил Код: bottom = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', на Код: top = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', bottom = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', Теперь всё работает как часы. Спасибо!
Рабочий вариант отображение статей в шапке (header) в дефолтном шаблоне 1. В БД в таблице information создал столбец top по аналогии с bottom. Код: ALTER TABLE `prefix_information` ADD `top` INT(1) NOT NULL DEFAULT '0' AFTER `information_id`; 2. В файле admin/controller/catalog/information.php перед if (isset($this->request->post['bottom'])) { добавил Код: if (isset($this->request->post['top'])) { $data['top'] = $this->request->post['top']; } elseif (!empty($information_info)) { $data['top'] = $information_info['top']; } else { $data['top'] = 0; } 3. В файле admin/language/ru-ru/catalog/information.php добавил Код: $_['entry_top'] = 'Показывать в хедере'; $_['help_top'] = 'Показывать в хедере \ шапке магазина'; 4. В файле admin/model/catalog/information.php заменил Код: bottom = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', на Код: top = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', bottom = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', 5. В файле admin/view/template/catalog/information_form.twig перед <label class="col-sm-2 control-label" for="input-bottom"><span data-toggle="tooltip" title="{{ help_bottom }}">{{ entry_bottom }}</span></label> добавил Код: <label class="col-sm-2 control-label" for="input-top"><span data-toggle="tooltip" title="{{ help_top }}">{{ entry_top }}</span></label> <div class="col-sm-10"> <div class="checkbox"> <label>{% if top %} <input type="checkbox" name="top" value="1" checked="checked" id="input-top" /> {% else %} <input type="checkbox" name="top" value="1" id="input-top" /> {% endif %} </label> </div> </div> </div> <div class="form-group"> 6. В файле catalog/controller/common/header.php после $this->load->language('common/header'); Код: $this->load->model('catalog/information'); $data['informations'] = array(); foreach ($this->model_catalog_information->getInformations() as $result) { if ($result['top']) { $data['informations'][] = array( 'title' => $result['title'], 'href' => $this->url->link('information/information', 'information_id=' . $result['information_id']) ); } } 7. В файле catalog/language/ru-ru/common/header.php добавил Код: $_['text_articles'] = 'Статьи'; 8. В файле после {{ blog_menu }} Код: {% if informations %} <div class="pull-left"> <div class="btn-group"> <button class="btn btn-link dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-book"></i> <span class="hidden-xs hidden-sm hidden-md">{{ text_articles }}</span> <i class="fa fa-caret-down"></i> </button> <ul class="dropdown-menu"> {% for information in informations %} <li><a href="{{ information.href }}">{{ information.title }}</a></li> {% endfor %} </ul> </div> </div> {% endif %}
И я свои 5 вставлю..)) Последний пункт имелось в виду в файле по пути: Код: /catalog/view/theme/default/template/common/header.twig Проверил. Всё работает. Спасибо автору