Alexhoward Posted October 5, 2008 Share Posted October 5, 2008 Good Evening, I'm not even sure where to start with this! i've got a shopping basket that stores all the products in different sessions, i'd like to be able to save these somehow, so customers can pull them up again in their historical/order tracking page... i honestly don't even know where to start! would someone be able to point me in the right direction..? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
xtopolis Posted October 5, 2008 Share Posted October 5, 2008 Like a shopping list? You could easily use a database to create one (or several) lists for that user to maintain and save (items) to bring up later. Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted October 5, 2008 Author Share Posted October 5, 2008 How do you mean...? Do some kind of loop and save them into SQL...? Quote Link to comment Share on other sites More sharing options...
xtopolis Posted October 5, 2008 Share Posted October 5, 2008 Well, clarify what you mean.. You have a shopping basket that stores all the products in different sessions? -Do you mean, in a user's session(singular!), you have an array to hold their shopping cart items? If you already have the items you want grouped somehow(such as an array), then write them into a delimited string and the save it to the database with a username/time/title?/value ... and when they are logged in, allow them to see those saved groupings of items.. But I'm still confused.. are you talking about purchased items, wishlists, other? Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted October 5, 2008 Author Share Posted October 5, 2008 Hi xtopolis, Thanks for having the patience with this it's a bit hard to explain... i think they are in an array see: http://www.phpfreaks.com/forums/index.php/topic,218849.msg1002551.html#msg1002551 they are all stored in one session , with multiple products, so : $_SESSION['cart'][$product_id] this will be once items have been purchased, so i can subtract them from our stock, as well as save them so customers can view their orders and track progress Quote Link to comment Share on other sites More sharing options...
xtopolis Posted October 5, 2008 Share Posted October 5, 2008 Yea, you keep the user's cart items in an array stored in their session. As far as keeping an order history, I would recommend you use a database of some sort, unique by order#. The logic is kinda like this: 1)User has items in cart... 2)User purchases items... 3)The purchase order has a unique id, the customer is unique. 4)I would store in a database the following info: order id, username(or userid), date & time, products purchased* 5)(cart is cleared, since items have been bought) *products purchased. how you store this is up to you, whether you use a delimited string, or a lookup table is based on your comfort level., but I strongly suggest a lookup table for future compatibility, less headaches if a product id changes. -- Remove from your stock: -This is an ecommerce topic, where I don't have a lot of expertise. I can offer insight still however; I would think that stock wouldn't be subtracted until the payment has been confirmed? It's up to you, I don't know what you're selling, or what happens when someone orders something that's out of stock. You could lump it in with step 2-4 though, user makes payment, payment goes through, stock reflects new total stock left. Like I said, ecommerce is not my strong point, so I would get a 2nd opinion. Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted October 5, 2008 Author Share Posted October 5, 2008 Hi, thanks again, i've got all our stock info in mysql already, and will be using paypal as the payment route. therefore when i get the success message from paypal (payment confirmed), i will complete the order and subtract the stock quantity . my only issue is trying to work out how to get the order out of the session and into the database...? just can't visualise how it works...? do you know of a good tutorial here or anywhere else that can help me? or even what that kind of process would be called...? I truely have no idea... cheers Quote Link to comment Share on other sites More sharing options...
xtopolis Posted October 5, 2008 Share Posted October 5, 2008 I was trying to make a simple example, but it became kind of complicated(whole system).. All $_SESSION['cart'] is is an array. List items in cart: <?php foreach($_SESSION['cart'] as $item){ echo $item.'<br />'; } ?> That will get you a list of products in their cart. If you were going to do it in a poor fashion, you could do something like this: <?php $items = implode(',',$_SESSION['cart']); //holds a comma delimited list of cart (32,42,23,12)<<-- hopefully those are product ids $sql = "INSERT INTO order_history (oid,uid,when,prods) VALUES ('','$userid','','$items')"; ?> where when = oid(order id)=auto_inc, uid(user id), when=timestamp and voila you have a simple, but not future/change compatible history. I'll try to make an example of a correct way, but I don't know if I'll have time. Even though I just gave you an example to use comma delimited items as a value, you really shouldn't, it makes future changes hectic. You need to use a lookup table to store : oid,pid which has a pid for every item purchased on that oid. If you do that, you won't need the prods column in the example i gave. You would use a join to get items purchased. Think about it, I'll post a simple example if I have time, but tbh, I don't know if I will. Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted October 13, 2008 Author Share Posted October 13, 2008 Thanks for the reply, i've given this a go, but all i can get back is the quantity of the products...? the products are stored in the session as: $_SESSION['cart'][$product_id] so the count is stored in the session, and the product id in the second part... could someone please help me out? Thanks! Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted October 13, 2008 Author Share Posted October 13, 2008 Sorted! foreach ($_SESSION['cart'] as $product_id => $quantity) { Thanks for all your help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.