View Full Version : Link to ADD TO CART with attributes passed by URL ?

12-09-2013, 11:56 PM

I'm trying to add products-with-attributes to the cart directly using a direct link, without having to go through the "This product has options that must be selected before it can be purchased." attributes selection page.

How can I do that ?

I've already tried:
<a href="http://site.com/product_info.php?products_id=229{5}22&action=buy_now">
<a href="http://site.com/product_info.php?products_id=229{5}22&opts=1&action=add_product">
<a href="http://site.com/shopping_cart.php?action=add_product&products_id=229{5}22>

Whenever I use either of these options, no product is added to the cart.

Any ideas ?

Thank you.

12-10-2013, 09:07 AM
Look around line 520 of catalog/includes/application_top.php for the add_product case.

Find: case 'add_product' :

You will see that the code base is expecting the parameters to be sent via POST not via GET (Ie in the URL).

You can either code up your link into a POST form OR recode the application_top.php to look for POST or GET.

Up to you really!

The whole statement is wrapped in an IF

if (isset($_POST['products_id']) && is_numeric($_POST['products_id']) && ($_POST['products_id']==(int)$_POST['products_id'])) {

So you should be able to copy this entire IF and simply replace $_POST with $_GET and then put in after it and before:

tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));


12-15-2013, 02:19 AM
Hello pgmarshall,

Thank you for your answer. I've been trying to pull this off, no luck unfortunately.

In option 1, code up the link into a POST form: how do I do that ? can you please post an example ?

In option 2, recode application_top.php: is there any downside to that ?
I kinda prefer option 1, as it doesn't involve recoding.

In this case, how would a link of this form look like ?


12-15-2013, 03:38 PM
To further clarify what I need to do:

I'd like to do nice-looking html pages (for example landing pages), with a list of products with nice images... or banners on a blog, with a link to product-with-attributes-ADD-TO-CART, etc.

In other words, these links should be directly linked to a product + attributes + ADD TO CART action.

All of this looks quite easy, except when I want to pass the product's attribute along with that link.

For example, a table with iPods, every one with a different color and capacity, or with accessories included.... Everything calls the same product with different attributes.

How do I refer to these links-to-product-with-attributes-ADD-TO-CART ?

I've been doing much more complex stuff on my cart, I've got the feeling that this is way easier than what I'm (unsuccessfully) trying :(