2013-05-29 40 views
1

我建立與Opencart的1.5.5.1一店的子類別(我是新來的吧),我遇到了一個小問題:Opencart的:那種產品將根據其在分類頁面

我的任何主要類別頁面看起來是這樣的:
精確搜索:
        -Subcategory1
        -Subcategory2
        -Subcategory3

   產品1    產品2    產品3     ...

子類別1,2和3個被鏈接到子類別頁面。

我想要什麼我的主要類別頁面是一樣的:

子類別1
產品1    產品2    產品3     .......

Subcategory2
產品1    產品2    產品3     .......

Subcategory3
產品1    產品2    產品3     .......

凡子類別1,2和3不再鏈接到子類別頁面,但簡單的文本。

我發現這個擴展:http://www.opencart.com/index.php?route=extension/extension/info&token=b4381909f29ca2d2511830b09f09fa84&extension_id=11190但也許有人可以幫我沒有我不必支付$ 15

誰能幫助我嗎?

+0

您是否安裝了自定義/新主題,或者您是否使用了默認的opencart主題? –

+0

@BIT CHEETAH - 我使用默認主題。 –

+0

@burhan - 我還沒有嘗試過那麼多。這是opencart論壇上的一些帖子,詢問同樣的事情,但沒有任何具體的答案。我嘗試從默認主題修改一些php和tpl文件,但沒有運氣。 –

回答

5

→好了,所以我會去通過一步一步來,問步驟之間的問題或最多投票這一步,如果你得到了它:

第1步:

打開以下文件:

catelog/controller/product/category.php 

首先保存這個文件的備份然後繼續進行!

某處大約第271行,你應該看到這一點:

 $this->data['categories'][] = array(

     'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''), 

     'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url) 

    ); 

更改上面的代碼:

 $this->data['categories'][] = array(

      'category_id' => $result['category_id'], /*!!!*/ 

      'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''), 

      'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url) 

    ); 

STEP 2:

打開您在步驟1中做了同樣的文件:

catelog/controller/product/category.php 

保存此文件的備份第一THEN繼續下去!

某處大約第271行,你應該看到這一點:

$this->data['categories'][] = array(

     'category_id' => $result['category_id'], /*!!!*/ 

     'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''), 

     'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url) 

    ); 

} 

/* New code will be pasted here! */ 

$this->data['products'] = array(); 

很顯然,這是我們在第1步製作的代碼,但是你的現在要做的就是複製後粘貼以下代碼最後一個'}',但在'$ this-> data ['products'] = array();'之前'

$this->data['products_all'] = array(); 

for($x = 0; $x < count($this->data['categories']); $x++) { 

    $cat = $this->data['categories'][ $x ][ 'category_id' ]; 
    $this->data['products_all'][ $cat ] = array(); 

    $data = array(
     'filter_category_id' => $cat, 
     'sort'    => $sort, 
     'order'    => $order, 
     'start'    => ($page - 1) * $limit, 
     'limit'    => $limit 
    ); 

    $product_total = $this->model_catalog_product->getTotalProducts($data); 
    $results = $this->model_catalog_product->getProducts($data); 

    foreach ($results as $result) { 

     if ($result['image']) { 
      $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')); 
     } 
     else { $image = false; } 

     if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { 
      $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))); 
     } 
     else { $price = false; } 

     if ((float)$result['special']) { 
      $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'))); 
     } 
     else { $special = false; } 

     if ($this->config->get('config_tax')) { 
      $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']); 
     } 
     else { $tax = false; }    

     if ($this->config->get('config_review_status')) { 
      $rating = (int)$result['rating']; 
     } 
     else { $rating = false; } 

     $this->data['products_all'][ $cat ][] = 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, 100) . '..', 
      'price'  => $price, 
      'special'  => $special, 
      'tax'   => $tax, 
      'rating'  => $result['rating'], 
      'reviews'  => sprintf($this->language->get('text_reviews'), (int)$result['reviews']), 
      'href'  => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id']) 

     ); 
    } 
} 

第3步:

打開以下文件:

catalog/view/theme/default/template/product/category.tpl 

保存此文件的備份第一THEN繼續下去!

地方約19行,你應該看到這一點:

<?php if ($categories) { ?> 
    <h2><?php echo $text_refine; ?></h2> 
    <div class="category-list"> 
    <?php if (count($categories) <= 5) { ?> 
    <ul> 
     <?php foreach ($categories as $category) { ?> 
     <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li> 
    <?php } ?> 
    </ul> 
    <?php } else { ?> 

更改上面的代碼:

<?php if ($categories) { ?> 

    <div class="category-list"> 

    <?php 

     if (count($categories) <= 5) { 

      foreach ($categories as $k=>$category) { 

       if($k > 0) echo '<br /><br />'; 

       echo '<div class="product-filter" style="background:#222;padding:5px;padding-bottom:2px">'; 
       echo '<a href="' . $category['href'] . '" style="font-size:21px;text-decoration:none;"><h2 style="color:#eee;font-style:italic"><span style="color:#777;position:relative;bottom:2px">&rarr;&nbsp;</span><span style="border-bottom:solid 1px #777;">' . $category['name'] . '</span>:</h2></a>'; 
       echo '</div>'; 
       echo '<hr style="border:none;border-top:solid 1px #eee"/>'; 
       echo '<div class="product-list">'; 

       foreach ($products_all[ $category['category_id'] ] as $product) 
       { 
        echo '<div>'; 
        if ($product['thumb']) { 
         echo '<div class="image"><a href="' . $product['href'] . '"><img src="' . $product['thumb'] . '" title="' . $product['name'] . '" alt="' . $product['name'] . '" /></a></div>'; 
        } 
        echo '<div class="name"><a href="' . $product['href'] . '">' . $product['name'] . '</a></div>'; 
        echo '<div class="description">' . $product['description'] . '</div>'; 
        if ($product['price']) { 
         echo '<div class="price">'; 
         if (!$product['special']) { echo $product['price']; } 
         else { echo '<span class="price-old">' . $product['price'] . '</span> <span class="price-new">' . $product['special'] . '</span>'; } 
         if ($product['tax']) { echo '<br /><span class="price-tax">' . $text_tax . ' ' . $product['tax'] . '</span>'; } 
         echo '</div>'; 
        } 
        if ($product['rating']) { 
         echo '<div class="rating"><img src="catalog/view/theme/default/image/stars-' . $product['rating'] . '.png" alt="' . $product['reviews'] . '" /></div>'; 
        } 
        echo '<div class="cart">'; 
        echo '<input type="button" value="' . $button_cart . '" onclick="addToCart(\'' . $product['product_id'] . '\');" class="button" />'; 
        echo '</div>'; 
        echo '<div class="wishlist"><a onclick="addToWishList(\'' . $product['product_id'] . '\');">' . $button_wishlist . '</a></div>'; 
        echo '<div class="compare"><a onclick="addToCompare(\'' . $product['product_id'] . '\');">' . $button_compare . '</a></div>'; 
        echo '</div>'; 
       } 
       echo '</div>'; 

      } 

     ?> 

    <?php } else { ?> 
+0

好吧,我改變了目錄/控制器/產品/ category.php中的代碼(第1步完成)。第2步? –

+0

難道你不要三次思考,並要求OP提高你的每個答案,如果他得到它有點苛刻? **你應該只回答一次,並對你的答案進行編輯。**我正在標記你的三個答案。 – shadyyx

+0

@shadyyx,不,我不這樣做,只是因爲我回答了這個問題並不意味着答案就在我的電腦上。我知道如何去做,但我必須像我那樣編寫代碼。如果我沒有把它分開,這個問題本來就沒有答案,因爲如果不知道提問者是否可以繼續並完成這項工作,我不會冒險完成整個作品。這個積極的要求是一個微不足道的激勵,我不得不幫助拉杜,這也爲他節省了15美元:我非常懷疑他會認爲我的方法「有點苛刻」。這些都是那些沒有真正適中的控制者所掌握的東西。 –

0

什麼Opencart的2?如果我喜歡你,我得到

注意:未定義抵消:60 .. \ category.tpl上線59 警告:爲的foreach()提供的參數無效.. \ category.tpl上線59

相關問題