help in shopping cart! :(
Posted: Sat Oct 28, 2006 10:57 am
i know shopping cart shd sounds early for experts but to a noob like me!! it do sounds easy at first but when i started 'coding' i'm struck!! anybody there can lend a helping hand?
The below coding is a part thats called when you click on the update button of the shopping cart.. i'm using cookie for this time.. any other better way in doing please do let me know! and oh ya.. there's error on the part where the condition checks on the 0 that the user entered in for the qty. If the user entered in 0 or checked on the remove checkboxes, it will then take the cookie out and move the cookie below up(its in array).
i simply can't get it right!! its up at my neck now!! anyone help?!?!
:(:(
The below coding is a part thats called when you click on the update button of the shopping cart.. i'm using cookie for this time.. any other better way in doing please do let me know! and oh ya.. there's error on the part where the condition checks on the 0 that the user entered in for the qty. If the user entered in 0 or checked on the remove checkboxes, it will then take the cookie out and move the cookie below up(its in array).
i simply can't get it right!! its up at my neck now!! anyone help?!?!
Code: Select all
if(isset($_POST['btnUpdate'])){
$intCount=1;
$intQty=0;
$intNum="0";
$intCountZero=0;
$intCountItem=0;
//check if there's 0;
foreach ($_COOKIE['id'] as $IdName => $IdValue){
foreach ($_COOKIE['qty'] as $qtyName => $qtyValue){
if($IdName==$qtyName){
foreach($_POST['txtQty'] as $qtyId => $qtyV){
if(($qtyId + 1)==$IdName && ($qtyId + 1)==$qtyName){
if($qtyV==0){
$intCountZero++;
}
$intCountItem++;
}
}
}//if
}//foreach
}//foreach
if($intCountZero>0 && $intCountZero!=1){
for($i = 1; $i <=$intCountZero; $i++) {
$intCount=1;
$intQty=0;
$intNum="0";
$intCountOnce=0;
$countV=0;
foreach ($_COOKIE['id'] as $IdName => $IdValue){
foreach ($_COOKIE['qty'] as $qtyName => $qtyValue){
if($IdName==$qtyName){
if(is_numeric($txtQty[$intQty])==false){
$intNum="1";
setcookie("id[$intCount]");
setcookie("qty[$intCount]");
setcookie("id[$intCount]","$IdValue",time()+86400);
setcookie("qty[$intCount]","$qtyValue",time()+86400);
}else{
foreach($_POST['txtQty'] as $qtyId => $qtyV){
if(($qtyId + 1)==$IdName && ($qtyId + 1)==$qtyName){
if($qtyV==0 && $intCountOnce==0){
setcookie("id[$intCount]");
setcookie("qty[$intCount]");
$countV=$intCount;
$intCountOnce=1;
}elseif($intCountOnce==1){
setcookie("id[$countV]");
setcookie("qty[$countV]");
setcookie("id[$countV]","$IdValue",time()+86400);
setcookie("qty[$countV]","$txtQty[$intQty]",time()+86400);
setcookie("id[$intCount]");
setcookie("qty[$intCount]");
$countV++;
}else{
setcookie("id[$intCount]");
setcookie("qty[$intCount]");
setcookie("id[$intCount]","$IdValue",time()+86400);
setcookie("qty[$intCount]","$txtQty[$intQty]",time()+86400);
}
$intCount++;
$intQty++;
}//if
if($intQty==$intCountItem){
break;
}
}//foreach
}//if
}//if
if($intQty==$intCountItem){
break;
}
}//foreach
if($intQty==$intCountItem){
break;
}
}//foreach
}//for
}elseif($intCountZero==1){
foreach ($_COOKIE['id'] as $IdName => $IdValue){
$intCount=1;
foreach ($_COOKIE['qty'] as $qtyName => $qtyValue){
if($IdName==$qtyName){
setcookie("id[$intCount]");
setcookie("qty[$intCount]");
}
}
}
}else{//if no "0" found in qty value and checkbox remove is not checked
$intCount=1;
$intQty=0;
$intNum="0";
foreach ($_COOKIE['id'] as $IdName => $IdValue){
foreach ($_COOKIE['qty'] as $qtyName => $qtyValue){
if($IdName==$qtyName){
if(is_numeric($txtQty[$intQty])==false){
$intNum="1";
setcookie("id[$intCount]");
setcookie("qty[$intCount]");
setcookie("id[$intCount]","$IdValue",time()+86400);
setcookie("qty[$intCount]","$qtyValue",time()+86400);
}else{
setcookie("id[$intCount]");
setcookie("qty[$intCount]");
setcookie("id[$intCount]","$IdValue",time()+86400);
setcookie("qty[$intCount]","$txtQty[$intQty]",time()+86400);
}
$intCount++;
$intQty++;
}//if
}//foreach
}//foreach
}
if($intNum=="1"){
header("Location:".$PHP_SELF."?strAlert=1&$intCountZero");
}else{
header("Location:".$PHP_SELF."?strAlert=2&$intCountZero");
}