Page 1 of 1
shopping cart
Posted: Fri Feb 25, 2005 12:02 am
by shiznatix
I am trying to code a small shopping cart that when you click checkout it passes everything to paypal. Questions -
A: How should I save the shopping cart infomation for each person? Is doing it through cookies bad? I can't have the user register with me so using a db with stored username and password wont go. Any sugestions on that will be very helpful.
B: Is there any way that anyone knows about that when the person pays their cookies will be deleted as to empty their shopping cart on my server?
Thanks. (and yes I have researched this stuff but have found no answers

)
Posted: Fri Feb 25, 2005 12:47 am
by feyd
- sessions
- if you have the option to use a thank you type page, or any page that ends on your server, you can erase the session then..
Posted: Fri Feb 25, 2005 1:48 am
by n00b Saibot
I have worked with Paypal and Authorize.Net and that problem occured with me too. See they have a pre-defined var names that you pass it for the transaction to occur. If you pass it any other var e.g. user_registration_no along with its value it will return that same key-value pair in its response

So damn simple

Posted: Fri Feb 25, 2005 11:34 am
by shiznatix
awesome ill look into it!
ps what happened to all the avatars?
Posted: Fri Feb 25, 2005 12:08 pm
by shiznatix
ok problem, im coding the shopping cart with sessions. this is my code so far
Code: Select all
$_SESSIONї'products'] = $_SESSIONї'products'].'*'.$item_name.'*';
$_SESSIONї'total'] = $_SESSIONї'total']+$amount;
$pro = explode('*', $_SESSIONї'products']);
$count = count($pro);
$query = mysql_query("SELECT * FROM items ORDER BY itemid DESC");
while($item = mysql_fetch_assoc($query)){
for($i=0; $i<$count; $i++){
if ($proї$i] == $itemї'name']){
$itm = $itemї'name'];
$_SESSIONї$itm] = $_SESSIONї"$itm"]+1;
}
}
}
while($item = mysql_fetch_assoc($query)){
$itm = $itemї'name'];
foreach($_SESSIONї$itm] as $itmc => $amt){
echo '<br>______________<br>';
echo 'You have '.$amt.' of '.$itmc.'<br>';
echo '<br>______________<br>';
}
}
echo 'Your total is'.$_SESSIONї'total'];
where i think im having the trouble is in setting the session item name with its value. its suposed to for each item you added to your cart it checkes the amount that you want for that item but doing a $_SESSION[$itm]; to make the session thing based on the item name is definatly not working i dont think. any sugestions?...or is this just complete garbage and my only real option is suicide?
Posted: Fri Feb 25, 2005 2:28 pm
by shiznatix
scratch that, that sucks i know.
but! i have a db that stores the cartID as your session id and there will be multiple rows with your cartID and each has its own itemID. I need to take all of the itemID's and turn them into a array so it will look like
array(123, 542, 67) each number being a seperate itemID where your cartID equals your session id. I dont know the sql to do this. Help?
Posted: Sat Feb 26, 2005 1:48 am
by n00b Saibot
Not SQL but a little of PHP+MySQL
Code: Select all
$result = mysql_query("SELECT itemID FROM cartDB WHERE cartID = '".session_id()."'") or die("Damn! You can't even write SQL correctly!<br>".MySQL_Error()); //;)
while(itemsї] = mysql_fetch_row($result));
That should do it!