I want to add attributes in products on the category.tpl page. I found answers only for previous opencart versions. But in this one it doesn't work:
- in /catalog/model/catalog/product.php replaced the contents to
"public function getProductAttributes($product_id) {",
public function getProductAttributesnocat($product_id) {
$product_attribute_data = array();
$product_attribute_query = $this->db->query("SELECT a.attribute_id, ad.name, pa.text FROM " . DB_PREFIX . "product_attribute pa LEFT JOIN " . DB_PREFIX . "attribute a ON (pa.attribute_id = a.attribute_id) LEFT JOIN " . DB_PREFIX . "attribute_description ad ON (a.attribute_id = ad.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 a.sort_order, ad.name");
foreach ($product_attribute_query->rows as $product_attribute) {
$product_attribute_data[] = array(
'attribute_id' => $product_attribute['attribute_id'],
'name' => $product_attribute['name'],
'text' => $product_attribute['text']
);
}
return $product_attribute_data;
}
- in /catalog/controller/product/category.php after
$data['products'][] = array(
added
'attribute' => $this->model_catalog_product->getProductAttributes($result['product_id']),
- in /catalog/view/my_theme/default/template/product/category.tpl before
<?php if ($product['rating']) { ?>
added
<?php if ($product['attribute']) { ?>
<?php foreach ($product['attribute'] as $attribute) { ?>
<span><?php echo $attribute['name']; ?>:</span> <?php echo $attribute['text']; ?><br />
<?php } ?>
<?php } ?>
As result opencart said:
Notice: Undefined index: attribute in .../catalog/view/theme/my_theme/template/product/category.tpl on line 127
But I'm not strong in php. Will be very appreciate, if you can help.