Shopping Cart
Moderator: General Moderators
Shopping Cart
Hello,
I'm working on a webshop for my site. It's a shop for Audio products but i want if the user added something to the shopping cart if he visits back the site 5hours later it still is in the basket.
If possible can somebody gives me some examples or scripts. I'm newbie and have to finish this before july for my website. I already made the tables with products, ... but i don't understand to start with this cookies or sessions.
Cheers
Kris
I'm working on a webshop for my site. It's a shop for Audio products but i want if the user added something to the shopping cart if he visits back the site 5hours later it still is in the basket.
If possible can somebody gives me some examples or scripts. I'm newbie and have to finish this before july for my website. I already made the tables with products, ... but i don't understand to start with this cookies or sessions.
Cheers
Kris
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Setting a cookie is fairly easy:
http://www.php.net/manual/en/function.setcookie.php
If you are storing the contents of their shopping cart in a database table then all you need is some unique identifier linked to them that you can store both in the database and the cookie.
Mac
http://www.php.net/manual/en/function.setcookie.php
If you are storing the contents of their shopping cart in a database table then all you need is some unique identifier linked to them that you can store both in the database and the cookie.
Mac
A cookie with a randomly generated value (script below if you need one) could identify different shoppers without requiring them to input anything.
Code: Select all
// random string of numbers and upper/lower case characters of length given by, er, $length
function random_numchar($length) {
$chars = array_merge(range(a, z), range(0, 9));
$counter = 0;
while ($counter < $length) {
$x = mt_rand(0, 35);
$char = $chars[$x];
$y = mt_rand(1, 2);
IF ($y % 2 == 0 AND ctype_alpha($char)) {
$char = strtoupper($char);
}
$str .= $char;
$counter++;
}
return $str;
}
Last edited by McGruff on Thu Aug 11, 2005 12:34 pm, edited 1 time in total.
Updating Shopping Cart
Can someone help me with an update function i have a problem:
when i use the function for viewing the cart i put the quantity like this
<input type=\"text\" name=\"qty\" size=\"2\" value=\"$qty\">
The value $qty comes out from the database but if i update it doesn't works because it still takes the value from the $qty from the database.
Now i want is when a user changed the quantity in the text field it also will be updated. Can someone helps me?
Regards
Kris
when i use the function for viewing the cart i put the quantity like this
<input type=\"text\" name=\"qty\" size=\"2\" value=\"$qty\">
The value $qty comes out from the database but if i update it doesn't works because it still takes the value from the $qty from the database.
Now i want is when a user changed the quantity in the text field it also will be updated. Can someone helps me?
Regards
Kris
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You'd have to have a bit of code that set $qty to the posted value if set, or otherwise to the db value, maybe something like this (assuming that you can access the db value as $row['qty']):
Mac
Code: Select all
$qty = (isset($_POST['qty'])) ? $_POST['qty'] : $row['qty'];Need Help!
I really need some help with my update function.
How can the function Update() knows what products that has to be updated i mean
Like this is the shopping cart.
Qty Product Name: Price
2 DMD RED - Reasonfreaks Edition ? 159.9
1 DMD YELLOW - Construction Ki t ? 74.95
When the user change the quantity of product 1 and 2 and press recalc then the qty has to been changed. But i really don't understand how i can make the function and how i need to call the function.
Like every row in the shopping cart needs an unique quantity field maybe the product code as field? like SMP-0000001 SMP-0000002
But then how can the function know all the fields. I hope you can help me because i have to finish my shop before june.
Regards
Kris
How can the function Update() knows what products that has to be updated i mean
Like this is the shopping cart.
Qty Product Name: Price
2 DMD RED - Reasonfreaks Edition ? 159.9
1 DMD YELLOW - Construction Ki t ? 74.95
When the user change the quantity of product 1 and 2 and press recalc then the qty has to been changed. But i really don't understand how i can make the function and how i need to call the function.
Like every row in the shopping cart needs an unique quantity field maybe the product code as field? like SMP-0000001 SMP-0000002
But then how can the function know all the fields. I hope you can help me because i have to finish my shop before june.
Regards
Kris
Is this shopping cart going to be used on a live commerce site? Forgive me for being blunt but I'd be concerned that, if you are struggling with the basic code, how well do you understand the security required to deal with credit card numbers? You need a fairly advanced knowledge level to with all that properly. It's bad for your business if CCs get hacked - and bad for the reputation of the internet & php as a whole as a safe way to do business.
Don't get me wrong: I don't want to put you off. As long as you bone up on all the issues you'll get there in the end.
Now that my standard rant is out of the way, do you know how to make a form / form processor script? If not, I'll post an example later today (after that I'll be away for a bit so be quick!).
Don't get me wrong: I don't want to put you off. As long as you bone up on all the issues you'll get there in the end.
Now that my standard rant is out of the way, do you know how to make a form / form processor script? If not, I'll post an example later today (after that I'll be away for a bit so be quick!).