在类别页面上显示产品属性 - Opencart 3
Display product attributes on category page - Opencart 3
我在 opencart 3 中创建了一个名为 'Flavour' 的属性,并希望在标题、价格、添加到购物车等每个产品的类别布局 (category.twig) 中显示此属性。是。
谢谢
在产品结果循环内的类别控制器中添加以下代码。
'attribute_groups' => $this->model_catalog_installer->getProductAttributes($result['product_id']),
然后在您的 category.twig 页面上添加以下代码以查看特定属性。
{% if product.attribute_groups %}
{% for attribute_group in product.attribute_groups %}
{% for attribute in attribute_group.attribute %}
{% if attribute.attribute_id == 14 %}
<p>Flavour: <span>{{ attribute.text }}</span></p>
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
请注意,您必须将属性循环中的 14 替换为您的确切属性 ID。您可以从管理面板的属性部分进行检查。
希望这能解决您的问题。
我在 opencart 3 中创建了一个名为 'Flavour' 的属性,并希望在标题、价格、添加到购物车等每个产品的类别布局 (category.twig) 中显示此属性。是。
谢谢
在产品结果循环内的类别控制器中添加以下代码。
'attribute_groups' => $this->model_catalog_installer->getProductAttributes($result['product_id']),
然后在您的 category.twig 页面上添加以下代码以查看特定属性。
{% if product.attribute_groups %}
{% for attribute_group in product.attribute_groups %}
{% for attribute in attribute_group.attribute %}
{% if attribute.attribute_id == 14 %}
<p>Flavour: <span>{{ attribute.text }}</span></p>
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
请注意,您必须将属性循环中的 14 替换为您的确切属性 ID。您可以从管理面板的属性部分进行检查。
希望这能解决您的问题。