Forums / Bug Reports / [Done v1.5.0] Stay on product listing after adding to cart

[Done v1.5.0] Stay on product listing after adding to cart

Started by bobmoss on 12 Feb 2011, 12:58 AM · Views: 6,662

Results 1 to 20 of 24
12 Feb 2011, 12:58 AM
#1
bobmoss avatar

bobmoss

New Zenner

Join Date:
Dec 2010
Posts:
20
Plugin Contributions:
0

[Done v1.5.0] Stay on product listing after adding to cart

I've got a buy it now button next to each product in the category product listing page.

When the user clicks on this button I want to add the product to the cart and stay exactly where they are - i.e. still on category product listing page.

I know there is the option under admin to "Display Cart After Adding Product" which I can set to false, but this then takes the user to the product information page, instead of staying right where they are.

I've also tried various hacks to product_listing.php (whcih I found on here using search) to essentially change "zen_href_link(zen_get_info_page..." to be "zen_href_link($_GET['main_page']..." which works to a degree in that it stays on category product listing page, however it seems to "select" the product you have just added. So the breadcrumb now says "Home - Category - Product Name" instead of "Home - Category". Also the "productListHeading" is set to the added product not the category.

So, any ideas how to get this to work properly?

Thanks.

Bob.

12 Feb 2011, 12:17 PM
#2
bobmoss avatar

bobmoss

New Zenner

Join Date:
Dec 2010
Posts:
20
Plugin Contributions:
0

Re: [Done v1.5.0] Stay on product listing after adding to cart

OK, I've managed to figure out how to do this.

Within the product_listing.php file (which if you are using overrides, your overridden copy should be in includes\modules\YOURTEMPLATE, find the section which says:

if (PRODUCT_LIST_PRICE_BUY_NOW == '2' && $listing->fields['products_qty_box_status'] != 0) {  

$lc_button= zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($listing->fields['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $listing->fields['products_id']), 'post', 'enctype="multipart/form-data"') . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($listing->fields['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_draw_hidden_field('products_id', $listing->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) . '</form>';

And change the line to read:

$lc_button= zen_draw_form('cart_quantity', zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=add_product'), 'post', 'enctype="multipart/form-data"') . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($listing->fields['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_draw_hidden_field('products_id', $listing->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) . '</form>';

Note that in addition to changing the zen_href_link bit, you need to remove the '&products_id' code from the action. This is the bit that sets the current product.

Hope this is useful for other people.

Bob.

12 Feb 2011, 3:16 PM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: [Done v1.5.0] Stay on product listing after adding to cart

Before changing code, did you try the setting in the Configuration ... My Store ... for:

Display Cart After Adding Product
Display the shopping cart after adding a product (or return back to their origin)

true
false

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

12 Feb 2011, 3:25 PM
#4
bobmoss avatar

bobmoss

New Zenner

Join Date:
Dec 2010
Posts:
20
Plugin Contributions:
0

Re: [Done v1.5.0] Stay on product listing after adding to cart

I did try that setting, however, as I said in my original message, when you set that to false it doesn't actually take you back to where you were. It takes you back to the product information page for the product you added.

So, if you are on the product listing page and click "add" it moves you to the product details rather thank keeping you exactly where you were.

Bob.

12 Feb 2011, 4:31 PM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: [Done v1.5.0] Stay on product listing after adding to cart

I cannot repeat the problem when it is set to not go to the shopping cart, I stay where I am ...

What version Zen Cart are you using?

What happens if you switch to the Classic Template?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

12 Feb 2011, 6:49 PM
#6
bobmoss avatar

bobmoss

New Zenner

Join Date:
Dec 2010
Posts:
20
Plugin Contributions:
0

Re: [Done v1.5.0] Stay on product listing after adding to cart

Hi Ajeh,

I'm using the latest version of Zen cart (1.3.9h).

I've just switched to "Classic Green" and it does exactly the same thing.

Are you adding a product to the cart from the Product listing page? (rather than the product description page?)

Unfortunately I can't put my site on the internet right now to show you what is happening.

Bob.

12 Feb 2011, 6:55 PM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: [Done v1.5.0] Stay on product listing after adding to cart

Regardless of where ...

Product Listing

Product _info

New Product Listing

I add to cart and stay on the same page ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

14 Feb 2011, 10:58 AM
#8
bobmoss avatar

bobmoss

New Zenner

Join Date:
Dec 2010
Posts:
20
Plugin Contributions:
0

Re: [Done v1.5.0] Stay on product listing after adding to cart

Ajeh:

Regardless of where ...

Product Listing

Product _info

New Product Listing

I add to cart and stay on the same page ...

Hmmm, interesting.

I've just gone and looked at the base product_listing.php (i.e. the original one as installed on a clean installation) and the bit of code that sets the href for the buy it now button is:

    
 $lc_button= zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($listing->fields['products_id'])....

Which clearly is a link to the product info page (i.e. not where I want to go) rather than the product listing page.

So I'm curious as to why you don't see it going to the info page.

Bob.

14 Feb 2011, 3:00 PM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: [Done v1.5.0] Stay on product listing after adding to cart

While the link is designed for that, there is other code that checks the setting for whether or not to go to the shopping cart when products are added ... this additional code "overrules" the way the add to cart handles the redirect ...

A search on:
DISPLAY_CART

will show you what files are using it ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

14 Feb 2011, 3:20 PM
#10
bobmoss avatar

bobmoss

New Zenner

Join Date:
Dec 2010
Posts:
20
Plugin Contributions:
0

Re: [Done v1.5.0] Stay on product listing after adding to cart

Ajeh:

While the link is designed for that, there is other code that checks the setting for whether or not to go to the shopping cart when products are added ... this additional code "overrules" the way the add to cart handles the redirect ...

A search on:
DISPLAY_CART

will show you what files are using it ...

I've just had a look through but cannot see anywhere where it would actually override which page it goes to.

However, I've noticed one thing, under Configuration -> product listing, what do you have "Display Product Add to Cart Button" set to?

I have mine set to "2", which is on with qty box per product.

Looking at the code I quoted earlier, it is only if you have this set to 2 that you will be re-directed to the product info page, otherwise is will work as you are experiencing.

14 Feb 2011, 4:26 PM
#11
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: [Done v1.5.0] Stay on product listing after adding to cart

If you Product has Attributes the Add to Cart will not show you will have a more info ...

That takes you to the Product _info page to make a choice on Attributes ...

Then, Add to cart from there keeps you on the Product _info ...

Otherwise, if you have the Add Quantity box showing on the Product Listing and add an amount it will add to cart but stay on the listing ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

14 Feb 2011, 5:00 PM
#12
bobmoss avatar

bobmoss

New Zenner

Join Date:
Dec 2010
Posts:
20
Plugin Contributions:
0

Re: [Done v1.5.0] Stay on product listing after adding to cart

Ajeh:

If you Product has Attributes the Add to Cart will not show you will have a more info ...

That takes you to the Product _info page to make a choice on Attributes ...

Then, Add to cart from there keeps you on the Product _info ...

Otherwise, if you have the Add Quantity box showing on the Product Listing and add an amount it will add to cart but stay on the listing ...

Right, I've just installed a brand new blank installation of Zen Cart with no modifications whatsoever and can reproduce the "issue" I've been experiencing.

If all the following conditions are true, then when you click on add to cart on the product listing page you are taken to the product information page instead of staying where you are:

  • Configuration -> My Store -> Display cart after adding product: TRUE
  • Configuration -> Product Listing -> Display Product Add to Cart Button: 2 (add to cart button on with qty).
  • Configuration -> Product Listing -> Display Multiple Products Qty Box Status and Set Button Location: 0 (off).

I think it is this last option that causes the issues. By setting this to 0, it creates an "Add this to my cart" button next to each product qty. Click on one of these buttons and you are taken to the product info, you DON'T stay where you are.

14 Feb 2011, 5:13 PM
#13
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: [Done v1.5.0] Stay on product listing after adding to cart

I moved this to the Bug Reports and will look into it further based on those settings ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

14 Feb 2011, 5:28 PM
#14
bobmoss avatar

bobmoss

New Zenner

Join Date:
Dec 2010
Posts:
20
Plugin Contributions:
0

Re: [Done v1.5.0] Stay on product listing after adding to cart

Ajeh:

I moved this to the Bug Reports and will look into it further based on those settings ...

Thanks!

20 Feb 2011, 12:05 PM
#15
jakedownhere avatar

jakedownhere

New Zenner

Join Date:
Aug 2006
Posts:
38
Plugin Contributions:
0

Re: [Done v1.5.0] Stay on product listing after adding to cart

Hello there!

Was just browsing through, looking for a way to set admin search to OR instead of AND when I read this and found it quite interesting.

I believe a good fix for this, Bob, is to set up the submit button to an iframe window with a die() command after the "add to cart" function has passed in the code.

With this, I mean to:

  1. Create an invisible iframe window which does the adding and loading the product into the shopping cart.
  2. Quits as soon as it does add it to the cart, to save on time.
  3. Your browser does not even twitch when you add something to the cart.

The downside is either not showing the product has been added without either a JS alert saying so, or changing the contents of the shopping cart box to display a message stating an item was added (like it does when you have the show-cart switch set to false).

I use iFrames with my admin side of things, changing item titles as needed, product qty, product price and product status, all without changing pages. Makes it great for inventory as without it, you have to edit each page to change those things.

Hope this helps or at least gives you some ideas...

Jake

26 Feb 2011, 5:32 PM
#16
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: [Done v1.5.0] Stay on product listing after adding to cart

bobmoss ... can you edit the file:
/includes/modules/product_listing.php

around line 134 and change the code to:

// qty box with add to cart button
            if (PRODUCT_LIST_PRICE_BUY_NOW == '2' && $listing->fields['products_qty_box_status'] != 0) {
//              $lc_button= zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($listing->fields['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $listing->fields['products_id']), 'post', 'enctype="multipart/form-data"') . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($listing->fields['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_draw_hidden_field('products_id', $listing->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) . '</form>';
              $lc_button= zen_draw_form('cart_quantity', zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $listing->fields['products_id']), 'post', 'enctype="multipart/form-data"') . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($listing->fields['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_draw_hidden_field('products_id', $listing->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) . '</form>';

Does this now work correctly for you?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

31 Mar 2011, 5:15 PM
#17
gorie avatar

gorie

New Zenner

Join Date:
Jan 2008
Posts:
89
Plugin Contributions:
0

Re: [Done v1.5.0] Stay on product listing after adding to cart

I had the same problem described above. I changed the code to what you provided Ajeh, and it works but there is a problem I have with it. It might be because I have the columns grid mod also.
But what happens for me now, is that it adds the product to the cart while staying on the product listing page as it should, HOWEVER, instead of the category header at the top, the text then changes to the product name (even though it stays on product listing page).
you can see what i mean here:
http://www.soaperia.com/store/index.php?main_page=index&cPath=1
where it says Soap, once you add a product, for example, click add Cotton Candy Soap to cart, it correctly adds the item to your cart and stays on the product listing rather than take you to the product display (which is how i want it), however the word "Soap" changes to "Cotton Candy Soap" (the product added) when it should still say "Soap" (the category).... any ideas how to fix this?

31 Mar 2011, 5:33 PM
#18
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: [Done v1.5.0] Stay on product listing after adding to cart

Must be your add on ... it is leaving the products_id=XX in the link ... if you remove that, it goes back to normal ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

31 Mar 2011, 5:54 PM
#19
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: [Done v1.5.0] Stay on product listing after adding to cart

Sorry ... I reproduced it ... let's see what can be done about it when:

When go to cart is OFF ...

Product listing is set to 2 on:

Display Product Add to Cart Button (0=off; 1=on; 2=on with Qty Box per Product)

and set to 0 on:

Display Multiple Products Qty Box Status and Set Button Location

and the Add to Cart maintains the products_id in the $goto and this is changes the bread crumb and page header for the Categories to the Categories and last products_id Product name added ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

31 Mar 2011, 11:00 PM
#20
gorie avatar

gorie

New Zenner

Join Date:
Jan 2008
Posts:
89
Plugin Contributions:
0

Re: [Done v1.5.0] Stay on product listing after adding to cart

so does that mean this isn't an easy fix? :(
hopefully someone can help