A-A+
ecshop商品属性按照ID进行排列
客户在添加商品属性时,发现其属性不是按照最新添加的来排序,也就是最新 ID 来排序的,实际是在 ecshop 默认的排序列表中没有指定(属性ID)来排序所导致的问题了,下面夏日博客就给解决一下这个问题,这里参照的是 ecshop 的默认模板了。
首先打开 /includes/lib_goods.php,修改如下的代码,注意红色添加的 order by 代码部分.
- /* 获得商品的规格 */
- $sql = "SELECT a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type, ".
- "g.goods_attr_id, g.attr_value, g.attr_price " .
- 'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
- 'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
- "WHERE g.goods_id = '$goods_id' " .
- 'ORDER BY g.goods_attr_id, a.sort_order, g.attr_price'; //红色排序部分
- $res = $GLOBALS['db']->getAll($sql);
另外还有一种情况就是我们在复制商品属性的时候,商品属性会跟原商品相反。
修改/inclues/lib_goods.php
- /**
- * 取得商品属性
- * @param int $goods_id 商品id
- * @return array
- */
- function get_goods_attr($goods_id)
- {
- $attr_list = array();
- $sql = "SELECT a.attr_id, a.attr_name " .
- "FROM " . $GLOBALS['ecs']->table('goods') . " AS g, " . $GLOBALS['ecs']->table('attribute') . " AS a " .
- "WHERE g.goods_id = '$goods_id' " .
- "AND g.goods_type = a.cat_id " .
- "AND a.attr_type = 1".' ORDER BY a.attr_id';
- $attr_id_list = $GLOBALS['db']->getCol($sql);
- $res = $GLOBALS['db']->query($sql);
- while ($attr = $GLOBALS['db']->fetchRow($res))
- {
- if (defined('ECS_ADMIN'))
- {
- $attr['goods_attr_list'] = array(0 => $GLOBALS['_LANG']['select_please']);
- }
- else
- {
- $attr['goods_attr_list'] = array();
- }
- $attr_list[$attr['attr_id']] = $attr;
- }
- $sql = "SELECT attr_id, goods_attr_id, attr_value " .
- "FROM " . $GLOBALS['ecs']->table('goods_attr') .
- " WHERE goods_id = '$goods_id' " .
- "AND attr_id " . db_create_in($attr_id_list).' ORDER BY goods_attr_id';
- $res = $GLOBALS['db']->query($sql);
- while ($goods_attr = $GLOBALS['db']->fetchRow($res))
- {
- $attr_list[$goods_attr['attr_id']]['goods_attr_list'][$goods_attr['goods_attr_id']] = $goods_attr['attr_value'];
- }
- return $attr_list;
- }
同样注意 .' ORDER BY goods_attr_id' 这一句,是把排序进行了固定。