广州传奇网络
地址:广州市天河区东圃大马路富华楼C座
电话:13808825895
QQ:1564443073
客户想把 20包装排前面,ec默认是按照价格来排的 当然不能满足 所以我们进行修改程序。
1、
1.ALTER TABLE `ecs_goods_attr` ADD `attr_sort` VARCHAR( 10 ) NOT NULL ;
属性表加attr_sort 字段。
2、打开 admin /include/lib_goods.php 716行 改为
1.$GLOBALS['_LANG']['spec_price'].' <input type="text" name="attr_price_list[]" value="' . $val['attr_price'] . '" size="5" maxlength="10" /> 排序<input type="text" name="attr_sort[]" value="'. $val['attr_sort'].'" size="5"">' :
不难看出我们是在这个价格后面多加了一个输入框而已。 这个程序是生产属性html标签的程序。
3、admin/include/lib_goods.php 615行 改为
1.function get_attr_list($cat_id, $goods_id = 0)
2.{
3.if (empty($cat_id))
4.{
5.return array();
6.}
7.
8.// 查询属性值及商品的属性值
9.$sql = "SELECT a.attr_id, a.attr_name,v.attr_sort, a.attr_input_type, a.attr_type, a.attr_values, v.attr_value, v.attr_price ".
10."FROM " .$GLOBALS['ecs']->table('attribute'). " AS a ".
11."LEFT JOIN " .$GLOBALS['ecs']->table('goods_attr'). " AS v ".
12."ON v.attr_id = a.attr_id AND v.goods_id = '$goods_id' ".
13."WHERE a.cat_id = " . intval($cat_id) ." OR a.cat_id = 0 ".
14."ORDER BY a.sort_order, a.attr_type, a.attr_id, v.attr_price, v.goods_attr_id";
15.
16.$row = $GLOBALS['db']->GetAll($sql);
17.
18.return $row;
19.}
大家发现 我们在查询的时候要加入 v.attr_sort 这一项 就是为了 显示的时候vlaue要有值,也就是获取值。
4、我们生产了框 也有了默认值 就会出现如图效果:
显示了 我们就要插入到表中 这样我们打开admin下 goods.php
1.if(isset($_POST['attr_id_list']))
2.{
3.foreach ($_POST['attr_id_list'] AS $key => $attr_id)
4.{
5.$attr_value = $_POST['attr_value_list'][$key];
6.$attr_price = $_POST['attr_price_list'][$key];
7.$attr_sort = $_POST['attr_sort'][$key];
8.if (!empty($attr_value))
9.{
10.if (isset($goods_attr_list[$attr_id][$attr_value]))
11.{
12.// 如果原来有,标记为更新
13.$goods_attr_list[$attr_id][$attr_value]['sign'] = 'update';
14.$goods_attr_list[$attr_id][$attr_value]['attr_price'] = $attr_price;
15.$goods_attr_list[$attr_id][$attr_value]['attr_sort'] = $attr_sort;
16.}
17.else
18.{
19.// 如果原来没有,标记为新增
20.$goods_attr_list[$attr_id][$attr_value]['sign'] = 'insert';
21.$goods_attr_list[$attr_id][$attr_value]['attr_price'] = $attr_price;
22.$goods_attr_list[$attr_id][$attr_value]['attr_sort'] = $attr_sort;
23.}
24.$val_arr = explode(' ', $attr_value);
25.foreach ($val_arr AS $k => $v)
26.{
27.if (!isset($keywords_arr[$v]) && $attr_list[$attr_id] == "1")
28.{
29.$keywords_arr[$v] = $v;
30.}
31.}
32.}
33.}
34.}
35.$keywords = join(' ', array_flip($keywords_arr));
36.
37.$sql = "UPDATE " .$ecs->table('goods'). " SET keywords = '$keywords' WHERE goods_id = '$goods_id' LIMIT 1";
38.
39.$db->query($sql);
40.
41./* 插入、更新、删除数据 */
42.foreach ($goods_attr_list as $attr_id => $attr_value_list)
43.{
44.foreach ($attr_value_list as $attr_value => $info)
45.{
46.if ($info['sign'] == 'insert')
47.{
48.$sql = "INSERT INTO " .$ecs->table('goods_attr'). " (attr_id, goods_id, attr_value, attr_price,attr_sort)".
49."VALUES ('$attr_id', '$goods_id', '$attr_value', '$info[attr_price]','$info[attr_sort]')";
50.}
51.elseif ($info['sign'] == 'update')
52.{
53.$sql = "UPDATE " .$ecs->table('goods_attr'). " SET attr_price = '$info[attr_price]',attr_sort='$info[attr_sort]' WHERE goods_attr_id = '$info[goods_attr_id]' LIMIT 1";
54.}
55.else
56.{
57.$sql = "DELETE FROM " .$ecs->table('goods_attr'). " WHERE goods_attr_id = '$info[goods_attr_id]' LIMIT 1";
58.}
59.$db->query($sql);
60.}
61.}
62.}
虽然程序多 大家跟踪看看 att_sort 就明白了 ,我们照猫画虎 都要加上他。后台就这样解决。
5、既然需要排序 当然前台要修改排序方式 我们通过程序跟踪 找到 include /lib_goods.php get_goods_properties 这个函数 把过去的 'ORDER BY g.sort_order, g.attr_price, g.goods_attr_id'; 改成 'ORDER BY g.sort_order, g.attr_sort, g.goods_attr_id';
通过以上实现流程 不光让我们明白属性显示如何加入排序,更应该懂得 我们是如何二次开发的,我们可以举一反三 比如 这个排序是 图片输入框 这不就实现属性图片显示吗 ?