Guest Posted January 3, 2007 Share Posted January 3, 2007 My php knowledge is nil. I have done things through trial and error with success but have had no luck achieving this. On the Category Page I have a list of products with 'Buy' and 'More' buttons. At the moment, if you select Buy it adds it to the basket and takes you to the product page. I don't want it to take you to the product page and I want to keep customers on the Category page. Does anyone know if this can be done and if so... how to do it? Thanks, Euan Quote Link to comment Share on other sites More sharing options...
markscarts Posted January 3, 2007 Share Posted January 3, 2007 Well, you can try this, it worked on my test store. Be careful - make copies of both files, in case you do not like the way it works or have problems with the code later! 1. OPEN includes/content/viewCat.inc.php LOOK for this line of code ( !! in three places !! ) $view_cat->parse("view_cat.productTable.products.buy_btn"); PASTE this line of code ABOVE it ( !! in three places !! ) $view_cat->assign("CAT_ID",$currentCat[0]['cat_id']); SAVE, CLOSE and UPLOAD that file. 2. OPEN skins/xx/styleTemplates/content/viewCat.tpl FIND this code (within a line of code around line 40): href="java script:submitDoc('prod{PRODUCT_ID}');'" REPLACE with this code: href="java script:submitDoc('prod{PRODUCT_ID}'); location='index.php?act=viewCat&catId={CAT_ID}'" NOTE!!! For security reasons, this forum separates the single word "javascript" into two words! When you search for or paste/replace the code above, make sure you turn the "javascript" back into one word! Quote Link to comment Share on other sites More sharing options...
Guest Posted January 3, 2007 Share Posted January 3, 2007 Thank you very much for the prompt and helpful response. It has worked as I envisaged it working. Your help is very much appreciated. Quote Link to comment Share on other sites More sharing options...
markscarts Posted January 3, 2007 Share Posted January 3, 2007 You're welcome :( Quote Link to comment Share on other sites More sharing options...
Guest Posted January 9, 2007 Share Posted January 9, 2007 For some products the above code works - and for others it just won't add them to the basket. Any ideas why? Also, when you search and press the buy button on the search results, it comes up and says no products in this category? Thanks again for your assistance. Euan Quote Link to comment Share on other sites More sharing options...
Al Brookbanks Posted January 9, 2007 Share Posted January 9, 2007 Is it because they have product options that need selecting? Quote Link to comment Share on other sites More sharing options...
Guest Posted January 9, 2007 Share Posted January 9, 2007 There are no product options at all. If it was a session problem... is there anyway that can be resolved? In addition, what files do I need to edit so that on the search results it would do the same thing and not say "There are no products in this category" when you click the Buy button? Quote Link to comment Share on other sites More sharing options...
markscarts Posted January 10, 2007 Share Posted January 10, 2007 If you feel the code I gave above is causing the problems, please restore your backup files. Quote Link to comment Share on other sites More sharing options...
Guest estelle Posted January 10, 2007 Share Posted January 10, 2007 This is a bug in new versions of CubeCart. Caused by the following code added in includes/boxes/shoppingCart.inc.php... // prevents refresh adding extras to the basket header("Location: index.php?act=viewProd&productId=".$_POST['add']); exit; Personally I would just comment out the above code. Quote Link to comment Share on other sites More sharing options...
markscarts Posted January 10, 2007 Share Posted January 10, 2007 That makes sense, because the javascript I added is reloading the page to keep the visitor on viewCat. Rather than doing away with the "do not re-add prods on refresh" code, see your other post at .com where convict has posted a possible solution for the bug. Quote Link to comment Share on other sites More sharing options...
Guest Posted January 10, 2007 Share Posted January 10, 2007 Estelle and Mark, Thanks for your responses. I apologise now but I am a little confused as to what I should do now (probably due to my nil understanding of php, etc). Are you saying I should leave the code Mark provided as is and just comment out the 2 lines of code Estelle provided? / prevents refresh adding extras to the basket header("Location: index.php?act=viewProd&productId=".$_POST['add']); exit; Thanks, Euan Quote Link to comment Share on other sites More sharing options...
Al Brookbanks Posted January 10, 2007 Share Posted January 10, 2007 I would suggest using the following code you mentioned: header("Location: index.php?act=viewProd&productId=".$_POST['add']); exit; You could use the http referrer but that isn't reliable. Quote Link to comment Share on other sites More sharing options...
Guest Posted January 10, 2007 Share Posted January 10, 2007 I would suggest using the following code you mentioned: header("Location: index.php?act=viewProd&productId=".$_POST['add']); exit; You could use the http referrer but that isn't reliable. Al, Thanks for the reply. How do you mean use the following code I mentioned? Do you mean comment it out or do you mean use it in the viewCat.tpl file as the link reference? Sorry for asking so many questions - this is all a learning process for me. Euan Quote Link to comment Share on other sites More sharing options...
Guest freshyseth Posted January 30, 2007 Share Posted January 30, 2007 I have updated the information in the "includes/boxes/shoppingCart.inc.php" to be the following: // prevents refresh adding extras to the basket if(isset($_POST['location'])){ $location = $_POST['location']; }else{ $location = "act=viewProd&productId=".$_POST['add']; } header("Location: index.php?".$location); exit; Then I set in the "includes/content/viewCat.inc.php": if(isset($_GET['page'])){ $view_cat->assign("PAGE_NUM",$_GET['page']); }else{ $view_cat->assign("PAGE_NUM",""); } $view_cat->assign("CAT_ID",$currentCat[0]['cat_id']); in the same 3 places that Mark suggested. Notice the last line in the above code block is the code that Mark recommended at the beginning of this post. Then I have in "skins/{yourstyle}/styleTemplates/viewCat.tpl": <!-- BEGIN: buy_btn --> <input type="hidden" name="add" value="{PRODUCT_ID}" /> <input type="hidden" name="location" value="act=viewCat&catId={CAT_ID}&page={PAGE_NUM}" /> <input type="text" name="quan" value="1" size="1" /> <a href="java script:submitDoc('prod{PRODUCT_ID}');" class="txtButton">{BTN_BUY}</a> <!-- END: buy_btn --> The code in viewCat.inc.php assigns the current page number for the category to the PAGE_NUM template variable. Then I include it in the location redirect. This way if you are on page 3 of a category and add a product to the cart it returns you to page 3 of the category instead of page 1. Also, you'll notice that I have a text box for <input> named "quan". This is so that the user can enter the quantity of products they want, hit the "Buy" button and it will add that quantity of products to the cart and return them to the exact same page they were just on, which to them looks like they didn't go anywhere and the product was just added. I removed the "More" button to make room for the input field. They can still get to product details by clicking on the image or title of the product. Hope this helps! freshyseth Quote Link to comment Share on other sites More sharing options...
markscarts Posted January 30, 2007 Share Posted January 30, 2007 Godd work! ;) Quote Link to comment Share on other sites More sharing options...
convict Posted January 31, 2007 Share Posted January 31, 2007 I posted this in cubecart.org on January, 10th as a reponse to Eauan - subten request: ----------- There are couple of another solutions like this one: viewCat.tpl <!-- BEGIN: buy_btn --> <input type="hidden" name="stay" value="" /> includes/boxes/shoppingCart.inc.php if (!isset($_POST['stay'])) { // prevents refresh adding extras to the basket header("Location: index.php?act=viewProd&productId=".$_POST['add']); exit; } Red marked is new code. Never tried but should work. ----------- @subten (Euan) I surprised you never posted any feedback there :( Quote Link to comment Share on other sites More sharing options...
Guest wamasterhunter Posted February 5, 2007 Share Posted February 5, 2007 Help, I followed freshyseth's instructions and now the first product of each list puts the LAST product in the list into the cart, but the rest give me an error that says:The form you are attempting to subit called 'prodxx' coulden't be found. Please make sure the submitDoc function has the correct id and name". I checked and the code is the same. Thanks Micah www.webtest.creationtidbits.com Quote Link to comment Share on other sites More sharing options...
Guest Posted February 5, 2007 Share Posted February 5, 2007 Guys, Never noticed these new posts over the last few days. I'll check them out tonight and see how well they work. Thanks, Euan Quote Link to comment Share on other sites More sharing options...
Guest wamasterhunter Posted February 5, 2007 Share Posted February 5, 2007 Convict, Worked like a gem, thank you lots. Now I just need to get the "more" off the page. Any Ideas? thanks, Micah Quote Link to comment Share on other sites More sharing options...
Guest Posted February 5, 2007 Share Posted February 5, 2007 Convict, Worked like a gem, thank you lots. Now I just need to get the "more" off the page. Any Ideas? thanks, Micah Remove the more button from the category box in the templates folder within your skin. Quote Link to comment Share on other sites More sharing options...
Guest wamasterhunter Posted February 5, 2007 Share Posted February 5, 2007 Found it, and fixed it. Thanks Quote Link to comment Share on other sites More sharing options...
Guest Posted February 5, 2007 Share Posted February 5, 2007 @subten (Euan) I surprised you never posted any feedback there Yeah sorry Convict... work has been mad (I only do this as a hobby) and I've only just found time to do some work as you'll know from me buying your mods :) Quote Link to comment Share on other sites More sharing options...
convict Posted February 10, 2007 Share Posted February 10, 2007 @subten (Euan) I surprised you never posted any feedback there :D Yeah sorry Convict... work has been mad (I only do this as a hobby) and I've only just found time to do some work as you'll know from me buying your mods Null problemo, well work is mad sometime however i feel mad because of work LOL Only I wanted to see how it works, thanks to wamasterhunter :D Quote Link to comment Share on other sites More sharing options...
Guest Posted March 21, 2007 Share Posted March 21, 2007 Convict, Got round to trying your solution last night and it appears to work Will test it on various computers on different connections to ensure that it is ok. Just need to try an incorporate it on the homepage with the latest products... that's a job for the weekend! Thanks again Convict and everyone else who has posted here. Quote Link to comment Share on other sites More sharing options...
Guest PaulD Posted July 9, 2007 Share Posted July 9, 2007 Well, you can try this, it worked on my test store. Be careful - make copies of both files, in case you do not like the way it works or have problems with the code later! 1. OPEN includes/content/viewCat.inc.php LOOK for this line of code ( !! in three places !! ) $view_cat->parse("view_cat.productTable.products.buy_btn"); PASTE this line of code ABOVE it ( !! in three places !! ) $view_cat->assign("CAT_ID",$currentCat[0]['cat_id']); SAVE, CLOSE and UPLOAD that file. 2. OPEN skins/xx/styleTemplates/content/viewCat.tpl FIND this code (within a line of code around line 40): href="java script:submitDoc('prod{PRODUCT_ID}');'" REPLACE with this code: href="java script:submitDoc('prod{PRODUCT_ID}'); location='index.php?act=viewCat&catId={CAT_ID}'" NOTE!!! For security reasons, this forum separates the single word "javascript" into two words! When you search for or paste/replace the code above, make sure you turn the "javascript" back into one word! Wow - Thank you ever so much. I really thought I could do this but after 2 hours of failing miserably I searched cube cart and found this. Fantastic!!!! I would never have worked that out. Brilliant. Works perfectly and I can go to sleep now (it is quite late) happy!!! Thank you again Paul. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.