[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.
Re: 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:
Code:
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:
Code:
$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.
Re: Stay on product listing after adding to cart
Before changing code, did you try the setting in the Configuration ... My Store ... for:
Quote:
Display Cart After Adding Product
Display the shopping cart after adding a product (or return back to their origin)
true
false
Re: 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.
Re: 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?
Re: 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.
Re: 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 ...
Re: Stay on product listing after adding to cart
Quote:
Originally Posted by
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:
Code:
$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.
Re: 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 ...
Re: Stay on product listing after adding to cart
Quote:
Originally Posted by
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.