ecshop二次开发属性库存缺货的思路

2010-02-04 22:48 来源:www.chinab4c.com 作者:admin

     在ecshop二次开发的过程中,我们往往会遇到给属性增加库存,我们已经实现了给ecshop属性增加库存管理,如果我们要处理属性缺货,那么我们还需要做另外一个尝试.ecshop二次开发属性缺货  

1:ecshop的flow.php中增加

    //===================================
 //属性库存和购买关联起来
 //===================================
 if(!empty($goods->spec)){//如果选择了属性
  
  $sql = "SELECT a.attr_id, a.attr_name, a.attr_type, ".
            "g.goods_attr_id, g.attr_value, g.attr_price ,g.attr_count " .
        'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
        'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
        "WHERE a.attr_type != 0 AND g.goods_id = '" . $goods->goods_id . "' and g.attr_id " .
        'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
  $res = $GLOBALS['db']->getAll($sql);
  if($res){
   foreach ($res AS $row)
            {  if(in_array($row['goods_attr_id'],$goods->spec)){//如果取得属性ID在列表属性内,要判断属性库存
      if($goods->number > $row['attr_count']){//如果库存大于该颜色尺寸,进行缺货登记
       $result['error']   = 2;
       $result['goods_id'] = $goods->goods_id;
       $result['parent'] = $goods->parent;
       $result['message'] = $row['attr_name']."为".$row['attr_value']."的库存不足,只有". $row['attr_count']."件,请进行缺货登记!";
       die($json->encode($result)); 
      }
     }
    }
  }
  }
 //===================================
 //属性库存和购买关联起来
 //===================================

2:ecshop的flow.php中的update

if($goods['goods_attr_id']){//如果选择了属性
   
    $ar = explode(",",$goods['goods_attr_id']);
    $sql = "SELECT a.attr_id, a.attr_name, a.attr_type, ".
     "g.goods_attr_id, g.attr_value, g.attr_price ,g.attr_count " .
    'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
    'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
    "WHERE a.attr_type != 0 AND g.goods_id = '" . $goods['goods_id'] . "' and g.attr_id " .
    'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
    $res = $GLOBALS['db']->getAll($sql);
    if($res){
     foreach ($res AS $row)
     {  if(in_array($row['goods_attr_id'],$ar)){//如果取得属性ID在列表属性内,要判断属性库存
        if($val > $row['attr_count']){//如果库存大于该颜色尺寸,进行缺货登记
         
      show_message($row['attr_name']."为".$row['attr_value']."的库存不足,只有". $row['attr_count']."件,请进行缺货登记!");
      exit;
        }
       }
      }
    }
   
  }

来源:中国B4C电子商务