quantrum Posted April 10, 2008 Share Posted April 10, 2008 Hi, I'm just wondering, how'd I write into the shopping cart that upon clicking checkout, if a set item isn't in the basket then you have to go back to it to add it ? so like something along the lines of (not code just a better example of what i mean) if the cart does not contain (product_id 63) then go to (product_id 63) else continue with checkout and see if person is logged in etc...etc... Thanks, Mark Link to comment Share on other sites More sharing options...
photofxplus Posted April 10, 2008 Share Posted April 10, 2008 Something like this: On page checkout_shipping.php, towards the top before Lines: // if the customer is not logged on, redirect them to the login page if (!tep_session_is_registered('customer_id')) { $navigation->set_snapshot(); tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL')); } Put this: if (!$cart->in_cart(63)) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, '?products_id=63')); } Lloyd Link to comment Share on other sites More sharing options...
quantrum Posted April 10, 2008 Author Share Posted April 10, 2008 Excellent, thanks, thats half the problem I got sorted :thumbsup: now i just gotta get it so that if product 63 is in the cart that it continues to the login screen if (!$cart->in_cart(63)) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=63')); } if (!tep_session_is_registered('customer_id')) { $navigation->set_snapshot(); tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL')); } thats what i've got thanks to photofxplus n the help is greatly appreciated, just need to put like some form of else statement in there like, if it is there, then continue on to the login section or else carry on further any ideas ? Link to comment Share on other sites More sharing options...
photofxplus Posted April 10, 2008 Share Posted April 10, 2008 That should do both. If the product is not in the cart it redirects. So-- if the product is in the cart then it continues with the purchase - normal osC ops. Lloyd Link to comment Share on other sites More sharing options...
quantrum Posted April 10, 2008 Author Share Posted April 10, 2008 ah i see....it doesnt seem to wanna cause i added the product to the cart and it just continued on anyway to product id 63 :unsure: Link to comment Share on other sites More sharing options...
photofxplus Posted April 10, 2008 Share Posted April 10, 2008 OK, the function in_cart just checks to see if the product_id is set. Sorry.. You would need to use the function: get_products() This returns an array of all the products_id in the cart, then loop thru the array searching for '63'. Such as: $redirect = true; while ($products = $cart->get_products()) { if ((int)$products['id'] == 63) { $redirect = false; break; } if ($redirect) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=63')); } Please be advised that the product_id returned by the above function may include parameters in which case you may need to format with the function: function tep_get_prid($uprid) Lloyd Link to comment Share on other sites More sharing options...
quantrum Posted April 10, 2008 Author Share Posted April 10, 2008 OK, the function in_cart just checks to see if the product_id is set. Sorry.. You would need to use the function: get_products() This returns an array of all the products_id in the cart, then loop thru the array searching for '63'. Such as: $redirect = true; while ($products = $cart->get_products()) { if ((int)$products['id'] == 63) { $redirect = false; break; } if ($redirect) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=63')); } Please be advised that the product_id returned by the above function may include parameters in which case you may need to format with the function: function tep_get_prid($uprid) so without making myself seem like a complete retard...how would I implement the code into the cart ? is it just paste something like that into the same place as the other ? Thanks for all your help, you've no idea how much i appreciate it Link to comment Share on other sites More sharing options...
photofxplus Posted April 10, 2008 Share Posted April 10, 2008 I just looked at the first function again: in_cart($products_id) It requires the product uprid not the product_id. Thats the thing about messing with the shopping cart - it places orders in the basket using all parameters seperated by {}. The first example I gave you will work however you will need to find the product id string. You can do this by adding the item 63 to the basket then going to your database table 'customers_basket'. Look under the column 'products_id'. You should see something like: 63{6}14. The middle and last number will not be the same as shown - look at the first number. The first number there is the product id you ar looking for. Copy this entire string and paste into: if (!$cart->in_cart('63{6}14')) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=63')); } Please note I have removed the '?' from FILENAME_PRODUCT_INFO, 'products_id=63' you do not need that. There are other functions in the class 'cart' that may be easier but that should work. It will check for the product in the cart. If it is there than normal osC should continue. If not then redirect. Lloyd Link to comment Share on other sites More sharing options...
quantrum Posted April 10, 2008 Author Share Posted April 10, 2008 I just did what you said and put if (!$cart->in_cart('63{28}267')) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=63')); } above the login bit as you said before on the checkout_shipping.php page, but its still doing the same thing...its redirecting whether i've added it or not i don't think it likes me ... sori to keep bein a pain :'( Link to comment Share on other sites More sharing options...
burt Posted April 10, 2008 Share Posted April 10, 2008 You need to do something different if the product has options. My idea is to make a new function that lists only the product ID's rather than the product ID and the options. Then put them in an array, and then check if the array contains the ID of the product - and if it does not, then redirect back to the product. That would probably be the most straightforward? Link to comment Share on other sites More sharing options...
quantrum Posted April 10, 2008 Author Share Posted April 10, 2008 that sounds like a good idea (to be honest, i will try absolutely anything, it's the only thing stopping a customer from taking the site off me and they annoying me bout it) Only thing is... how would I do something like that ? Link to comment Share on other sites More sharing options...
quantrum Posted April 15, 2008 Author Share Posted April 15, 2008 This problem is still drivin me insane, i've tried so many different things and even spent a day n half reading a huge thick php book back to front to see if that'd have any help for me...but it didnt...but now I know more about PHP...anyone any ideas ? Link to comment Share on other sites More sharing options...
photofxplus Posted April 15, 2008 Share Posted April 15, 2008 Do an echo statement to find out what the function is returning. while (list($key, $value) = each($cart->get_products()) { echo 'key = ' . $key . ' value = ' . $value . '<br>'; } Lloyd Link to comment Share on other sites More sharing options...
quantrum Posted April 15, 2008 Author Share Posted April 15, 2008 Do an echo statement to find out what the function is returning.while (list($key, $value) = each($cart->get_products()) { echo 'key = ' . $key . ' value = ' . $value . '<br>'; } where abouts would I put that to get back what I'd need ? sorry I know this sounds soooo stupid n i just cant understand why it wont work. Link to comment Share on other sites More sharing options...
quantrum Posted April 15, 2008 Author Share Posted April 15, 2008 I just got it to work a little bit more than it did...i got it so that it'll recognise product 63 in the cart and ask you to login, if all of the attributes are set to their default values...but theres quite a few attributes and if i change even one of them...it redirects again back to product number 63 belows what i used if (!$cart->in_cart('63{28}267{19}25{20}283{21}63{22}269{23}135{24}284{25}174{26}273{27}224')) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=63')); } just like you said a couple days ago (i realised i accidently missed a couple of the numbers off towards the end) Link to comment Share on other sites More sharing options...
photofxplus Posted April 15, 2008 Share Posted April 15, 2008 Put it on the page that you would like the customer redirected from if the item is not in the cart. Ill tell ya what - put it on this page: catalog/checkout_payment.php around line 132: <!-- body //--> <table border="0" width="100%" cellspacing="3" cellpadding="3"> change to: <!-- body //--> while (list($key, $value) = each($cart->get_products()) { echo 'key = ' . $key . ' value = ' . $value . '<br>'; } <table border="0" width="100%" cellspacing="3" cellpadding="3"> Lloyd Link to comment Share on other sites More sharing options...
quantrum Posted April 15, 2008 Author Share Posted April 15, 2008 Put it on the page that you would like the customer redirected from if the item is not in the cart. Ill tell ya what - put it on this page: catalog/checkout_payment.php around line 132: <!-- body //--> <table border="0" width="100%" cellspacing="3" cellpadding="3"> change to: <!-- body //--> while (list($key, $value) = each($cart->get_products()) { echo 'key = ' . $key . ' value = ' . $value . '<br>'; } <table border="0" width="100%" cellspacing="3" cellpadding="3"> It just keeps producing errors saying Parse error: syntax error, unexpected '{' then on to the line info etc...etc... and yet whenever I remove the { } from it...it doesnt work Link to comment Share on other sites More sharing options...
photofxplus Posted April 15, 2008 Share Posted April 15, 2008 Try this: $redirect = true; $products = $cart->get_products(); for ($i=0, $n=sizeof($products); $i<$n; $i++) { if ($products[$i]['id'] == 63) { $redirect = false; break; } } if ($redirect) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=63')); } Lloyd Link to comment Share on other sites More sharing options...
quantrum Posted April 15, 2008 Author Share Posted April 15, 2008 Try this: $redirect = true; $products = $cart->get_products(); for ($i=0, $n=sizeof($products); $i<$n; $i++) { if ($products[$i]['id'] == 63) { $redirect = false; break; } } if ($redirect) { tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=63')); } omg omg omg omg omg omg omg omg omg omg omg omg omg omg omg omg omg omg omg omg IT WORKS !!! thank you soooooooo sooo much for all your help, it finally works...YAY !!! THANK YOU !!! i owe you big time for that Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.