Answer the question
In order to leave comments, you need to log in
How to display attributes in the product card in the catalog?
Good afternoon!
Essence of the question: products are displayed on the category page in opencart 3 - we decided to add their attributes to the product cards.
But a problem arose - the attributes of one product are loaded and shown in all, when filtering (JS is triggered), the attributes are updated (apparently the next product_id is taken) and again all the products have the same attributes - but in fact they are naturally different.
I understand that the problem is that there is not enough cycle inside the product by attributes, but no matter how much I tried, nothing happened.
Tell me what to add and register please!
HTML code (simplified):
{% if products %}
{% for product in products %}
<div class="product-details">
<div class="dop_atr">
{% if product.product_atributes %}
{% for product_atribute in product.product_atributes %}
{{ product_atribute.name }}: {{ product_atribute.text }}.
{% endfor %}
{% endif %}
</div>
</div>
{% endfor %}
{% endif %}
//products
$data['products'] = array();
...
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
...
$product_atributes = $this->model_catalog_product->getProductCatAttributes($result['product_id']);
$data['products'][] = array(
'product_id' => $result['product_id'],
'product_atributes' => $product_atributes,
...
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);
}
public function getProductCatAttributes($product_id) {
$query = $this->db->query("SELECT ad.name, pa.text FROM " . DB_PREFIX . "product_attribute pa LEFT JOIN " . DB_PREFIX . "attribute_description ad ON (ad.attribute_id = pa.attribute_id) WHERE pa.product_id = '" . (int)$product_id . "' AND ad.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pa.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ad.name");
return $query->rows;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question