Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/03/2004, 14:19
luisman01
 
Fecha de Ingreso: julio-2002
Ubicación: Valencia estado Carabobo
Mensajes: 18
Antigüedad: 21 años, 9 meses
Puntos: 0
Pregunta ayudaaaaa....unserialize+linux+cookies

programando un carrito de compras con la siguiente clase me he topado con el problema que cuando guarda los datos en la cookie y trata de recuperarlos con "unserialize" no me unserializa la variable del carrito ..este problema se me presenta solo con Linux ya que en windows me funciona perfectamente....otro detalle es que si en vez de utlizar cookies utilizo sesiones esta clase funcion bien en linux ..agradezco de antemando cualquier ayuda...

anexo el codigo de la clase con los respectivos comentarios de los dos casos utlizando cookie y sessiones ademas del metodos de la forma de uso...



//********************declaracion de la clase ******************
<?PHP
session_start();

class myItem{
var $Ref; //referencia de producto
var $Fccid; //FCCID del producto
var $Pict; //url o path de la foto del producto
var $Des; //descripcion del product
var $Qty = 0; //Cantidad
var $Pri = 0; //precio de producto
var $Par = ""; //Queru o parametros aplicables al rublo
var $Chv = "";
}
class myBasket{
var $Items;
var $expire ;
var $Basket;
var $Empty = true;

function myBasket($Basket){
$this->Items = array();
/*
if(isset($_COOKIE["$Basket"])){
$this->Items = unserialize($_COOKIE["$Basket"]);
}
*/
if(isset($_SESSION["$Basket"])){
$this->Items = unserialize($_SESSION["$Basket"]);
}

if(sizeof($this->Items) > 0) $this->Empty = false;
$this->Basket = $Basket;
$this->expire = mktime(0,0,0,date("m") ,date("d")+365,date("Y"));
}

function putCesta(){
setcookie($this->Basket,serialize($this->Items),$this->expire);
//$_SESSION[$this->Basket]=serialize($this->Items);
if(sizeof($this->Items) > 0) $this->Empty = false;
}

function add($Ref,$Fccid="",$Pict="", $Des = "", $Qty = 0, $Pri = 0, $Par = "",$Chv = ""){
$item = new myItem();
$item->Ref = $Ref;
$item->Fccid = $Fccid;
$item->Pict = $Pict;
$item->Des = $Des;
$item->Qty = $Qty;
$item->Pri = $Pri;
$item->Par = $Par;
$item->Chv = $Chv;
/*if($this->Items[$Ref]->Qty > 0){
$item->Qty += $this->Items[$Ref]->Qty;
}*/
$this->Items[$Ref] = $item;
}

function Upd($Ref,$Qty = 0,$Chv =""){
$this->Items[$Ref]->Qty = $Qty;
$this->Items[$Ref]->Chv = $Chv;
}


function del($Ref){
$tmp = array();
while(list( $It, $value ) = each( $this->Items) ) {
if($It != $Ref) $tmp[$It] = $value;
}
$this->Items = $tmp;
}

function cls(){
$tmp = array();
$this->Items = $tmp;
}

}
?>

//***************uso de la clase *******************

<?

include ('class.NokTemplate.php');
include_once("myBasket.php");
$bk = new myBasket("cart");
$html = new NokTemplate('./');

$html->cargar('tTemplate','remote_template.html');
$html->cargar('Cart','tmyshoppingcart.html');

$html->definirBloque('tContenido', 'Cart');
$html->definirBloque('tFila', 'Cart');
$html->definirBloque('tCart','Cart');
$html->definirBloque('tEmpty','Cart');
if($_GET['ope']=='add'){
$bk->add($_POST['Product_id'],$_POST['FCCID'],$_POST['Picture'], $_POST['Description'],$_POST['Qty'],$_POST['Price'],$_POST['Param'],$_GET['Chv']);
}

if($_REQUEST['ope']=='Update'){
$sP= $_POST['Product_id'];
$sQ= $_POST['Qty'];
if(is_array($sP)){
while (list( $pos , $valor) = each($sP)){
if(intval($sQ[$pos]) == 0){
$bk->del($valor);
}else{
$bk->Upd($valor,$sQ[$pos]);
}
}
}
}

if($_REQUEST['ope']=='Remove'){
$bk->del($_REQUEST['Product_id']);
}

if($_POST['ope']=='cls'){
$bk->cls();
}

$bk->putCesta();

$tQty = 0;
$tPri = 0;
if(!$bk->Empty){
while( list( $Ref, $value ) = each( $bk->Items) ) {
$html->asignar('Product_id',$Ref);
$html->asignar('FCCID',$value->Fccid);
$html->asignar('DESCRIPTION',$value->Des);
$html->asignar('Qty',$value->Qty);
$html->asignar('PRICE',$value->Pri);
$tot = $value->Qty * $value->Pri;
$html->asignar('TOTALPRICE',$tot);
$html->asignar('Picture',$value->Pict);
$html->expandir('basket','+tFila');
$tQty += $value->Qty;
$tPri += $tot;

}

$html->asignar('Totalf',$tPri);
$html->expandir('Cart','tCart');
$html->expandir('contenido','tContenido');
$html->asignar('last_page',$_SERVER['HTTP_REFERER']);

}else{
$html->expandir('Cart','tEmpty');
$html->expandir('contenido','tContenido');

}

$html->expandir('CACHE','tTemplate');
$html->imprimir('CACHE');

?>