Jump to content

Archived

This topic is now archived and is closed to further replies.

Guest

Buy Button on Category Page

Recommended Posts

Guest

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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
Guest

Thank you very much for the prompt and helpful response. It has worked as I envisaged it working.

Your help is very much appreciated.

Share this post


Link to post
Share on other sites
Guest

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

Share this post


Link to post
Share on other sites
Guest

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?

Share this post


Link to post
Share on other sites
Guest estelle

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Guest

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Guest

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

Share this post


Link to post
Share on other sites
Guest freshyseth

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

Share this post


Link to post
Share on other sites

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 ;) :(

Share this post


Link to post
Share on other sites
Guest wamasterhunter

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

Share this post


Link to post
Share on other sites
Guest

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

Share this post


Link to post
Share on other sites
Guest wamasterhunter

Convict,

Worked like a gem,

thank you lots.

Now I just need to get the "more" off the page.

Any Ideas?

thanks,

Micah

Share this post


Link to post
Share on other sites
Guest

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.

Share this post


Link to post
Share on other sites
Guest wamasterhunter

Found it, and fixed it.

Thanks

Share this post


Link to post
Share on other sites
Guest

@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 :)

Share this post


Link to post
Share on other sites

@subten (Euan) I surprised you never posted any feedback there :D :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 :wacko:

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

Share this post


Link to post
Share on other sites
Guest

Convict,

Got round to trying your solution last night and it appears to work :D

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.

Share this post


Link to post
Share on other sites
Guest PaulD

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.

Share this post


Link to post
Share on other sites

×
×
  • Create New...