我有一个打开的购物车网站,在一个页面上显示所有产品(如果用户选择查看此页面)。我试图按人气排序限制为1个特定产品类别(类别ID:23),而不是目前最新添加的类别。
我知道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"> </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'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'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 :(得分:1)
好的,我会尝试设置查询,你需要调用的方法,然后你就可以了。
这应该是为了获得所有(或使用LIMIT 10
时的前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
列名称 - 在查询数据库之前检查一下。
如果您希望按购买的数量获得所有产品:
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中启动查询,如果有任何问题,请告诉我它们是否有效或发布错误消息...