A
A
Alpha122019-08-06 16:33:53
opencart
Alpha12, 2019-08-06 16:33:53

How to display the category name in the product card?

Opencart 3 is like this. you need to enter the name of the category in the product card. Tried so
in the model added

public function getCategoryNames($product_id) {     
        $query = $this->db->query("SELECT cd.name
                        FROM " . DB_PREFIX . "category_description cd
                        LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p2c.category_id = cd.category_id)
                            WHERE p2c.product_id = '" . (int)$product_id . "'
                            AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "'");     
        return $query->rows;
    }

In controller after Added
$data['points'] = $product_info['points'];
/add_cat_list_baco
       $data['cat_list'] = $this->model_catalog_product->getCategoryNames($product_id);
//EOF_add_cat_list_baco

In the template I output like this
{% if catlist %}
                {% for catlist in catname %}
                    <li>{{% catname.name %}}</li>
                {% endfor %}
{% endif %}

I update the modifier cache, go to the product card, and there is a twig error
Mistake

Fatal error: Uncaught Twig_Error_Syntax: Unexpected token "operator" of value "%" in "basecart/template/product/product.twig" at line 124. in /home/a0289328/domains/turbach.ru/public_html/system/library/template/Twig/ExpressionParser.php:190 Stack trace: #0 /home/a0289328/domains/turbach.ru/public_html/system/library/template/Twig/ExpressionParser.php(84): Twig_ExpressionParser->parsePrimaryExpression() #1 /home/a0289328/domains/turbach.ru/public_html/system/library/template/Twig/ExpressionParser.php(41): Twig_ExpressionParser->getPrimary() #2 /home/a0289328/domains/turbach.ru/public_html/system/library/template/Twig/Parser.php(144): Twig_ExpressionParser->parseExpression() #3 /home/a0289328/domains/turbach.ru/public_html/system/library/template/Twig/TokenParser/For.php(40): Twig_Parser->subparse(Array) #4 /home/a0289328/domains/turbach.ru/public_html/system/library/template/Twig/Parser.php(187): Twig_TokenParser_For->parse(Object(Twig_Token)) #5 /home/a0289328/domains/turbach.ru/public_html/system/library/template/Twig/T in /home/a0289328/domains/turbach.ru/public_html/system/library/template/Twig/ExpressionParser.php on line 190


What am I doing wrong ? Tell me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Polos, 2019-08-06
@Alpha12

{{ catname.name }}
I haven't looked at the rest of the code, I think everything seems to be ok.
Error - extra%.
UPD: for catlist in catname, now you need to use catlist in the loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question