Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/08/2004, 13:32
Lautaroe
 
Fecha de Ingreso: julio-2004
Ubicación: Arg. Neuquén
Mensajes: 44
Antigüedad: 19 años, 9 meses
Puntos: 0
Clases en php

Hola. tengo que implementar una clase de carrito de compra, pero no sé como. ayuda por favor como la implento??? o si me pueden dar algunos tutoriales o algo
Código PHP:
class Basket {
        var 
$basket_count;
        var 
$basket_item_id;
        var 
$basket_item_name;
        var 
$basket_item_quantity;
        var 
$basket_item_data;
        var 
$basket_item_price;

        function 
Basket() {
                
$this->basket_count=0;
        }
        function 
Add_Item($ID,$name,$quantity=1,$price=0,$data='') {
                
$this->basket_item_id[$this->basket_count]=$ID;
                
$this->basket_item_name[$this->basket_count]=$name;
                
$this->basket_item_quantity[$this->basket_count]=$quantity;
                
$this->basket_item_data[$this->basket_count]=$data;
                
$this->basket_item_price[$this->basket_count]=$price;
                
$this->basket_count++;
                return (
$this->basket_count-1);
        }
        function 
Del_Item($pos) {
                
$this->basket_item_id[$pos]='';
                
$indice=$this->basket_count;
                
$contador=$pos;
                while (
$contador<$indice){
                    
$this->basket_item_id[$contador]=$this->basket_item_id[$contador+1];
                    
$this->basket_item_name[$contador]=$this->basket_item_name[$contador+1];
                    
$this->basket_item_quantity[$contador]=$this->basket_item_quantity[$contador+1];
                    
$this->basket_item_data[$contador]=$this->basket_item_data[$contador+1];
                    
$this->basket_item_price[$contador]=$this->basket_item_price[$contador+1];
                    
$contador++;
                }
                
$this->basket_item_id[$contador]=null;
                
$this->basket_item_name[$contador]=null;
                
$this->basket_item_quantity[$contador]=null;
                
$this->basket_item_data[$contador]=null;
                
$this->basket_item_price[$contador]=null;
                
$this->basket_count=$contador-1;
        }
        function 
Get_Item_ID($pos) {
                return 
$this->basket_item_id[$pos];
        }
        function 
Get_Item_Name($pos) {
                return 
$this->basket_item_name[$pos];
        }
        function 
Get_Item_Price($pos) {
                return 
$this->basket_item_price[$pos];
        }
        function 
Get_Item_Quantity($pos) {
                return 
$this->basket_item_quantity[$pos];
        }
        function 
Get_Item_Data($pos) {
                return 
$this->basket_item_data[$pos];
        }
        function 
Set_Item_Quantity($pos,$quantity) {
                
$this->basket_item_quantity[$pos]=$quantity;
        }
        function 
Set_Item_Data($pos,$data) {
                
$this->basket_item_data[$pos]=$data;
        }
        function 
Enum_Items($start=false) {
                static 
$current;
                if (
$current>=$this->basket_count) return -1;
                if (!
$start) {
                        
$current++;
                } else {
                        
$current=0;
                }
                while ((
$this->basket_item_id[$current]=='') && ($current<$this->basket_count)) {
                        
$current++;
                }
                return (
$current<$this->basket_count) ? $current : -1;
        }
        function 
Empty_Basket() {
                
$this->basket_count=0;
        }
        function 
Get_Basket_Count() {
            
$num=0;
            for (
$i=0;$i<$this->basket_count;$i++) {
                        if (
$this->basket_item_id[$i]!=''$num++;
            }
            return 
$num;
        }