Given2Fly Posted July 20, 2004 Posted July 20, 2004 Hi, I need help creating an if else statement for shoppingcart.php. Basically, if someone adds product 29 to their cart, the page sees that and redirects them to a page that will show them the course materials they will need to go along with that. Can anyone help?
peterr Posted July 20, 2004 Posted July 20, 2004 Hi, I can't remember what the variable name is in osC for product ID (or it's maybe from an array ?? ), anyway let's assume it is called 'product_id' for this exercise, the code would be something like: <?PHP if(product_id == '29') { header("Location: http://www.example.com/course_materials.php"); /* Redirect browser */ } ?> Read up on the header() function here at PHP.NET Peter
TomThumb Posted July 20, 2004 Posted July 20, 2004 In /catalog/includes/application_top.php starting at line 356 you need to change 2 case statements. Original code // customer adds a product from the products page 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; // performed by the 'buy now' button in product listings and review page case 'buy_now' : if (isset($HTTP_GET_VARS['products_id'])) { if (tep_has_product_attributes($HTTP_GET_VARS['products_id'])) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id'])); } else { $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+1); } } tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); break; add if ($HTTP_POST_VARS['products_id'] == '29') { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=24')); } else { Where 24 is the product you want to redirect them to. Above each tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); to get this as the final // customer adds a product from the products page 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']); } if ($HTTP_POST_VARS['products_id'] == '29') { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=24')); } else { tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); break; // performed by the 'buy now' button in product listings and review page case 'buy_now' : if (isset($HTTP_GET_VARS['products_id'])) { if (tep_has_product_attributes($HTTP_GET_VARS['products_id'])) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id'])); } else { $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+1); } } if ($HTTP_POST_VARS['products_id'] == '29') { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=24')); } else { tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); break; while (!succeed) {try()}; GMT -6:00
Given2Fly Posted July 20, 2004 Author Posted July 20, 2004 Thank you both.. I tried the second one, and now I get this error.... Parse error: parse error, unexpected T_CASE in /home/jamesray/public_html/eventscart/includes/application_top.php on line 369 This is line 369 case 'buy_now' : if (isset($HTTP_GET_VARS['products_id'])) { Any thoughts?
Given2Fly Posted July 20, 2004 Author Posted July 20, 2004 Peterr, Where would I put your code? In the header.php or in shoppingcart.php or? Thanks!
TomThumb Posted July 20, 2004 Posted July 20, 2004 In the future post the whole error message. Sorry, I had not tested this. We just need to take out the else statements. So change it to this. // customer adds a product from the products page 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']); } if ($HTTP_POST_VARS['products_id'] == '29') { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=24')); } tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); break; // performed by the 'buy now' button in product listings and review page case 'buy_now' : if (isset($HTTP_GET_VARS['products_id'])) { if (tep_has_product_attributes($HTTP_GET_VARS['products_id'])) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id'])); } else { $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+1); } } if ($HTTP_POST_VARS['products_id'] == '29') { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=24')); } tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); break; while (!succeed) {try()}; GMT -6:00
Recommended Posts
Archived
This topic is now archived and is closed to further replies.