我想在category.tpl頁面的產品中添加屬性。 我只爲以前的opencart版本找到答案。但在這一個它不工作:category.tpl中的Opencart 2.0屬性頁面
- 在/catalog/model/catalog/product.php 更換內容
"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(
添加
'attribute' => $this->model_catalog_product->getProductAttributes($result['product_id']),
- 在/catalog/view/my_theme/default/template/product/category.tpl 前
<?php if ($product['rating']) { ?>
添加
<?php if ($product['attribute']) { ?>
<?php foreach ($product['attribute'] as $attribute) { ?>
<span><?php echo $attribute['name']; ?>:</span> <?php echo $attribute['text']; ?><br />
<?php } ?>
<?php } ?>
作爲結果Opencart的說:
注意:未定義指數:屬性在... /目錄/視圖/主題/ my_theme /模板/產品/上線category.tpl 127
但我不強大的PHP。將非常感謝,如果你能幫助。
我安裝vqmod和遵循指令顯示類產品
更多細節和演示屬性。唉。 注意:未定義的索引:/ home/m/marsha/sun/public_html/vqmod/vqcache/vq2-catalog_view_theme_coloring_template_product_category中的attribute_groups。第112行的tpl 第112行:<?php if($ product ['attribute_groups']){?> – Loloka
這意味着在目錄/ controller/product/category.php中沒有添加 'attribute_groups'=> $ this-> model_catalog_product-> getProductAttributes($ result ['product_id']), 將以上行添加到category.php –
的產品數組中,然後再次嘗試,但它沒有工作https://www.evernote.com/shard/s76/sh/deddc369-ee4f-4a11-ab8e-b58e9d551dbb/98bff9caf5da85782f85eb3411126119 – Loloka