分析ecshop购买必须选择颜色和尺寸

2009-12-12 17:41 来源:www.chinab4c.com 作者:ecshop专家

//##################
 //取得某商品下面属性ID的数组
 //##################
 function get_string($id,$gid){
  global $db;
  global $ecs;
  $ar = array();
  $re = $db -> getAll("select goods_attr_id from ".$ecs->table('goods_attr')." where goods_id = $gid and attr_id = $id");
  if($re){
   foreach($re as $k){
    $ar[] = $k[goods_attr_id];//属性数组ID
   }
  }
  return $ar;
 }
 $ys = $db -> getAll("select * from ".$ecs->table('goods_attr')." where goods_id = ".$goods->goods_id." and attr_id = 211");
 $cc = $db -> getAll("select * from ".$ecs->table('goods_attr')." where goods_id = ".$goods->goods_id." and attr_id = 212");
 if($ys){//如果颜色存在,声明颜色
  $a = false;//这个判断颜色
  
 }
 if($cc){//如果尺寸存在,什么尺寸
  $b = false;//这个判断尺寸
  
 }
 
 //=====================
 //颜色:211
 //=====================
 $yanse = get_string(211, $goods->goods_id);//取得颜色的数组
 //=====================
 //规格:212
 //=====================
 $guige = get_string(212, $goods->goods_id);//取得尺寸的数组
 //如果属性存在
 $yanse_guige = array_merge($guige,$yanse);
 if($yanse_guige){
  if(empty($goods->spec)){
   $result[error] = 1;
   $result[message] = '请选择商品颜色和尺寸';
   die($json->encode($result));
  }
 }
 
 
 if($yanse){
  foreach($yanse as $m){
   if(in_array($m,$goods->spec)){//如果存在颜色
    $a = true;
    break;
   }
  } 
 }
 if($guige){
  foreach($guige as $m){
   if(in_array($m,$goods->spec)){//如果尺寸存在。就是
    $b = true;
    break;
   }
  } 
 }
 
 if((isset($a))&&($a ==  false)){
  $result[error] = 1;
  $result['message']="请选择商品颜色";
  die($json->encode($result));
 }
 if(isset($b)&&($b == false)){
  $result[error] = 1;
  $result['message']="请选择商品尺寸";
  die($json->encode($result));
 }