Guest Posted June 20, 2007 Posted June 20, 2007 Hello Everyone I've written some code that allows me to add items to the cart on my osCommerce site from a form submission on another site. The problem is my code can only handle 1 item at a time and the form may submit upto 4. The data can come across as either 4 separate variables or as csv. Any idea how to adapt the code below to handle this. // customer adds a product from the Thule Database case 'add_product_thule' : if (isset($HTTP_POST_VARS['products_model'])) { $tule_products_model = $HTTP_POST_VARS['products_model']; $thulequery="SELECT products_id FROM products WHERE products_model = $thule_products_model"; $thule_products_id_query = mysql_query($thulequery) or die(mysql_error()); $thule_products_id = mysql_result($thule_products_id_query,0); $cart->add_cart($thule_products_id, $cart->get_quantity(tep_get_uprid($thule_products_id, $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']); } tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); break;
Bloged Posted June 20, 2007 Posted June 20, 2007 Hello Everyone I've written some code that allows me to add items to the cart on my osCommerce site from a form submission on another site. The problem is my code can only handle 1 item at a time and the form may submit upto 4. The data can come across as either 4 separate variables or as csv. Any idea how to adapt the code below to handle this. This totaly depends on how you get your values if you get four totaly different values you have to set them in a array to loop them or if you have them in a array you can loop them directly! This will think you have an array in $HTTP_POST_VARS['products_model']. // customer adds a product from the Thule Database case 'add_product_thule' : if (isarray($HTTP_POST_VARS['products_model'])) { foreach($HTTP_POST_VARS['products_model'] AS $products_model) { $thulequery="SELECT products_id FROM products WHERE products_model = $products_model"; $thule_products_id_query = mysql_query($thulequery) or die(mysql_error()); $thule_products_id = mysql_result($thule_products_id_query,0); $cart->add_cart($thule_products_id, $cart->get_quantity(tep_get_uprid($thule_products_id, $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']); } } tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); break; If you have more questions just ask them! Grtz, Arjan Gelderblom I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. -- Stephen Hawking
Bloged Posted June 20, 2007 Posted June 20, 2007 Saw an error in the code, so here it is with change: // customer adds a product from the Thule Database case 'add_product_thule' : if (isarray($HTTP_POST_VARS['products_model'])) { foreach($HTTP_POST_VARS['products_model'] AS $products_model) { $thulequery="SELECT products_id FROM products WHERE products_model = $products_model"; $thule_products_id_query = mysql_query($thulequery) or die(mysql_error()); $thule_products_id = mysql_result($thule_products_id_query,0); $cart->add_cart($thule_products_id, $cart->get_quantity(tep_get_uprid(products_model, $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']); } } tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); break; Grtz, Arjan Gelderblom I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. -- Stephen Hawking
Recommended Posts
Archived
This topic is now archived and is closed to further replies.