2012-06-08 16 views
-1

我有一個打開的購物車網站,在一個頁面上顯示所有產品(如果用戶選擇查看此頁面)。我試圖將它按受歡迎程度進行排序,僅限於1個特定的產品類別(類別ID:23),而不是根據最新添加的內容進行排序。分類頁面按人氣排序(PHP + Opencart)

我知道Opencart已經具有嵌入式熱門功能,因爲您可以在管理部分中查看報告,以查看最多以及最購買的報告。

查看分類頁面下:

<?php echo $header; ?> 

<div id="content"> 
    <div class="top"> 
    <div class="left"></div> 
    <div class="right"></div> 
    <div class="center"> 
    <?php if (trim($heading_title)=="Kippahs"){$heading_title="Kippah Gallery";} ?> 
    <?php if (trim($heading_title)=="Wedding Glass Art"){$heading_title="Wedding Glass Gallery";} ?> 
    <?php if (trim($heading_title)=="Judaic Art"){$heading_title="Judaica Art Gallery";} ?> 
    <?php if (trim($heading_title)=="Artist"){$heading_title="Meet Our Artists";} ?> 
    <?php if (trim($heading_title)=="Ketubahs"){$heading_title="Scroll Down to View All Our Ketubahs on One Page";} ?> 

<?php if($_SERVER['QUERY_STRING']=='_route_=all-our-ketubot/' || substr($_SERVER['QUERY_STRING'],0,23)=='_route_=all-our-ketubot' || substr($_SERVER['QUERY_STRING'],0,15)=='_route_=ketubah' || substr($_SERVER['QUERY_STRING'],0,24)=='_route_=meet-our-artists' || substr($_SERVER['QUERY_STRING'],0,24)=='_route_=our-most-amazing' || substr($_SERVER['QUERY_STRING'],0,24)=='_route_=the-interfaith-k'){ ?> 
    <script type="text/javascript"> 
     <!-- 
     function MM_jumpMenu(targ,selObj,restore){ //v3.0 
     eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 
     if (restore) selObj.selectedIndex=0; 
     } 
     //--> 
    </script> 


<?php include("selector.php"); ?> 


<?php } ?> 

<div style="width:800px;"> 
     <h1><?php echo $heading_title; ?></h1> 
    </div> 
    </div> 
    </div> 
    <div class="middle"> 

    <table style="margin-top:-35px;margin-bottom:0px;padding:10px;"> 
     <tr> 
     <?php 
    if($_SERVER['QUERY_STRING']!='_route_=ketubahs'){ 
    ?> 
     <?php if ($thumb) { ?> 
     <td><img class="catimg" src="<?php echo $thumb; ?>" alt="<?php echo $heading_title; ?>" width="150" height="150" /></td>  
     <?php } 
                } 
     ?> 
     <?php if ($description) { ?> 
     <td valign="top" class="headcat"><?php echo $description; ?></td> 
     <?php } ?> 
     </tr> 
    </table> 


    <div class="clear">&nbsp;</div><!--[if lt IE 7]><br /><![endif]--> 
    <?php if (!$categories && !$products) { ?> 
    <div class="content"><?php echo $text_error; ?></div> 
    <?php } ?> 
    <?php 
    if($_SERVER['QUERY_STRING']!='_route_=ketubahs'){ 
    ?> 
    <!--<?php /* if ($categories) { */ ?> --> 
    <?php if ($categories && $heading_title!="Scroll Down to View All Our Ketubahs on One Page") { ?> 
    <table class="listC" cellspacing="7"> 
     <?php for ($i = 0; $i < sizeof($categories); $i = $i + 4) { 
     $numpages=sizeof($products); 
     ?> 
     <tr> 
     <?php for ($j = $i; $j < ($i + 4); $j++) { ?> 
     <td width="25%"><?php if (isset($categories[$j])) { ?> 
      <a href="<?php echo $categories[$j]['href']; ?>"><img src="<?php echo $categories[$j]['thumb']; ?>" title="<?php echo $categories[$j]['name']; ?>" alt="<?php echo $categories[$j]['name']; ?>" style="margin-bottom: 3px;" /></a><br /> 
      <a href="<?php echo $categories[$j]['href']; ?>"><?php echo $categories[$j]['name']; ?></a> 
      <?php } ?></td> 
     <?php } ?> 
     </tr> 
     <?php } ?> 
    </table> 
    <?php } 
                } 
    ?> 
    <?php if ($products) { ?> 
<!-- <div class="sort"> --> 
     <div class="sort" <?php if ($heading_title=="Scroll Down to View All Our Ketubahs on One Page") { echo "style='margin-top:-40px;'"; } ?> > 
     <div class="div1"> 
     <select name="sort" onchange="location = this.value"> 
      <?php foreach ($sorts as $sorts) { ?> 
      <?php if (($sort . '-' . $order) == $sorts['value']) { ?> 
      <option value="<?php echo $sorts['href']; ?>" selected="selected"><?php echo $sorts['text']; ?></option> 
      <?php } else { ?> 
      <option value="<?php echo $sorts['href']; ?>"><?php echo $sorts['text']; ?></option> 
      <?php } ?> 
      <?php } ?> 
     </select> 
     </div> 
     <div class="div2"><?php echo $text_sort; ?></div> 
    </div> 
    <table class="listC" cellspacing="7"> 
     <?php for ($i = 0; $i < sizeof($products); $i = $i + 4) { 
     $numpages=sizeof($products); 
     ?> 
     <tr> 
     <?php for ($j = $i; $j < ($i + 4); $j++) { ?> 
     <td width="25%"> 
<?php if (isset($products[$j])) { ?> 
       <a href="<?php echo $products[$j]['href']; ?>"><img src="<?php echo $products[$j]['thumb']; ?>" title="<?php echo $products[$j]['name']; ?>" alt="<?php echo $products[$j]['name']; ?>" width="210px" height="210px" /></a><br /><Br /> 
      <div style="margin-top:-15px;"><a href="<?php echo $products[$j]['href']; ?>"><?php echo $products[$j]['name']; ?></a><br /> 
<?php  if($products[$j]['artist'] != 'Rosenthal, Gary' and $products[$j]['artist'] != 'Jessy Judaica' and !empty($products[$j]['artist'])){ 
      $artist_fname=substr($products[$j]['artist'],strpos($products[$j]['artist'],",")+1); 
      $artist_lname=substr($products[$j]['artist'],0,strpos($products[$j]['artist'],",")); 
     $artist_fullname=trim($artist_fname)." ".trim($artist_lname); 
     if (trim($products[$j]['artist'])=="Zeev") { 
     $artist_fullname="Ze&#39;ev"; } 
     if (trim($products[$j]['artist'])=="This is not a Ketubah") { 
     $artist_fullname="This is not a Ketubah"; } 
     $artistname=str_replace(' ','-',$artist_fullname); 
     if (trim($artistname)=="Ze&#39;ev") { 
     $artistname="Ze-ev"; } 
     if (trim($artistname)=="This is not a Ketubah") { 
     $artistname="This is not a Ketubah"; } 
     $artist_path='meet-our-artists/'.strtolower($artistname); 
?> 
      <a href="<?php echo $artist_path; ?>"><span style="color:#FFF;font-weight:200;"><?php echo $artist_fullname; ?></span></a><br /> 
<?php } else { ?> 
      <span style="color: #999; font-size: 11px;"><?php echo $products[$j]['model']; ?></span><br /> 
<?php } ?> 
      <?php if ($display_price) { ?> 
      <?php if (!$products[$j]['special']) { ?> 
      <span style="color: #00d8ff; font-weight: bold;cursor:default;"><?php echo $products[$j]['price']; ?></span> 
      <?php } else { ?> 
      <span style="color: #00d8ff; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="color: #FAA; font-weight: bold;"><?php echo $products[$j]['special']; ?></span> 
      <?php } ?> 
</div> 
      <?php } ?> 
      <br /> 
      <?php if ($products[$j]['rating']) { ?> 
      <img src="catalog/view/theme/default/image/stars_<?php echo $products[$j]['rating'] . '.png'; ?>" alt="<?php echo $products[$j]['stars']; ?>" /> 
      <?php } ?> 
        <a class="cart_add" href="<?php echo $products[$j]['add']; ?>" title="<?php echo $button_add_to_cart; ?>" ><span><?php echo $button_add_to_cart; ?></span></a> 

      <?php } ?> 

      <!--<a href="<?php echo $add_to_wishlist; ?>" class="wish_add" rel="nofollow"><span><?php echo $button_to_wishlist; ?>+ Favorites</span></a>--> 

      </td> 
     <?php } ?> 
     </tr> 
     <?php } ?> 

    </table> 
    <div class="pagination" style="width:950px;text-align:right"><?php 
    if (($numpages-$ii)>1) { 
    echo "Displaying all ".($numpages-$ii)." items in this category."; 
    } else { 
    echo "Displaying 1 item in this category."; 
    } ?></div> 
     <?php } ?> 



    </div> 
    <div class="bottom"> 
    <div class="left"></div> 
    <div class="right"></div> 
    <div class="center"></div> 
    </div> 
</div> 
<?php echo $footer; ?> 

任何幫助將是驚人的!

預先感謝您

+0

什麼問題? – shadyyx

+0

爲什麼你不使用Bestseller模塊 - 從'catalog/model/catalog/product.php'使用它的'getBestsellerProducts'方法(對方法名稱不太確定)。 – shadyyx

+0

對不起,我說過這個問題:我試圖按照受歡迎程度排序,只限於1個特定的產品類別(類別ID:23),而不是目前最新增加的排序。 我需要實現哪些代碼才能使用我可以通過購買流行度排序的功能,或基於類別ID 23進行查看的功能? 我目前正在使用的打開的購物車不幸的是高度自定義,並且股票功能往往被自定義代碼忽略。這就是爲什麼我需要手動創建它。 再次提供任何幫助,然後表示讚賞。 – Andrew

回答

1

OK,我只是嘗試設置了查詢,該方法需要調用一切圍繞在你們的身上呢。

這應該是讓所有(或前10個使用LIMIT 10時)從23類產​​品通過意見下令降

SELECT p.*, pd.* 
FROM `product` p 
LEFT JOIN `product_description` pd 
    ON p.`product_id` = pd.`product_id` 
     AND pd.`language_id` = {<YOUR_LANGUAGE_ID>} 
LEFT JOIN `product_to_category` ptc 
    ON p.`product_id` = ptc.`product_id` 
     AND ptc.`category_id` = 23 
ORDER BY p.`views` DESC 
LIMIT 10 

注意:不能確定p.views列名 - 檢查查詢之前DB。

如果您想通過購買數把所有的產品:

SELECT p.*, pd.*, 
    (SELECT COUNT(op.product_id) 
     FROM `order_products` op 
     WHERE op.product_id = p.product_id 
    ) AS product_count 
FROM `product` p 
LEFT JOIN `product_description` pd 
    ON p.`product_id` = pd.`product_id` 
     AND pd.`language_id` = {<YOUR_LANGUAGE_ID>} 
LEFT JOIN `product_to_category` ptc 
    ON p.`product_id` = ptc.`product_id` 
     AND ptc.`category_id` = 23 
ORDER BY product_count DESC 
LIMIT 10 

注意:再次聲明,我不知道的order_products表名...

嘗試推出phpMyAdmin中的查詢,並讓我知道,如果他們正在工作或發佈錯誤消息,應該有任何...