Jump to content

[SOLVED] Unique sessions


dlf1987

Recommended Posts

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

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.

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.

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.