Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Variable from external site; reset variable in session as needed?


hb_cmcl

Recommended Posts

Hello,

 

I'm still relatively new to osCommerce but I've managed to customize a few things here and there for a couple of clients' stores, and I now have a new task that's a little frustrating -- hopefully someone here can steer me in the right direction. I've searched previous topics and Googled like crazy and I've gotten a few ideas, but I think I need a little more specific help. I'm not yet fully comfortable with sessions, and that seems to be where my solution lies.

 

A client wants a shopping cart where a customer can click a link from an external site and have a certain parameter "pre-selected" in the cart -- basically, the customer will be on "http://www.mysite.com/index.php" and click a link to "http://www.myoscommercestore.com/somepage.php?myvar=1234" to go to the shopping cart, and the variable "myvar" with the value "1234" will be stored and remain in the session, and at checkout will enter that value in a custom field in the "orders" table" so that it can be retrieved later for reporting purposes. (How many people bought stuff through "1234" or "9876" or whatever.)

 

These two old threads seemed to give the most help to me so far, and I've got at least the first part of what I want to do working. On the external site, I've got the link to somepage.php?myvar=1234. On somepage.php, I have

  if( !tep_session_is_registered('myvar') ) {
tep_session_register('myvar');
$myvar = $myvar;
 }

right underneath the "require('includes/application_top.php');" part; and on some other pages linked from there I've just echoed the $myvar to make sure it's pulling the info, and it is. So far, so good.

 

I haven't even gotten to the part where it inserts the info into the orders table yet, because first I want to make sure that the customer can basically reset and start shopping with a new $myvar variable -- say, by going back to the original site and clicking a different link, like somepage.php?myvar=9876. How can I make some way for them to reset that variable in the session, e.g., "Click here to reset your 'myvar' selection"? Do they need to have a whole new session started? I'm not even sure how to do that, if it's necessary, but I'm hoping there's some way to keep the session and just change the variable. Right now, if I click a new link going to somepage.php?myvar=9876, the pages are still echoing 1234, presumably because that's what's stored in the session.

 

Or, is there a better way to do this altogether? Thanks for any help you can provide.

Link to comment
Share on other sites

Hello,

 

I'm still relatively new to osCommerce but I've managed to customize a few things here and there for a couple of clients' stores, and I now have a new task that's a little frustrating -- hopefully someone here can steer me in the right direction. I've searched previous topics and Googled like crazy and I've gotten a few ideas, but I think I need a little more specific help. I'm not yet fully comfortable with sessions, and that seems to be where my solution lies.

 

A client wants a shopping cart where a customer can click a link from an external site and have a certain parameter "pre-selected" in the cart -- basically, the customer will be on "http://www.mysite.com/index.php" and click a link to "http://www.myoscommercestore.com/somepage.php?myvar=1234" to go to the shopping cart, and the variable "myvar" with the value "1234" will be stored and remain in the session, and at checkout will enter that value in a custom field in the "orders" table" so that it can be retrieved later for reporting purposes. (How many people bought stuff through "1234" or "9876" or whatever.)

 

These two old threads seemed to give the most help to me so far, and I've got at least the first part of what I want to do working. On the external site, I've got the link to somepage.php?myvar=1234. On somepage.php, I have

  if( !tep_session_is_registered('myvar') ) {
tep_session_register('myvar');
$myvar = $myvar;
 }

right underneath the "require('includes/application_top.php');" part; and on some other pages linked from there I've just echoed the $myvar to make sure it's pulling the info, and it is. So far, so good.

 

I haven't even gotten to the part where it inserts the info into the orders table yet, because first I want to make sure that the customer can basically reset and start shopping with a new $myvar variable -- say, by going back to the original site and clicking a different link, like somepage.php?myvar=9876. How can I make some way for them to reset that variable in the session, e.g., "Click here to reset your 'myvar' selection"? Do they need to have a whole new session started? I'm not even sure how to do that, if it's necessary, but I'm hoping there's some way to keep the session and just change the variable. Right now, if I click a new link going to somepage.php?myvar=9876, the pages are still echoing 1234, presumably because that's what's stored in the session.

 

Or, is there a better way to do this altogether? Thanks for any help you can provide.

 

I think I know what you mean (speed read it).

 

For example one of my customers sites requires to record responses from every online google ad with a different code for each ad.

 

Similar I think.

 

If i'm on the right track this is what you do ..

 

1) install the supertracker contribution .. this records a load of valuable information one of which is the $_SERVER['REQUEST_URI'] (read querystring).

2) As an extra you can install my salestracker (not what you asked for but will give you good info on this basis)

3) When you create any link that you wish to record .. give it a standard parameter.

 

I'd advise something like ?source=google&keyword=wiggit

 

So the link url may look like ..

 

http://www.mysite.com/index.php?products_i...;keyword=wiggit

 

or if an ULTIMATE SEO URL ..

 

http://www.mysite.com/my-fantastic-wiggit-...;keyword=wiggit

 

Note in one ?source in the other &source this is important to get right or you'll get errors.

 

Supertracker is the crux as all important info is being stored. Getting it out is just a coding job.

 

Supertracker does a lot of reporting .. salestracker will allow you to see sales by picking a time period and will also show you where they came from and the ?source=google&keyword=wiggit bit.

 

You can then write simple admin scripts to report on whatever you want.

 

Hope that helps.

 

Rob

Link to comment
Share on other sites

Rob,

 

Thanks very much for the quick reply. I'm looking at the files in supertracker and while it seems like a cool tool, it might not quite be what I'm looking for here (though maybe down the road my client would appreciate the extra info on who's looking at what and where they came from). The main thing I need at this point, as opposed to just plain referrer info, is a way for the customer to "Choose another myvar" so that that info can be recorded in the orders table come checkout time. Does supertracker have a method or function to do that?

 

I have actually set up the new field in the orders table already now, and changed the order.php and checkout_process.php files so that the $myvar info will be added to the orders table at checkout. My setup is functioning almost exactly as I want it to, except for the ability of the customer to choose a new $myvar. I'm hoping there's something niiiiice and simple I can do to make it work...

Link to comment
Share on other sites

Aaah I read it a bit more carefully now.

 

Well .. I'm not gonna write it for you :D

 

Here's a pointer: -

 

How can I make some way for them to reset that variable in the session

 

 

( isset($_GET['myvar']) ? ($_SESSION['myvar'] = tep_sanitize_string($_GET['myvar']) : NULL );

 

That'll reset myvar

Link to comment
Share on other sites

Hmmm, I still seem to be missing something. I tried using that code, but I kept getting an error about "unexpected ':'" so I shuffled it around a little; Tried this:

  if ( isset($myvar)) {
 $_SESSION['myvar'] = tep_sanitize_string($myvar);
 }

Which didn't do anything...Googling a little and looking at the functions seems to indicate that tep_sanitize_string just strips the whitespace and/or special characters out of a string? Not sure, still new at this. Then I tried this:

  if ( isset($myvar)) {
 $_SESSION['myvar'] = NULL;
 }

This actually did strip the $myvar out, since going to the other pages where I had echoed $myvar, it was no longer visible -- but then, I wasn't able to assign a new $myvar -- it stayed blank on all the pages even after clicking a new link ("somepage.php?myvar=5678"). I tried to rectify that by modifying the code on the original page like so:

  if (!tep_session_is_registered('myvar') || $_SESSION['myvar'] = NULL) {
tep_session_register('myvar');
$myvar = $myvar;
 }

 

And this:

  if (!tep_session_is_registered('myvar') || empty($_SESSION['myvar'])) {
tep_session_register('myvar');
$myvar = $myvar;
 }

 

Aaaaand:

  if (!tep_session_is_registered('myvar') || !isset($_SESSION['myvar'])) {
tep_session_register('myvar');
$myvar = $myvar;
 }

 

And even:

  if (!tep_session_is_registered('myvar') || $myvar = NULL) {
tep_session_register('myvar');
$myvar = $myvar;
 }

 

No luck -- once I've nullified the $myvar spot in the session, it apparently stays null until I actually delete the session and start a new one, which I'm trying to avoid making the customer do. I'm trying to teach myself to fish here...

 

Just to reiterate how the setup works, somebody clicks a link to "sompage.php?myvar=1234" and the value 1234 gets stored in the "myvar" field which I've added to the "orders" table upon checkout; but they need to be able to reset that value at any point before checkout, say clicking a link to "reset.php" will clear just that value in the session, and then they can click "somepage.php?myvar=9876" and now "9876" is stored in the session instead. Am I missing something obvious (probably)?

Link to comment
Share on other sites

LOL oops missed a bracket. :blush:

 

( isset($_GET['myvar']) ? ($_SESSION['myvar'] = tep_sanitize_string($_GET['myvar'])) : NULL );

Link to comment
Share on other sites

Hrm, well, it doesn't throw an error anymore, but it's not stripping the variable either. In fact, if I go into the sessions table in phpMyAdmin, it still shows

myvar|s:5:"58764";

at the end of the "value" field, where 58764 is just the last gobbletygook number I assigned to the variable. Tried stripping it down to

( isset($myvar) ? ($_SESSION['myvar'] = tep_sanitize_string($myvar)) : NULL );

with the same result.

 

What's happening is, I put the code on conditions.php right under the application_top:

  if (!tep_session_is_registered('myvar')) {
tep_session_register('myvar');
$myvar = $myvar;
 }

and just echo $myvar on shipping.php, privacy.php, contact_us.php, and a few others, just to make sure it was working, so if I go to conditions.php?myvar=58764, and then go to shipping.php or privacy.php, 58764 is echoed nicely. I put your code on a new page, test_variable.php, again under the application_top, thinking that if I click on that page that code will be executed and reset the variable, but it's not doing it. Do I need to put it someplace else? I still wonder if tep_sanitize_string is the right thing to use...

 

I've been playing around with using tep_session_unregister('myvar') instead, but I don't seem to be having much luck there, either. Argh.

Link to comment
Share on other sites

I think i've lost what the hell it is you are trying to do.

 

My understanding was that you wanted it so that if a customer came into the shop with myvar=x on the querystring that this value would be set as myvar in the session.

 

I then understood that if the customer came back with myvar=y on the querystring that myvar would be set on the session as y.

 

Where am I missing your point?

Link to comment
Share on other sites

My understanding was that you wanted it so that if a customer came into the shop with myvar=x on the querystring that this value would be set as myvar in the session.

 

I then understood that if the customer came back with myvar=y on the querystring that myvar would be set on the session as y.

 

That's pretty much it, plus the need for a way for the customer to clear the myvar before coming back with a different one. They come in with myvar=x and x is set in the session. Then they "click here to choose another myvar," myvar is cleared or reset in the session somehow (without having to get a whole new session). They click somewhere else that says myvar=y and y is now set in the session. So far, I haven't achieved that.

 

I apologize if I've confused the issue, figured "talking it out" and showing all the different things I've tried would help. The echoes aren't important except insofar as they tell me what value is currently stored in the session.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...