ecshop 单位显示 首页单位显示 商品详细页面 单位显示
2015-10-26 17:21
537 查看
ecshop 单位显示 首页单位显示 商品详细页面 单位显示
1,单位 控制在 分类中, {$goods.measure_unit}
2 如果使用属性里面的单位 比较复杂
3 首页显示单位的时候,,涉及到的文件 libaray/recommend_hot.lbi
4 首页显示单位的时候,,涉及到的静态缓存
/temp/static_caches
静态缓存只保存goods_id ,和sort_order,其他信息再重读读取数据库的数据
具体看get_recommend_goods()函数
5 因为首页涉及到页面比较多。。请到cache查看index.dwt.php看编译好的文件,然后修改对应的文件 添加 {$goods.measure_unit}
分类页面的修改
模板goods_list.lbi 注意要改2处 display : text 和grid
<!-- {if $show_marketprice} -->
{$lang.market_price}<font class="market">{$goods.market_price}/{$goods.measure_unit}</font><br />
<!-- {/if} -->
<!--{if $goods.promote_price neq "" } -->
{$lang.promote_price}<font class="shop">{$goods.promote_price}/{$goods.measure_unit}</font><br />
<!--{else}-->
{$lang.shop_price}<font class="shop">{$goods.shop_price}/{$goods.measure_unit}</font><br />
<!--{/if}-->
category.php
修改函数
/**
* 获得分类下的商品
*
* @access public
* @param string $children
* @return array
*/
function category_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 <= $max ";
}
/* 获得商品列表 modified by yanggg*/
$sql = 'SELECT c.measure_unit,g.goods_id, g.goods_name, g.goods_name_style, g.comments_number,g.sales_volume,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('category') . ' AS c ON g.cat_id = c.cat_id ' .
'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);
if($_GET['debug']){
var_dump($sql);
}
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$arr[$row['goods_id']]['measure_unit'] = $row['measure_unit']; //
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']]['name'] = $row['goods_name'];
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
$arr[$row['goods_id']]['sales_volume'] = $row['sales_volume'];
$arr[$row['goods_id']]['comments_number'] = $row['comments_number'];
/* 折扣节省计算 by ecmoban start */
if($row['market_price'] > 0)
{
$discount_arr = get_discount($row['goods_id']); //函数get_discount参数goods_id
}
$arr[$row['goods_id']]['zhekou'] = $discount_arr['discount']; //zhekou
$arr[$row['goods_id']]['jiesheng'] = $discount_arr['jiesheng']; //jiesheng
/* 折扣节省计算 by ecmoban end */
$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']);
}
return $arr;
}
1,单位 控制在 分类中, {$goods.measure_unit}
2 如果使用属性里面的单位 比较复杂
3 首页显示单位的时候,,涉及到的文件 libaray/recommend_hot.lbi
4 首页显示单位的时候,,涉及到的静态缓存
/temp/static_caches
静态缓存只保存goods_id ,和sort_order,其他信息再重读读取数据库的数据
具体看get_recommend_goods()函数
5 因为首页涉及到页面比较多。。请到cache查看index.dwt.php看编译好的文件,然后修改对应的文件 添加 {$goods.measure_unit}
<?php $data = array ( 'best' => array ( 'goods_id' => '353', 'sort_order' => '100', ), 'new' => array ( ), 'hot' => array ( ), 'brand' => array ( 353 => '泉品尚', 351 => '泉品尚', ), ); ?>
/** * 获得推荐商品 * * @access public * @param string $type 推荐类型,可以是 best, new, hot * @return array */ function get_recommend_goods($type = '', $cats = '') { //if($_GET['debug']) die($type); if (!in_array($type, array('best', 'new', 'hot'))) { return array(); } //取不同推荐对应的商品 static $type_goods = array(); if (empty($type_goods[$type])) { //初始化数据 $type_goods['best'] = array(); $type_goods['new'] = array(); $type_goods['hot'] = array(); $data = read_static_cache('recommend_goods'); if ($data === false) { $sql = 'SELECT c.measure_unit,g.goods_id, g.is_best, g.is_new, g.is_hot, g.is_promote, b.brand_name,g.sort_order ' . ' FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON g.cat_id = c.cat_id ' . ' LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . ' WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND (g.is_best = 1 OR g.is_new =1 OR g.is_hot = 1)'. ' ORDER BY g.sort_order, g.last_update DESC'; $goods_res = $GLOBALS['db']->getAll($sql); //定义推荐,最新,热门,促销商品 $goods_data['best'] = array(); $goods_data['new'] = array(); $goods_data['hot'] = array(); $goods_data['brand'] = array(); if (!empty($goods_res)) { foreach($goods_res as $data) { if ($data['is_best'] == 1) { $goods_data['best'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']); } if ($data['is_new'] == 1) { $goods_data['new'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']); } if ($data['is_hot'] == 1) { $goods_data['hot'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']); } if ($data['brand_name'] != '') { $goods_data['brand'][$data['goods_id']] = $data['brand_name']; } } } write_static_cache('recommend_goods', $goods_data); } else { $goods_data = $data; } $time = gmtime(); $order_type = $GLOBALS['_CFG']['recommend_order']; //按推荐数量及排序取每一项推荐显示的商品 order_type可以根据后台设定进行各种条件显示 static $type_array = array(); $type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot'); if (empty($type_array)) { foreach($type2lib as $key => $data) { if (!empty($goods_data[$key])) { $num = get_library_number($data); $data_count = count($goods_data[$key]); $num = $data_count > $num ? $num : $data_count; if ($order_type == 0) { //usort($goods_data[$key], 'goods_sort'); $rand_key = array_slice($goods_data[$key], 0, $num); foreach($rand_key as $key_data) { $type_array[$key][] = $key_data['goods_id']; } } else { $rand_key = array_rand($goods_data[$key], $num); if ($num == 1) { $type_array[$key][] = $goods_data[$key][$rand_key]['goods_id']; } else { foreach($rand_key as $key_data) { $type_array[$key][] = $goods_data[$key][$key_data]['goods_id']; } } } } else { $type_array[$key] = array(); } } } //取出所有符合条件的商品数据,并将结果存入对应的推荐类型数组中 $sql = 'SELECT c.measure_unit,g.goods_id, g.goods_name, g.goods_name_style, g.comments_number, g.sales_volume, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, RAND() AS rnd " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON g.cat_id = c.cat_id ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' "; $type_merge = array_merge($type_array['new'], $type_array['best'], $type_array['hot']); $type_merge = array_unique($type_merge); $sql .= ' WHERE g.goods_id ' . db_create_in($type_merge); $sql .= ' ORDER BY g.sort_order, g.last_update DESC'; //modified by yanggg if($_GET['debug']) var_dump($sql); $result = $GLOBALS['db']->getAll($sql); foreach ($result AS $idx => $row) { if($_GET['debug']) var_dump($row); if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } /* 折扣节省计算 by ecmoban start */ if($row['market_price'] > 0) { $discount_arr = get_discount($row['goods_id']); //函数get_discount参数goods_id } $goods[$idx]['zhekou'] = $discount_arr['discount']; //zhekou $goods[$idx]['jiesheng'] = $discount_arr['jiesheng']; //jiesheng /* 折扣节省计算 by ecmoban end */ //modified by yanggg 2015 10 25 $goods[$idx]['measure_unit'] = $row['measure_unit']; $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['comments_number'] = $row['comments_number']; $goods[$idx]['sales_volume'] = $row['sales_volume']; $goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : ''; $goods[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']); $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); if (in_array($row['goods_id'], $type_array['best'])) { $type_goods['best'][] = $goods[$idx]; } if (in_array($row['goods_id'], $type_array['new'])) { $type_goods['new'][] = $goods[$idx]; } if (in_array($row['goods_id'], $type_array['hot'])) { $type_goods['hot'][] = $goods[$idx]; } } } return $type_goods[$type]; }
分类页面的修改
模板goods_list.lbi 注意要改2处 display : text 和grid
<!-- {if $show_marketprice} -->
{$lang.market_price}<font class="market">{$goods.market_price}/{$goods.measure_unit}</font><br />
<!-- {/if} -->
<!--{if $goods.promote_price neq "" } -->
{$lang.promote_price}<font class="shop">{$goods.promote_price}/{$goods.measure_unit}</font><br />
<!--{else}-->
{$lang.shop_price}<font class="shop">{$goods.shop_price}/{$goods.measure_unit}</font><br />
<!--{/if}-->
category.php
修改函数
/**
* 获得分类下的商品
*
* @access public
* @param string $children
* @return array
*/
function category_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 <= $max ";
}
/* 获得商品列表 modified by yanggg*/
$sql = 'SELECT c.measure_unit,g.goods_id, g.goods_name, g.goods_name_style, g.comments_number,g.sales_volume,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('category') . ' AS c ON g.cat_id = c.cat_id ' .
'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);
if($_GET['debug']){
var_dump($sql);
}
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$arr[$row['goods_id']]['measure_unit'] = $row['measure_unit']; //
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']]['name'] = $row['goods_name'];
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
$arr[$row['goods_id']]['sales_volume'] = $row['sales_volume'];
$arr[$row['goods_id']]['comments_number'] = $row['comments_number'];
/* 折扣节省计算 by ecmoban start */
if($row['market_price'] > 0)
{
$discount_arr = get_discount($row['goods_id']); //函数get_discount参数goods_id
}
$arr[$row['goods_id']]['zhekou'] = $discount_arr['discount']; //zhekou
$arr[$row['goods_id']]['jiesheng'] = $discount_arr['jiesheng']; //jiesheng
/* 折扣节省计算 by ecmoban end */
$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']);
}
return $arr;
}
相关文章推荐
- VirtualBox安装Centos6.4不能为虚拟电脑打开一个新的任务
- 架构师知识体系(3)--系统架构管理实践
- eclipse或者SpringToolSuite里访问tomcat首页出现404错误解决之法
- Linux 常用命令
- 设计模式在C语言中的应用--读nginx源码
- PopupWindow如何右对齐
- 架构师知识体系(2)--什么是架构师
- 58同城沈剑:好的架构源于不停地衍变,而非设计
- Ubuntu下配置Tomcat服务器以及设置自动启动的方法
- 更改Tomcat startup.bat启动窗口名称
- 架构师知识体系(1)--WEB架构师成长之路
- Centos & 下Nagios的安装与配置
- 【Java Web】在Eclipse下配置Tomcat服务器
- linux打包压缩命令汇总
- linux安装nginx
- linux64 安装jpeg出错make:./libtool:Commandnotfound
- CentOS epel yum 源配置
- centos linux 上安装nginx+php的正确配置
- linux c 实现字符串替换
- 跳板机平台搭建