Originariamente inviato da XanderX
Non è che mi daresti una mano a capire come modificare questa funzione ?
Ok.
Non bisogna modificare molto dovrebbe proprio essere sufficiente fare quello che ti ho detto prima, più o meno così:
Codice PHP:
function addtocart($pid,$q,$taglia,$colore){
$q=1;
if($pid<1 or $q<1) return;
if(is_array($_SESSION['cart'])){
if(product_exists($pid,$taglia,$colore)) return; //aggiung. tag e col
$max=count($_SESSION['cart']);
$_SESSION['cart'][$max]['productid']=$pid;
$_SESSION['cart'][$max]['qty']=$q;
$_SESSION['cart'][$max]['tgy']=$taglia;
$_SESSION['cart'][$max]['cuy']=$colore;
$_SESSION['cart'][$max]['cod']=$codice;
}
else{
$_SESSION['cart']=array();
$_SESSION['cart'][0]['productid']=$pid;
$_SESSION['cart'][0]['qty']=$q;
$_SESSION['cart'][0]['tgy']=$taglia;
$_SESSION['cart'][0]['cuy']=$colore;
$_SESSION['cart'][0]['cod']=$codice;
}
}
function product_exists($pid,$taglia,$colore){ //aggiungiamo tag e colore
$pid=intval($pid);
$max=count($_SESSION['cart']);
$flag=0;
for($i=0;$i<$max;$i++){
if($pid==$_SESSION['cart'][$i]['productid']
&& $taglia == $_SESSION['cart'][$i]['tgy']) //aggiungiamo ctr su tg
&& $colore == $_SESSION['cuy'][$i]['tgy']){//e ctr sul colore
$flag=1;
break;
}
}
return $flag;
}