Author Topic: Redirection to external URL after 'add to cart' clicked?  (Read 3933 times)

SecureYourself

  • Beginner
  • *
  • Posts: 3
    • SecureYourself.co.uk - Free and easy to understand internet security advice
Redirection to external URL after 'add to cart' clicked?
« on: June 01, 2010, 22:26:48 pm »
Hi guys,

I wish to (for only certain products) redirect users to an external website after clicking the 'add to cart' button. This URL will be different for different products.

I have spent a long time trawling through forums to find an answer or solution to this idea, but to no avail.

I appreciate any comments or ideas you guys may have.

richsung

  • Jr. Member
  • **
  • Posts: 85
Re: Redirection to external URL after 'add to cart' clicked?
« Reply #1 on: June 01, 2010, 23:03:48 pm »
There's a field that settable in the backend for each product called product_url... if you wanted to, you could keep it blank for regular products (ones that will use the regular checkout process), but when you have a custom external checkout required, the flypage could be modified to check if product_url is different not equal to ""...

In this case, the Add to Cart link could be replaced with a different link (perhaps also warning the user that they'll be re-directed to an external link).

--Rich
--Rich

SecureYourself

  • Beginner
  • *
  • Posts: 3
    • SecureYourself.co.uk - Free and easy to understand internet security advice
Re: Redirection to external URL after 'add to cart' clicked?
« Reply #2 on: June 02, 2010, 20:04:54 pm »
Thank you very much richsung for your prompt and clear response to my question.

However, I am still trying to decipher as to what coding to use to check if product_url is equal to blank  and if not to continue onto a specific URL etc.

Would it just be a simple IF statement (e.g. If Product_URL = "www.secureyourself.co.uk" then redirect to 'www.secureyourself.co.uk') and if so where do I find this PHP file etc?

At the moment, when I insert a URL into the product url field I see nothing changing on the front end?

Thanks again!

richsung

  • Jr. Member
  • **
  • Posts: 85
Re: Redirection to external URL after 'add to cart' clicked?
« Reply #3 on: June 02, 2010, 22:49:19 pm »
Have a look at the directory:
/components/com_virtuemart/themes/default/templates/product_details if you're using the default virtuemart template. Edit the php file that you're using as your flypage template.

This post might be helpful (if product_url can't be seen in the flypage):
http://forum.virtuemart.net/index.php?action=printpage;topic=60766.0

Once you're getting the product_url field visible at the template level
As for the code, there's a spot in the template where's it's outputting the add to cart icon:
<?php echo $addtocart ?>

You'd change that to somethink like
<?php

if ($product_url == ""){
  echo $addtocart;
} else {
  echo "<a target=\"_blank\" href=\"".$product_url."\">Go to external site</a><br />";
}

Something like that... format as desired.

--Rich







Thank you very much richsung for your prompt and clear response to my question.

However, I am still trying to decipher as to what coding to use to check if product_url is equal to blank  and if not to continue onto a specific URL etc.

Would it just be a simple IF statement (e.g. If Product_URL = "www.secureyourself.co.uk" then redirect to 'www.secureyourself.co.uk') and if so where do I find this PHP file etc?

At the moment, when I insert a URL into the product url field I see nothing changing on the front end?

Thanks again!

SecureYourself

  • Beginner
  • *
  • Posts: 3
    • SecureYourself.co.uk - Free and easy to understand internet security advice
Re: Redirection to external URL after 'add to cart' clicked?
« Reply #4 on: June 03, 2010, 23:07:06 pm »
Thank you so much for your help.

What you have advised has worked beautifully! It was exactly the solution I was after.

But could I just ask one more thing from you please. Upon the new browser window opening after clicking the link (using the above code that you gave me), the new window opens and inserts the "Product_URL" variable in the address bar as it should, but it places it AFTER my websites URL?

For example http://www.secureyourself.co.uk/www.ProductURL.co.uk

I just want to be able to edit the coding slightly to remove my website url from the front?

Your input is greatly appreciated!

richsung

  • Jr. Member
  • **
  • Posts: 85
Re: Redirection to external URL after 'add to cart' clicked?
« Reply #5 on: June 04, 2010, 06:38:20 am »
That's an easy one...

Just make sure your product URL is entered as

http://www.ProductURL.co.uk

instead of just www.ProductURL.co.uk

When the user's browser sees an href that doesn't have an http:// before it, it assumes it's a reference based off of the current web site.

--Rich

pamchal

  • Beginner
  • *
  • Posts: 17
Re: Redirection to external URL after 'add to cart' clicked?
« Reply #6 on: November 28, 2010, 01:29:54 am »
Hi,
I wanna use a button instead of text (Go to external site) for the link. How am I supposed to change the code?

Thanks in advance

pamchal

  • Beginner
  • *
  • Posts: 17
Re: Redirection to external URL after 'add to cart' clicked?
« Reply #7 on: November 28, 2010, 12:20:46 pm »