Guest Posted May 20, 2003 Posted May 20, 2003 Hello, I have tried with no success to provide a link that will add an item to cart from an external page to oscommerce. Any assistance will be appreciated. -R
josheli Posted May 21, 2003 Posted May 21, 2003 sure, just put the form from product_info.php on your external page, like this example: http://www.austinbeads.com/_test.html use an image: <form name="cart_quantity" action="http://www.josheli.com/catalog/product_info.php?products_id=24&action=add_product" method="post"> <input type="hidden" name="products_id" value="24"><input type="image" src="http://www.josheli.com/catalog/includes/languages/english/images/buttons/button_in_cart.gif" border="0" alt="In Cart" title=" In Cart "></form> use a link: <form name="cart_quantity2" action="http://www.josheli.com/catalog/product_info.php?products_id=24&action=add_product" method="POST"> <input type="hidden" name="products_id" value="24"><a href="javascript:document.cart_quantity2.submit();">Add to cart</a></form>
Guest Posted May 21, 2003 Posted May 21, 2003 What about appending the posted data to the url? Something along the lines of http://www.josheli.com/catalog/product_inf...ion=add_product (the above link doesn't work) Is it possible to use GET instead of POST?
josheli Posted May 21, 2003 Posted May 21, 2003 the link does work .... when it is inside the form i posted above. in application_top.php there is this code to add a product case 'add_product' : if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) { $cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']); } tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); break; you can try to add GET vars, though be careful with the "$HTTP_POST_VARS['id']" variable. it's the attribute array and the only way to pass an array in the URL is to implode it to a string, append all that data to the URL, then explode/split it back to an array on the other side. so, something like this (though it might mess something else up somewhere else)... case 'add_product' : if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) { $cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']); } elseif(isset($HTTP_GET_VARS['products_id']) && is_numeric($HTTP_GET_VARS['products_id'])) { $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_GET_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']); } tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); break; or, you can add a flag to the link, something like http://www.josheli.com/catalog/product_inf...oduct&offsite=1 then, before the "// Shopping cart actions" you can try to set the post vars with the get vars something like... if(isset($HTTP_GET_VARS['offsite']) && $HTTP_GET_VARS['offsite']==1 && isset($HTTP_GET_VARS['products_id']) && is_numeric($HTTP_GET_VARS['products_id'])) { $HTTP_POST_VARS['products_id']=$HTTP_GET_VARS['products_id']; } but what's wrong with the form method i posted above?
Guest Posted May 21, 2003 Posted May 21, 2003 Nothing is wrong with the code, I am just trying to create a link that will not be dependent on a form. You solutions will defintely work. Thanks.
Xajar Posted May 23, 2003 Posted May 23, 2003 josheli or anyone, The information you provided works, however it does not add the product attributes. Do you know what you need to do to get the attributes of the product added at the same time? Either by url reference, or form reference, but outside of osc. Thanks in advance! Xar
Xajar Posted May 23, 2003 Posted May 23, 2003 josheli or anyone, The information you provided works, however it does not add the product attributes. Do you know what you need to do to get the attributes of the product added at the same time? Either by url reference, or form reference, but outside of osc. Thanks in advance! Xar
loxly Posted May 23, 2003 Posted May 23, 2003 There is an xml contribution in the downloads you might want to check out. [no external urls in signatures please, kthanks]
Guest Posted May 23, 2003 Posted May 23, 2003 Can you provide a link to the contribution ... couldn't find it.
josheli Posted May 23, 2003 Posted May 23, 2003 yes it does add them to the cart, if you put the options/attribs in the form... example (josheli.com will add to austinbeads.com): http://www.josheli.com/_test.html options/attributes are posted to the form in the id[] array. they are usually passed around osc (though not to the shopping cart) in a url something like this... http://www.site.com/catalog/somepage.php?p...id=34{5}21{63}4 where 34=product id 5 and 63 are option ids 21 and 4 are the corresponding attribute ids.
shaunklink Posted February 25, 2006 Posted February 25, 2006 I knows it's been years since this question was answered....but I want to know how to determine the attribute id's and option id's once they are added to the system?
doorwish Posted December 31, 2007 Posted December 31, 2007 Hi People! Well I have the same problem at the moment and need to link different "add to cart" buttons to products with different attributes from an external page/site. A direct link like "josheli" mentioned would be perfect. But does it work? And what is the link to that contribution "loxly" ?????????? Your post is no help at all like that! :( Please HELP! :) IT?s ALL good!!!
jasperss Posted September 29, 2008 Posted September 29, 2008 Hi everyone, I know this is probably really simple but im kinda new to all this stuff. Thanks to the advise of this forum i've managed to get the <form name="cart_quantity2" action="http://mysite.com/product_info.php?products_id=24&action=add_product" method="POST"> <input type="hidden" name="products_id" value="24"><a href="java script:document.cart_quantity2.submit();" >Add to cart</a></form> to work (thanks!). But im using an iframe on this page and the 'add to cart' link is in the iframe. I'm trying to get it to load the shopping_cart.php page in the parent frame rather than in the iframe when 'add to cart' is clicked. I tried <form name="cart_quantity2" action="http://mysite.com/product_info.php?products_id=24&action=add_product" method="POST"> <input type="hidden" name="products_id" value="24"><a href="java script:document.cart_quantity2.submit();" target="_parent">Add to cart</a></form> but no joy. Can anyone help, i'm guessin it can be done with simple javascript? Thanks, Matt
jasperss Posted September 30, 2008 Posted September 30, 2008 whops! Got it. target in wrong place. <form name="cart_quantity2" action="http://mysite.com/product_info.php?products_id=24&action=add_product" target="_parent" method="POST"> <input type="hidden" name="products_id" value="24"><a href="java script:document.cart_quantity2.submit();" >Add to cart</a></form> works. Matt
silasp Posted March 21, 2009 Posted March 21, 2009 You can use a link like the following: www.yourwebsite.com/catalog/index.php?action=buy_now&products_id=XX Replace URL with your actual site and change products_id=XX to the product ID you wish to add to the cart. This works great for individual items, not sure about items with attributes. Give it a test and see how you go. Cheers, Silas.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.