php交流

2008-07-25

共享sensorforyou的最近浏览过的产品功能

归类于: zencart — admin @ 3:15 pm

很简单的一个功能,就是在产品内容页面放入一段代码,把当前的产品id放到cookie中,当检查到cookie中有相应的值时,就把他按自己的样子显示出来
1。在includes/modules/pages/product_info/header_php.php 中加入以下代码,以写cookie
if($_GET[’products_id’] != ”) {
if(!isset($_COOKIE[’product_history’]) ) {
$history_array = (int)$_GET[’products_id’];
zen_setcookie(’product_history’, $history_array, time()+60*60*24*30, ‘/’, ‘www.sensorforyou.com’);

} else {
$history_array = explode(’,',$_COOKIE[’product_history’]);
array_unshift($history_array,(int)$_GET[’products_id’]);
$history_array = array_unique($history_array);
if(count($history_array) > 6)
array_pop($history_array);
zen_setcookie(’product_history’, implode(’,',$history_array), time()+60*60*24*30, ‘/’, ‘www.sensorforyou.com’);

}

}
注意要自己把zen_setcookie函数的域名参数改为自己的域名

2。在includes/modules/sideboxes/中加入recent_view.php
<?php
if(isset($_COOKIE[’product_history’]) && $_COOKIE[’product_history’] != ”) {

$product_array = explode(’,',$_COOKIE[’product_history’]);
$products_history = array();
$row = 0;
$content = ‘</tr>’;
for($i=0;$i<count($product_array);$i++) {
$products = $db->Execute(”select p.products_image, p.products_id, pd.products_name from
“.TABLE_PRODUCTS.” p, “.TABLE_PRODUCTS_DESCRIPTION.” pd
where p.products_id = pd.products_id and p.products_id = ‘”.$product_array[$i].”‘ and p.products_status = ‘1′
and pd.language_id = ‘” . (int)$_SESSION[’languages_id’] . “‘”) ;
if($products->RecordCount() > 0){
if($row == 0)
$content .= ‘<tr><td align=”center”><a href=”‘ . zen_href_link(zen_get_info_page($products->fields[’products_id’]), ‘cPath=’ . zen_get_product_path($products->fields[’products_id’]) . ‘&products_id=’ . $products->fields[’products_id’]) . ‘”>’ . zen_image(DIR_WS_IMAGES . $products->fields[’products_image’], $products->fields[’products_name’], ‘70′, ‘70′,’border=0′) . ‘</a></td>’;
else
$content .= ‘<td align=”center”><a href=”‘ . zen_href_link(zen_get_info_page($products->fields[’products_id’]), ‘cPath=’ . zen_get_product_path($products->fields[’products_id’]) . ‘&products_id=’ . $products->fields[’products_id’]) . ‘”>’ . zen_image(DIR_WS_IMAGES . $products->fields[’products_image’], $products->fields[’products_name’], ‘70′, ‘70′,’border=0′) . ‘</a></td></tr>’;
$row++;
if($row > 1)
$row = 0;
}
}
if($row != 0)
$content .= ‘<td></td></tr>’;
$title = ‘Recent viewed’;
require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,’common’) . ‘/’ . $column_box_default);
}
?>
这里有几点要说明,首先要在后台的管理中把这个模块enable,其次请自己修改显示的样式,再次我自己修改了tpl_box_default_left.php,所以如果你们有自己的sidebox模板,请把$column_box_default改成自己的模板

没有评论 »

还没有评论。

评论 RSS Feed。 引用 URL

发表评论

基于 WordPress