Welcome Guest, Not a member yet? Register   Sign In
How would you get this done?
#1

[eluser]NachoF[/eluser]
Im trying to set up a site that allows users to add to their cart certain products.. and then when they are ready to submit they fill in their name and phone number, click submit, and the only thing that has to happen is that the owners of the site get sent en email reporting that that certain client is interested in those products they added to their "cart"... as you can see there is no logging in and there is no payment, so keeping track of the added products is complicated..... I have a mysql table with products.... right now its set up as everytime the client adds the product to his cart I add an item to a requirements table that has two fields, product_id and session_id (using the session class)... the thing is that that session id gets reset every five minutes so sometimes if the client takes too long, the products in his cart will get deleted cause he now is identified with a new session id....... anyway, its good enough for my client but not for me.... anyone cares to share a different way of accomplishing this?
#2

[eluser]jedd[/eluser]
[url="http://ellislab.com/codeigniter/user-guide/libraries/sessions.html"]Session data[/url] is your friend.

Write a function that tests if a piece of user data exists in your session - if it does not, create it using some method of your choosing - the md5 of the session id, a timestamp, a random string, the actual session id, etc. Obviously the function will not overwrite this piece of userdata if it already exists.

All subsequent functions involved in cart adds, tracking, emailing and so on, will refer to this piece of data.
#3

[eluser]NachoF[/eluser]
Im not sure how to use this class correctly... what exactly should I use the session for??.. right now what I do is, when the client adds the product, a table called requirements with thwo fields gets an Insert. The two fields are product_id and session_id. And when the client wants to look at his cart before submitting, this requirements table gets a Select where $this->session->userdata('session_id')=session_id..... the problem with doing it like this is that session_id gets reset every five minutes so Im sure theres gotta be a different way of getting this done.... help is appreciated

Just in case, heres my code
This is on my controller
Code:
function cart()
    {
        $this->load->library('layout', 'layout_main');
        $id_Session = $this->session->userdata('session_id');
        $query=$this->RequerimientosModel->get_requerimientos($id_Session);
                //I then create the table and add to $data['table'];
        $this->layout->view('carrito_view',$data);
    }
This is on my model
Code:
function get_requerimientos($id_Session)
    {
    $this->id_Session = $id_Session;
        $this->db->select('nombre, id')->from('repuestos, requerimientos')->where('id_Session', $id_Session)->where("id=id_Repuesto",NULL,FALSE);
    $query = $this->db->get();
        return $query;
    }

As you can see it all depends on $this->session->userdata('session_id') and that would be fine if it didnt reset every five minutes Sad
#4

[eluser]jedd[/eluser]
As soon as your client lands - which would equate to when you record the session_id in your database - you want to create another, different, unique identifier for that user, and set it in the cookie.

So, as soon as you detect you are talking to a new client:

Code:
$this->session->set_userdata('identity',  $xyz);

From then on, you identify the user by that 'identity' (specifically by $this->session->userdata('identity').)

$xyz is something you create, using whatever algorithm you like in order to generate a unique id. I'd be opting for the session_id, but it could be anything. The point is that once that's done, you can totally ignore userdata('session_id').

Your code would require minimal changes - obviously you refer to 'identity' wherever you currently refer to 'session_id'.
#5

[eluser]NachoF[/eluser]
[quote author="jedd" date="1238967072"]As soon as your client lands - which would equate to when you record the session_id in your database - you want to create another, different, unique identifier for that user, and set it in the cookie.

So, as soon as you detect you are talking to a new client:

Code:
$this->session->set_userdata('identity',  $xyz);

From then on, you identify the user by that 'identity' (specifically by $this->session->userdata('identity').)

$xyz is something you create, using whatever algorithm you like in order to generate a unique id. I'd be opting for the session_id, but it could be anything. The point is that once that's done, you can totally ignore userdata('session_id').

Your code would require minimal changes - obviously you refer to 'identity' wherever you currently refer to 'session_id'.[/quote]

I see.... then I guess my question can be summed up as.... what algorithm would you use??.. I havent a clue
#6

[eluser]jedd[/eluser]
[quote author="NachoF" date="1238999298"][quote author="jedd" date="1238967072"]
I'd be opting for the session_id, but it could be anything. [/quote][/quote]
#7

[eluser]NachoF[/eluser]
But, like I said.... the session_id gets a new value every five minutes... thats the whole reason I started this thread, I dont want to have the users of the site to have to hurry to get their products...

Edit:
Hold on, i see what you mean... something like this in my index function?
Code:
$this->session->set_userdata('identity',  $this->session->userdata('session_id'));
..right?




Theme © iAndrew 2016 - Forum software by © MyBB