Jump to content

Buy Button on Category Page


Guest

Recommended Posts

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

Link to comment
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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
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.

Link to comment
Share on other sites

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

Link to comment
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.

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

Link to comment
Share on other sites

  • 3 weeks later...
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

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

Link to comment
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
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

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

  • 3 months later...
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...