2015-10-05 26 views
-2

我想在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。將非常感謝,如果你能幫助。

回答

0

雖然我建議使用VqMod,但手動可以執行以下操作: 公開目錄/控制器/產品/ category.php,找到下面的代碼:

$data['products'][] = array(
       'product_id' => $result['product_id'], 
       'thumb'  => $image, 
       'name'  => $result['name'], 
       'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..', 
       'price'  => $price, 
       'special'  => $special, 
       'tax'   => $tax, 
       'minimum'  => $result['minimum'] > 0 ? $result['minimum'] : 1, 
       'rating'  => $result['rating'], 
       'href'  => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url) 
      ); 

現在添加一行在它「attribute_groups '=> $這 - > model_catalog_product-> getProductAttributes($結果[' PRODUCT_ID']),然後產品陣列將是象下面這樣:

$data['products'][] = array(
       'product_id' => $result['product_id'], 
       'thumb'  => $image, 
       'attribute_groups'  => $this->model_catalog_product->getProductAttributes($result['product_id']), 
       'name'  => $result['name'], 
       'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..', 
       'price'  => $price, 
       'special'  => $special, 
       'tax'   => $tax, 
       'minimum'  => $result['minimum'] > 0 ? $result['minimum'] : 1, 
       'rating'  => $result['rating'], 
       'href'  => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url) 
      ); 

現在公開目錄/視圖/主題/ YOUR_THEME_FOLDER /模板/產品/ category.tpl並添加如下代碼略低於<p><?php echo $product['description']; ?></p>

<p> 
       <?php if ($product['attribute_groups']) { ?> 
      <div class="tab-pane" id="tab-specification"> 
       <table class="table table-bordered"> 
       <?php foreach ($product['attribute_groups'] as $attribute_group) { ?> 
       <thead> 
       <tr> 
        <td colspan="2"><strong><?php echo $attribute_group['name']; ?></strong></td> 
       </tr> 
       </thead> 
       <tbody> 
       <?php foreach ($attribute_group['attribute'] as $attribute) { ?> 
       <tr> 
        <td><?php echo $attribute['name']; ?></td> 
        <td><?php echo $attribute['text']; ?></td> 
       </tr> 
       <?php } ?> 
       </tbody> 
       <?php } ?> 
       </table> 
      </div> 
      <?php } ?> 
      </p> 

保存和重新加載將在 https://webocreation.com/blog/show-attributes-of-products-in-category-tpl-page-opencart-2-0

+0

我安裝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

+0

這意味着在目錄/ controller/product/category.php中沒有添加 'attribute_groups'=> $ this-> model_catalog_product-> getProductAttributes($ result ['product_id']), 將以上行添加到category.php –

+0

的產品數組中,然後再次嘗試,但它沒有工作https://www.evernote.com/shard/s76/sh/deddc369-ee4f-4a11-ab8e-b58e9d551dbb/98bff9caf5da85782f85eb3411126119 – Loloka