1. 在产品页显示一定数量的同类随机产品
在includes\templates\你的模板\templates\创建你的文件tpl_modules_product_info_similar.php 写入代码
[php]
<div id="similar_product">
<div class="headtitle"><h2>Customers who bought this product also purchased…</h2></div>
<div class="similar_content">
<ul>
<?php $products_id = (int)$_GET[‘products_id’];
$flash_page_id_con = array();
$flash_page_images_con = array();
$flash_page_price_con = array();
$flash_page_name_con = array();
$flash_page_query = "select p.products_id, p.products_image, pd.products_name from " . TABLE_PRODUCTS ." p, ". TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id AND pd.language_id = " . (int)$_SESSION[‘languages_id’] . " AND p.master_categories_id = " . zen_get_products_category_id($products_id) . " ORDER BY rand() limit 10";
$flash_page = $db->Execute($flash_page_query);
while(!$flash_page->EOF){
$flash_page_items[] = $flash_page->fields;
$flash_page_id_con[] = $flash_page->fields[‘products_id’];
$flash_page_images_src = is_int(strpos($flash_page->fields[‘products_image’],’,’))? substr($flash_page->fields[‘products_image’],0,strpos($flash_page->fields[‘products_image’],’,’)):$flash_page->fields[‘products_image’];
$flash_page_images_con[] = ‘"’.(zen_not_null($flash_page->fields[‘products_image’]) ? $flash_page_images_src : PRODUCTS_IMAGE_NO_IMAGE ).’"’;
$flash_page_price_con[] = ‘"’.$currencies->display_price(zen_get_products_base_price($flash_page->fields[‘products_id’]),zen_get_tax_rate($product_check->fields[‘products_tax_class_id’])).’"’;
$flash_page_name_con[] = ‘"’.zen_output_string(zen_get_products_name($flash_page->fields[‘products_id’])).’"’;
$flash_page->MoveNext();
}
$flash_page_id = implode(",", $flash_page_id_con);
$flash_page_images = implode(",", $flash_page_images_con);
$flash_page_price = implode(",", $flash_page_price_con);
$flash_page_name = implode(",", $flash_page_name_con);
$flash_page_display_num = $flash_page->RecordCount();
?>
<?php for($i = 0; $i< $flash_page_display_num ; $i++){?>
<li class="item li<?php echo $i;?><?php echo ($i%5 == 0)?’ first’:”?>">
<div class="s_product">
<div class="product-image">
<a href="<?php echo zen_href_link(zen_get_info_page($flash_page_items[$i][‘products_id’]), ‘products_id=’ . $flash_page_items[$i][‘products_id’]);?>"><?php echo zen_image(DIR_WS_IMAGES . $flash_page_items[$i][‘products_image’], $flash_page_items[$i][‘products_name’], 160, 160); ?></a>
</div>
<p class="productname"><a href="<?php echo zen_href_link(zen_get_info_page($flash_page_items[$i][‘products_id’]), ‘products_id=’ . $flash_page_items[$i][‘products_id’]);?>"><?php echo $flash_page_items[$i][‘products_name’]; ?></a></p>
<div class="price-box"><?php echo zen_get_products_display_price($flash_page_items[$i][‘products_id’]); ?></div>
</div>
</li>
<?php
//print_r($flash_page_items[$i]);
if($i%5 == 4){
echo ‘<br class="clearBoth" />’;
}
}
?>
</ul>
</div>
</div>
[/php]
即可
直接下载地址 http://vdisk.weibo.com/s/trcLFSjm5yIn
找到includes\templates\你的模板\templates\tpl_product_info_display.php文件
在相应的位置加上以下代码:
[php]<?php require($template->get_template_dir(‘tpl_modules_product_info_similar.php’,DIR_WS_TEMPLATE, $current_page_base,’templates’). ‘/tpl_modules_product_info_similar.php’);?>[/php]
2. 通过修改also purchased来显示一定数量产品
找到includes\classes\db\mysql\define_queries.php文件,修改SQL_ALSO_PURCHASED的sql语句来显示产品
把
[php]
DEFINE(‘SQL_ALSO_PURCHASED’, "select p.products_id, p.products_image
from " . TABLE_ORDERS_PRODUCTS . " opa, " . TABLE_ORDERS_PRODUCTS . " opb, "
. TABLE_ORDERS . " o, " . TABLE_PRODUCTS . " p
where opa.products_id = ‘%s’
and opa.orders_id = opb.orders_id
and opb.products_id != ‘%s’
and opb.products_id = p.products_id
and opb.orders_id = o.orders_id
and p.products_status = 1
group by p.products_id
order by o.date_purchased desc
limit " . MAX_DISPLAY_ALSO_PURCHASED);
[/php]
替换成
[php]
DEFINE(‘SQL_ALSO_PURCHASED’, "SELECT products.products_image, products.products_price,
products_description.products_name, products.products_date_added, products.products_id FROM products
Inner Join products_description ON products.products_id = products_description.products_id ORDER BY
products.products_date_added DESC,rand() LIMIT 8");
[/php]
如有好的方法可以贴出来一起学习
发表评论