基于ecshop的移动端 etouch实现动态获取分类商品列表
程序员文章站
2022-05-22 10:05:49
...
修改文件 category.php
关键两个地方需要修改
if ($_GET['act'] == 'asynclist') {
$sayList = array();
if (is_array($goodslist)) {
foreach ($goodslist as $vo) {
$shop_price = empty($vo['promote_price']) ? $vo['shop_price']:$vo['promote_price'];
$watermark_img = empty($vo['watermark_img']) ? '':'.$vo['goods_name'].'" />';
/* $sayList[] = array(
'pro-inner' => '
'. $shop_price .'
'.$vo['market_price'].'
月销:'.$vo['sales_count'].'
'.$watermark_img.'
'
);*/
$collectStr = '';
if($vo['collect']){
//如果已经搜藏了那么
$collectStr = '$vo['goods_id'].')">';
}else{
//如果没有搜藏那么
$collectStr = '$vo['goods_id'].')">';
}
$sayList[] = array(
'pro-inner'=>'
.$vo['goods_name'].'">
'.$vo['name'].'
'. $shop_price .'
月销:'.$vo['sales_count'].'
'.$collectStr.'
'
);
}
}
echo json_encode($sayList);
exit;
}
还有一个叫做 category_get_goods 这个函数此函数新增了一个字段 collect返回字段可以用于前端页面视图渲染的时候实现判断是否已经搜藏 并且根据是否搜藏显示不同的样式和绑定不同的事件函数
/**
* 获得分类下的商品
*
* @access public
* @param string $children
* @return array
*/functioncategory_get_goods($children, $brand, $min, $max, $ext, $size, $page, $sort, $order)
{$display = $GLOBALS['display'];
$where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ".
"g.is_delete = 0 AND ($children OR " . get_extension_goods($children) . ')';
if ($brand > 0)
{
$where .= "AND g.brand_id=$brand ";
}
if ($min > 0)
{
$where .= " AND g.shop_price >= $min ";
}
if ($max > 0)
{
$where .= " AND g.shop_price ;
}
/* 获得商品列表 */$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
"WHERE $where $ext ORDER BY $sort $order";
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
}
else
{
$promote_price = 0;
}
/* 处理商品水印图片 */$watermark_img = '';
if ($promote_price != 0)
{
$watermark_img = "watermark_promote_small";
}
elseif ($row['is_new'] != 0)
{
$watermark_img = "watermark_new_small";
}
elseif ($row['is_best'] != 0)
{
$watermark_img = "watermark_best_small";
}
elseif ($row['is_hot'] != 0)
{
$watermark_img = 'watermark_hot_small';
}
if ($watermark_img != '')
{
$arr[$row['goods_id']]['watermark_img'] = $watermark_img;
}
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
if($display == 'grid')
{
$arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
}
else
{
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
}
$arr[$row['goods_id']]['name'] = $row['goods_name'];
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
$arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
$arr[$row['goods_id']]['type'] = $row['goods_type'];
$arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : '';
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
$arr[$row['goods_id']]['sales_count'] = get_sales_volume($row['goods_id']); //显示月销量 by wangif (isset($_SESSION['user_id']) || $_SESSION['user_id'] != 0)
{
/* 检查是否已经存在于用户的收藏夹 */$sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('collect_goods') .
" WHERE user_id='$_SESSION[user_id]' AND goods_id = '".$row['goods_id']."'";
if ($GLOBALS['db']->GetOne($sql) > 0)
{
$arr[$row['goods_id']]['collect'] = 1;
}
else
{
$arr[$row['goods_id']]['collect'] = 0;
}
}else{
$arr[$row['goods_id']]['collect'] = 0;
}
}
return$arr;
}
客户端js代码参考
/* *
* 添加商品到收藏夹
*/var _current_collect = null;
var _current_goodsId = 0;
functioncollect(_this,goodsId)
{
_current_collect = _this;
_current_goodsId = goodsId;
jQuery.get('user.php?act=collect',{id:goodsId},collectResponse,"JSON");
}
functionuncollect(_this,goodsId)
{
_current_collect = _this;
_current_goodsId = goodsId;
jQuery.get('user.php?act=uncollect',{id:goodsId},collectResponse,"JSON");
}
/* *
* 处理收藏商品的反馈信息
*/functioncollectResponse(result)
{if(parseInt(result.error) === 0){
_current_collect.className = '';
_current_collect.className ="ycd-font-icon uncollect";
_current_collect.setAttribute('onclick',"uncollect(this,"+_current_goodsId+")");
_current_collect.innerHTML = '';
}
if(parseInt(result.error) === 3){
_current_collect.className = '';
_current_collect.className ="ycd-font-icon collect";
_current_collect.setAttribute('onclick',"collect(this,"+_current_goodsId+")");
_current_collect.innerHTML = '';
}
//这里加入成功//注意这里引入了一个自己写的基于zepto移动端函数库的一个插件 请参考我以前写的一篇文章里面有这个插件的代码
Zepto('body').popup({
title:'提示信息'
,id:'alert'
,closeOnOk:true
,ok:'确定',
message:result.message
});
}
总结
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });以前非常喜欢php 弄过一段时间 所以php代码也是基本上都能够看懂 mysql 也学过
没有php 基础的童鞋可以先去学学php基础
现在博主努力专研前端 后端也在学习 最近学习javascript 和 html5的新api 这些
记录下自己的工作
以上就介绍了基于ecshop的移动端 etouch实现动态获取分类商品列表,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。