我做的这个wishlist是基于cookie,加入wishlist不写入数据库,只是写在cookie里,不需要用户注册,在程序里设置cookie的生存期是一个月,大家可以自己改一下参数改变cookie的生存期。
1。includes/module/pages/下建立一个wishlist文件夹,里面包含一个header_php.php
header_php.php文件内容如下:记得要把cookie的作用域改成你自己的域名
<?php
$zco_notifier->notify('NOTIFY_HEADER_START_UNSUBSCRIBE');
require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
if($_GET['wish_id'] != ''){
if(!isset($_COOKIE['wishlist']) ) {
$wish_array = (int)$_GET['wish_id'];
zen_setcookie('wishlist', $wish_array, time()+60*60*24*30, '/', 'www.sensorforyou.com');
$_COOKIE['wishlist'] = $wish_array;
} else {
$wish_array = explode(',',$_COOKIE['wishlist']);
array_unshift($wish_array,(int)$_GET['wish_id']);
$wish_array = array_unique($wish_array);
zen_setcookie('wishlist', implode(',',$wish_array), time()+60*60*24*30, '/', 'www.sensorforyou.com');
$_COOKIE['wishlist'] = implode(',',$wish_array);
}
}
if($_POST['delete_x'] != '') {
$delete_array = $_POST['wish_id'];
$wish_array = explode(',',$_COOKIE['wishlist']);
$new_array = array();
for($i=0;$i<count($wish_array);$i++){
if(!in_array($wish_array[$i],$delete_array))
$new_array[] = $wish_array[$i];
}
$wish_array = $new_array;
zen_setcookie('wishlist', implode(',',$wish_array), time()+60*60*24*30, '/', 'www.sensorforyou.com');
$_COOKIE['wishlist'] = implode(',',$wish_array);
}
if($_POST['contact_x'] != ''){
if($_POST['wish_id'] != '') {
$wishlist_id = implode(',',$_POST['wish_id']);
zen_redirect(zen_href_link(FILENAME_CONTACT_US,'wish_id='.$wishlist_id));
}
}
if(isset($_COOKIE['wishlist'])) {
$wish_array = explode(',',$_COOKIE['wishlist']);
$wish_product_array = array();
for($i=0;$i<count($wish_array);$i++) {
$products = $db->Execute("select p.products_image, p.products_id, pd.products_name, p.products_model from
".TABLE_PRODUCTS." p, ".TABLE_PRODUCTS_DESCRIPTION." pd
where p.products_id = pd.products_id and p.products_id = '".$wish_array[$i]."' and p.products_status = '1'
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'") ;
if($products->RecordCount() > 0)
$wish_product_array[] = array('id' => $products->fields['products_id'],
'name' => $products->fields['products_name'],
'image' => $products->fields['products_image'],
'model' => $products->fields['products_model']);
}
}
$breadcrumb->add(NAVBAR_TITLE);
?>
二。在includes/template/sensor/template/下建立一个tpl_wishlist_default.php文件。我自己建立的模板叫sensor,如果自己没有建立相应的模板,可以在includes/template/template_default/template/下建立相应的tpl_wishlist_default.php文件
tpl_wishlist_default.php文件如下
<?php echo zen_draw_form('wishlist', zen_href_link(FILENAME_WISHLIST)) . "\n"; ?>
<!--eof Form start-->
<table width=770 align=center>
<tr>
<td valign=top>
<table width="570" border="0" cellpadding="0" cellspacing="2" class="mypimageBD" valign=top>
<tr>
<td valign=top width="570">
<?php
if(count($wish_product_array) > 0) {
echo '<table border="0" cellpadding="0" cellspacing="0">';
for($i=0;$i<count($wish_product_array);$i++) {
echo ' <tr><td>
<table><tr>
<td width=100 align=center>'.zen_draw_selection_field('wish_id[]','checkbox',$wish_product_array[$i]['id']).'</td>
<td width=120 align=center><a href="'.zen_href_link(zen_get_info_page($wish_product_array[$i]['id']), 'cPath=' . zen_get_product_path($wish_product_array[$i]['id']) . '&products_id=' . $wish_product_array[$i]['id']) . '">' . zen_image(DIR_WS_IMAGES . $wish_product_array[$i]['image'], $wish_product_array[$i]['name'], '100', '100','border=0') . '</a></td>
<td align=left><a href="'.zen_href_link(zen_get_info_page($wish_product_array[$i]['id']), 'cPath=' . zen_get_product_path($wish_product_array[$i]['id']) . '&products_id=' . $wish_product_array[$i]['id']) . '">' . $wish_product_array[$i]['name'].'</a></td>
</tr></table>
</td>
</tr>';
}
?>
</table>
<table border="0" cellpadding="0" cellspacing="0" height=5>
<tr><td> </td></tr>
</table>
<table border="0" cellpadding="1" cellspacing="2" class=imageBD width=100%>
<tr><td width=50% align=center><?php echo zen_image_submit(BUTTON_IMAGE_DELETE_BIG,BUTTON_DELETE_BIG_ALT,'name=delete');?></td>
<td width=50% align=center><?php echo zen_image_submit(BUTTON_IMAGE_CONTACT_ME,BUTTON_CONTACT_ME_ALT,'name=contact');?></td></tr>
</table>
</td>
</tr>
</table>
<?php
} else {
echo '<center><h3>Sorry! You haven\'t add any products in your Wishlist!</h3></center> </td>
</tr>
</table>';
}
?>
</td>
<td width=10></td>
<td width=190 valign=top>
</td>
</tr>
</table>
</form>
请注意这里的显示是sensorforyou的显示样式,你可以改变html变成自己的样式
三、在产品页面加入相应的wishlist按钮
<a href="'.zen_href_link(FILENAME_WISHLIST,'wish_id='.$_GET['products_id']).'">'.zen_image($template->get_template_dir('add_to_my_list.gif', DIR_WS_TEMPLATE, $current_page_base,'images'). '/add_to_my_list.gif', 'add to my list!','','','border="0"').'</a>'
把 define('FILENAME_WISHLIST','wishlist'); 加入到自己的文件定义文件里
你们可以试一下




News