新版购物车类,加入查找功能以及完善错误处理功能[3]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 twt326 的 blog

   for ($i=$id;$i<$this->sp_count-1;$i++)
     { for ($j=0;$j<=$this->f_num;$j++)
         $mycart[$i][$this->fields[$j]]=$mycart[$i+1][$this->fields[$j]];
     }
            unset( $mycart[$this->sp_count-1] ) ;
   $this->sp_count-=1;
            $_session["mycart"] = $mycart ;
   $this->cart=$mycart;
            $this->updatecart();
   }//del end
  
  //修改一件商品的数量  参数为 商品在购物车内的序号  需要改变的数量
  function modifyone($id,$num)
    {
          //session_start();
          $mycart = $_session["mycart"] ;
    if (! empty($mycart[$id][$this->f_key]))
      { if ($num>0)
          { $mycart[$id][$this->f_numkey]=$num;
            $this->cart=$mycart;
            $_session["mycart"]=$mycart;
            $this->updatecart();
        }
        else
       { $this->errmessage="商品数量小于或等于零!";
      return false;
       }
      }
    else
   {$this->errmessage="商品不存在!";
    return false;
   }
    }
 
  //修改一件商品的单价 参数介绍同修改商品数量
  function modifyprice($id,$num)
    {
          //session_start();
          $mycart = $_session["mycart"] ;
    if (! empty($mycart[$id][$this->f_key]))
   { if ($num>0)
       { $mycart[$id][$this->f_goldkey]=$num;
      $this->cart=$mycart;
      $_session["mycart"]=$mycart;
      $this->updatecart();
     }
     else
       {$this->errmessage="商品金额小于或等于零!";
     return false;
    }
      }
    else
   {$this->errmessage="商品不存在!";
    return false;
   }
    }//modifyprice end
   
   
   //某件商品加1 参数为商品在购物车内的序号
  function add1($id)
    {
          //session_start();
          $mycart = $_session["mycart"] ;
    $mycart[$id][$this->f_numkey]+=1;
    $this->cart=$mycart;
    $_session["mycart"]=$mycart;
    $this->updatecart();
    }
   
   
   //某件商品减1 参数为商品在购物车内的序号
  function del1($id)
    {
          //session_start();
          $mycart = $_session["mycart"] ;
    if($mycart[$id][$this->f_numkey]>1)
      $mycart[$id][$this->f_numkey]-=1;
    else
      {$this->errmessage="购物车内此商品只有一件,不可减1!";
   return false;}
    $this->cart=$mycart;
    $_session["mycart"]=$mycart;
    $this->updatecart();
    }
   
 
}//class end

本文关键:新版购物车类,加入查找功能以及完善错误处理功能
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top