CommerCentr
EN
Sign in

Метки, возможные ошибки

#1
Ошибка не явная, но если бы был включен strict режим для твига, то она была бы выявлена давно

{% for i in 0..tags|length %}
{% if i < (tags|length - 1) %} <a href="{{ tags.href }}">{{ tags.tag }}</a>,
{% else %} <a href="{{ tags.href }}">{{ tags.tag }}</a> {% endif %}
{% endfor %} </p>


Если есть метки

но считаются от 0

а цикл до количества

в результате

имеем

<a href=""></a>

Элемента нет

Исправляем

{% for i in 0..(tags|length - 1) %}
{% if i < (tags|length - 1) %} <a href="{{ tags.href }}">{{ tags.tag }}</a>,
{% else %} <a href="{{ tags.href }}">{{ tags.tag }}</a> {% endif %}
{% endfor %} </p>
#2
Часть вторая

В продолжение
бывает
теги (метки)
фф, ыы, вв,
последний элемент пустой
$data['tags'] = array();

if ($product_info['tag']) {
$tags = explode(',', $product_info['tag']);
foreach ($tags as $tag) {
$data['tags'][] = array(
'tag' => trim($tag),
'href' => $this->url->link('product/search', 'tag=' . trim($tag))
);
}
}


Вижу два решения
$data['tags'] = array();

if ($product_info['tag']) {
$tags = explode(',', $product_info['tag']);
$tags = array_filter($tags);
foreach ($tags as $tag) {
$data['tags'][] = array(
'tag' => trim($tag),
'href' => $this->url->link('product/search', 'tag=' . trim($tag))
);
}
}

$data['tags'] = array();

if ($product_info['tag']) {
$tags = explode(',', $product_info['tag']);
$tags = array_filter($tags);
foreach ($tags as $tag) {
if (trim($tag)) {
$data['tags'][] = array(
'tag' => trim($tag),
'href' => $this->url->link('product/search', 'tag=' . trim($tag))
);
}
}
}
#3
Три


Еще
if (isset($this->request->get['search']) || isset($this->request->get['tag'])) {



https://demo.opencart.com/index.php?route=product/search&tag=
https://demo.opencart.com/index.php?route=product/search&search=

if (!empty($this->request->get['search']) || !empty($this->request->get['tag'])) {

Т.е. пустая метка - случайно забытая запятая
И у вас есть немножко проблем
#4
по хорошему, то к вышеперечисленным фиксам, я бы добавил разделение логики поиска в модели, отлельно для тегов

Anyone can read. To post and vote, sign in.