dlf1987 Posted June 24, 2009 Share Posted June 24, 2009 In the backend of my site i have a shopping cart for our sales people who take orders over the phone. The problem is if they open mutiple "create order" pages it shows the same session cart on each page. How can i make unique carts? Below is the code i use for the carts. $_SESSION['CART']['ITEMS'][] = array( 'pro_id' => $pro_id, 'pro_name' => $pro_name ); This is what the current structure looks like... Array ( [CART] => Array ( [iTEMS] => Array ( [0] => Array ( [pro_id] => [pro_name] => test ) [1] => Array ( [pro_id] => [pro_name] => test 2 ) ) ) ) ------------------------------------------------------ Is there a way to make each cart have its own unique id, like how i wrote it below?... $_SESSION['CART'][***UNIQUEID***]['ITEMS'][] = array( 'pro_id' => $pro_id, 'pro_name' => $pro_name ); Array ( [CART] => Array ( [*** UNIQUE ID ***] => Array ( [iTEMS] => Array ( [0] => Array ( [pro_id] => [pro_name] => test ) [1] => Array ( [pro_id] => [pro_name] => test 2 ) ) ) [*** UNIQUE ID ***] => Array ( [iTEMS] => Array ( [0] => Array ( [pro_id] => [pro_name] => test ) [1] => Array ( [pro_id] => [pro_name] => test 2 ) ) ) ) ) And if the above is possible, how do i make a "IF" that checks for the unqiue cart and only pulls that cart to the page? Hope this makes since :/ Link to comment https://forums.phpfreaks.com/topic/163533-solved-unique-sessions/ Share on other sites More sharing options...
aggrav8d Posted June 24, 2009 Share Posted June 24, 2009 This is more of a design question than a PHP question. Yes, you can modify your cart in that way (depending on who else uses the same cart system). It might be cheaper to get your sales reps to handle a single cart at a time. Processing one order at a time will mean less chance of mistake. Link to comment https://forums.phpfreaks.com/topic/163533-solved-unique-sessions/#findComment-862830 Share on other sites More sharing options...
dlf1987 Posted June 24, 2009 Author Share Posted June 24, 2009 I assume what I'm asking must be possible. I need it to work not just for multiple carts but to prevent other user errors which i don't need to talk about. Link to comment https://forums.phpfreaks.com/topic/163533-solved-unique-sessions/#findComment-862837 Share on other sites More sharing options...
aggrav8d Posted June 24, 2009 Share Posted June 24, 2009 You're asking someone to write a lot of code to fix your issue but haven't revealed any of the existing code. Given the amount of work probably involved I'm fairly certain no one will fix your code for free. Maybe you need to hire someone with an NDA and get them to give you an honest assessment of your situation and what it will take to get you where you want to be. Link to comment https://forums.phpfreaks.com/topic/163533-solved-unique-sessions/#findComment-862841 Share on other sites More sharing options...
dlf1987 Posted June 24, 2009 Author Share Posted June 24, 2009 I'm pretty sure what im asking is pretty simple. I even gave an example asking if my example was the way to go about making the carts unique. Im pretty sure your blowing this way out of proportion. You obviously haven't even read my post and i would appreciate it if you wouldn't post anymore on this thread. Im trying to be nice here. If the 2nd part of my code i wrote is possible, how do i make a "IF" that checks for the unqiue cart and only pulls that cart to the page? Link to comment https://forums.phpfreaks.com/topic/163533-solved-unique-sessions/#findComment-862851 Share on other sites More sharing options...
aggrav8d Posted June 24, 2009 Share Posted June 24, 2009 There seems to be some misunderstanding here. You've shown a couple of arrays and expect someone to debug your PHP. I've written shopping carts from scratch before and know it's a lot more than just a couple of ifs to fix your situation. let's say you have function get_cart() { return $_SESSION['cart']; } that is in use everywhere the cart gets referenced. Now you'll probably want to change that to function get_cart($id) { return $_SESSION['cart'][$id]; } of course you'll also need a way to keep track of which cart a user is looking at, prevent an edit meant for cart A doesn't accidentally affect carts B and C, make sure that users on the front end of your site still only see the one-cart-at-a-time they're used to, modify your add-to-cart, checkout, & edit cart procedures to cope with the new get_cart(), write new code to create a new cart on demand, and then for niceness you might want to think about "move items from this cart to that cart", "merge these two carts", "split this cart in two", "clone this cart", and so on. The chances of you being nice are about as high as the chances that I didn't read your post. Link to comment https://forums.phpfreaks.com/topic/163533-solved-unique-sessions/#findComment-862861 Share on other sites More sharing options...
dlf1987 Posted June 24, 2009 Author Share Posted June 24, 2009 $_SESSION['CART'][***UNIQUEID***]['ITEMS'][] = array( 'pro_id' => $pro_id, 'pro_name' => $pro_name ); This code i previously put was the right way of doing it... and it was very simple. Guess i overlooked something... Link to comment https://forums.phpfreaks.com/topic/163533-solved-unique-sessions/#findComment-862888 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.