共享sensorforyou的基于cookie的wishlist

用于收藏精华贴子、网友共享的资料等。可以回复,不能发新贴。

版主: daimadaquan

版面规则
本版面不能发新贴,可以回复

共享sensorforyou的基于cookie的wishlist

帖子solomn » 2008-05-26 14:22

我做的这个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>&nbsp;</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'); 加入到自己的文件定义文件里

你们可以试一下
solomn
新手上路
新手上路
 
帖子: 9
注册: 2005-08-06 21:26

Re: 共享sensorforyou的基于cookie的wishlist

帖子radnows » 2008-05-27 22:53

不错 这个用作浏览历史会更好
头像
radnows
论坛版主
论坛版主
 
帖子: 3128
注册: 2005-08-09 23:57
地址: radnows.com

Re: 共享sensorforyou的基于cookie的wishlist

帖子derek » 2009-05-20 13:33

为什么我用这个代码,不是显示在左侧,而且是一排显示2个呢?我想一排显示一个!请问怎么办?
derek
新手上路
新手上路
 
帖子: 14
注册: 2009-05-17 19:21

Re: 共享sensorforyou的基于cookie的wishlist

帖子bindy1986 » 2010-07-13 11:37

怎么我的总提示我“Sorry! You haven't add any products in your Wishlist!”?
加入到商品也得 不是“add to wishlist”么?
各部分按钮的功能也没搞明白,
希望可以有个使用说明之类的。
头像
bindy1986
中级会员
中级会员
 
帖子: 95
注册: 2010-02-24 10:52
QQ 帐号: 59914465


回到 精华共享

在线用户

正在浏览此版面的用户:没有注册用户 和 0 位游客