Zen Cart Logo
Forums / Customization from the Admin / Inserting Customer ID into hyperlink as querystring in checkout_success

Inserting Customer ID into hyperlink as querystring in checkout_success

Views: 4,578

Results 1 to 10 of 10
5 Mar 2013, 8:16 AM
#1
marksmanaz avatar

marksmanaz

New Zenner

Join Date:
Jul 2009
Posts:
5
Plugin Contributions:
0

Inserting Customer ID into hyperlink as querystring in checkout_success

Hello,
I am using v1.5.1.
A few weeks ago I did read somewhere how to do this and I can't find it now. I spent the whole day looking so I apologize for asking again since I am sure this has been covered.

What I am trying to do is create a link on the checkout_success page using the define_checkout_success_page in the admin interface. I can successfully create the hyperlink but I can't get the value for $_SESSION['customer_id'] into my url as a variable to pass along to another page. This is what I have that is not working.

<a href="http://mydomain.com/Default.aspx/?ID=$_SESSION['customer_id']">Link text</a>

what you see is what I get. It successfully sends you to the new page but instead of ?ID=value it remains ?ID=$_SESSION['customer_id']

This is what shows in the address bar after following the link:
mydomain.com/Default.aspx/?ID=$_SESSION['customer_id']

Any and all help appreciated.

Good Night all,

Mark

5 Mar 2013, 12:37 PM
#2
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Inserting Customer ID into hyperlink as querystring in checkout_success

marksmanaz:

What I am trying to do is create a link on the checkout_success page using the define_checkout_success_page in the admin interface. I can successfully create the hyperlink but I can't get the value for $_SESSION['customer_id'] into my url as a variable to pass along to another page. This is what I have that is not working.

<a href="http://mydomain.com/Default.aspx/?ID=$_SESSION['customer_id']">Link text</a>

what you see is what I get. It successfully sends you to the new page but instead of ?ID=value it remains ?ID=$_SESSION['customer_id']

The problem is because you are "quoting" the entire string/URL, as such, "$_SESSION['customer_id']" is being taken literally.

Try rewriting the URL so it reads:
<a href="http://mydomain.com/Default.aspx/?ID=".$_SESSION['customer_id']>Link text</a>

(note, I've removed the end quote and placed it after the '='). The 'dot' between the 'new' quote and the $_SESSION variable is PHP's method of concatenating two strings. Since the $_SESSION variable is now 'exposed' (not contained within quotes) the actual ID will be inserted after the '='.

Cheers
Rod

5 Mar 2013, 2:05 PM
#3
marksmanaz avatar

marksmanaz

New Zenner

Join Date:
Jul 2009
Posts:
5
Plugin Contributions:
0

Re: Inserting Customer ID into hyperlink as querystring in checkout_success

RodG,
Thank you so much, I needed a fresh set of eyes. Unfortunately now that I changed the hyper link by moving the quotes in I only get this:

mydomain.com/Default.aspx/?ID=

I know I am in session because I can see that my test customer is logged in. Can I assume that the customer_id session variable is filled every time a customer logs in? Or only after creating an account? I will try another variable to see if I can pull any value from the session at all. Any suggestions would be great.

Thank you,

Mark

5 Mar 2013, 2:22 PM
#4
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Inserting Customer ID into hyperlink as querystring in checkout_success

marksmanaz:

Can I assume that the customer_id session variable is filled every time a customer logs in? Or only after creating an account?

I'd assume it'll be set whenever the customer is logged in. you know what they say about assumptions though.

marksmanaz:

I will try another variable to see if I can pull any value from the session at all. Any suggestions would be great.

Regardless of what you find, one suggestion I will make anyway, is rather than blindly assuming the $_SESSION['customer_id'] will be set and using it for the URL, I'd be inclined to perform a pre-check.

Something like:

if (isset($_SESSION['customer_id'])) {
$URL = "<a href="http://mydomain.com/Default.aspx/?ID=**".**$_SESSION['customer_id']>Link text</a>" ;
echo "$URL" ;

} else {

echo "$_SESSION['customer_id'] not set" ;
}

(Note how I've needed to 'escape' the embedded quote characters in this example).

Cheers
Rod

5 Mar 2013, 2:44 PM
#5
marksmanaz avatar

marksmanaz

New Zenner

Join Date:
Jul 2009
Posts:
5
Plugin Contributions:
0

Re: Inserting Customer ID into hyperlink as querystring in checkout_success

Thanks again Rod,
I am going to make another assumption here (lol) as I place this code in the define_checkout_success.php in the admin tools section it actually shows the code on the success page. That will be telling me that I can only use html in the define_checkout_success.php page. Where should I be placing this code to get the proper output of "Link Text" as a hyperlink on the page to the define_checkout_success.php page? Or do I need to "wrap" the code in some way so it renders from there properly?

Thanks again

5 Mar 2013, 4:42 PM
#6
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Inserting Customer ID into hyperlink as querystring in checkout_success

If you were getting the (incorrect) info added to your URL string, you were probably editing in the right place; but we need more context to advise correctly on how to make it work.

Is your link code inside or outside of <?php ?> tags? Outside will be outputting straight HTML and you would use something like```php
<a href="http://mydomain.com/Default.aspx/?ID=<?php echo $_SESSION['customer_id'];?>">Link text</a>

If inside PHP, the link string will be echoed or added to a variable for output, and you would have something resembling```php
$content .= '<a href="http://mydomain.com/Default.aspx/?ID=' . $_SESSION['customer_id'] . '">Link text</a> ';

Posting several lines around the place you are editing will help us help you.

13 Mar 2013, 1:21 PM
#7
marksmanaz avatar

marksmanaz

New Zenner

Join Date:
Jul 2009
Posts:
5
Plugin Contributions:
0

Re: Inserting Customer ID into hyperlink as querystring in checkout_success

I am sorry it has been a few days since I left off on this I had other urgent matters to attend to and I am now just getting back to this issue.

gjh42 I have attached a screen capture so you can see what I mean about the actual code that RodG suggested I used show on the checkout_success page. As you can see the code is visible to the user and does not render as intended. I am inserting the code in the define_checkout_success.php in the admin tools section.

This is what I have inserted into the page using the define pages editor:

<p><strong>Checkout Success Sample Text ...</strong></p><p>A few words about the approximate shipping time or your processing policy would be put here. </p> <p>This section of text is from the Define Pages Editor located under Tools in the Admin.</p>

if (isset($_SESSION['customer_id'])) {
$URL = "<a href="http://mydomain.com/Default.aspx/?ID=".$_SESSION['customer_id']>Link text</a>" ;
echo "$URL" ;

} else {

echo "$_SESSION['customer_id'] not set" ;
}

Any help appreciated as I am new to php.

Thanks,

Mark

Attachment 12142

13 Mar 2013, 1:36 PM
#8
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Inserting Customer ID into hyperlink as querystring in checkout_success

marksmanaz:

if (isset($_SESSION['customer_id'])) {
$URL = "<a href="http://mydomain.com/Default.aspx/?ID=".$_SESSION['customer_id']>Link text</a>" ;
echo "$URL" ;

} else {

echo "$_SESSION['customer_id'] not set" ;
}

Before this code you'll need to add a line that reads

<?php ; // turns PHP on // Then after the code you'll need to add ?> ; // Turn PHP off. (unless more php code follows)

Cheers
Rod

13 Mar 2013, 11:22 PM
#9
marksmanaz avatar

marksmanaz

New Zenner

Join Date:
Jul 2009
Posts:
5
Plugin Contributions:
0

Re: Inserting Customer ID into hyperlink as querystring in checkout_success

I want to take the time to thank Rod and gjh42 for all their help as I was able to get the customer ID to carry over in a query-string following their instructions. Thank you so much and have a wonderful day.

Mark

14 Mar 2013, 6:21 AM
#10
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Inserting Customer ID into hyperlink as querystring in checkout_success

marksmanaz:

I want to take the time to thank Rod and gjh42 for all their help as I was able to get the customer ID to carry over in a query-string following their instructions. Thank you so much and have a wonderful day.

Thanks. We appreciate knowing the problem has been solved. Your personal thanks is icing on the cake :)

Cheers
Rod