Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / Simple add to cart button in Product info page

Simple add to cart button in Product info page

Views: 2,840

Results 1 to 12 of 12
8 Dec 2012, 9:27 AM
#1
macbos avatar

macbos

New Zenner

Join Date:
Jul 2006
Location:
Holland
Posts:
27
Plugin Contributions:
0

Simple add to cart button in Product info page

Hi,

I want to use an add to cart button in de product info on the right site of my product info page.
This way customers can quickly add simple product to their main purchase.

Right now i use this url:

http://www.myshop.com/products_all.html?products_id=1547&action=buy_now

This works fine, but the problem is clicking on the link takes them to the all product listing page.
I would like them to stay on the (main) product page.:blush:

I know i should edit the init_cart_handler.php in /includes/init_includes/overrides/init_cart_handler.php

Like mentioned by drbyte in this discussion

http://www.zen-cart.com/showthread.php?83621-add-to-cart-without-displaying-product-info

Unfortunately i still can't get this to work.

Is there anyway i can create a simple add now button in the product info page.

Tnx Macbos

8 Dec 2012, 4:05 PM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Simple add to cart button in Product info page

A link to your site would take guessing out og the mix
Zencart by default displays an "add to cart" on the product info page as can be seen HERE

9 Dec 2012, 4:12 PM
#4
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Simple add to cart button in Product info page

Clicking added tocart "Winkelwagen - [lees meer]"

9 Dec 2012, 4:19 PM
#5
macbos avatar

macbos

New Zenner

Join Date:
Jul 2006
Location:
Holland
Posts:
27
Plugin Contributions:
0

Re: Simple add to cart button in Product info page

kobra:

Clicking added tocart "Winkelwagen - [lees meer]"

What do you mean ?

9 Dec 2012, 5:29 PM
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: Simple add to cart button in Product info page

It looks like you got it sorted out; clicking on the add-to-cart button on the product_info page returns you to that product_info page.

10 Dec 2012, 11:36 AM
#7
macbos avatar

macbos

New Zenner

Join Date:
Jul 2006
Location:
Holland
Posts:
27
Plugin Contributions:
0

Re: Simple add to cart button in Product info page

lat9:

It looks like you got it sorted out; clicking on the add-to-cart button on the product_info page returns you to that product_info page.

For the main product yes, but not the product under the product information.

10 Dec 2012, 2:39 PM
#8
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: Simple add to cart button in Product info page

Ahh, I see now!

The issue is that whatever code you're using to generate those "combo packs" is creating the "Buy Now" button as a hyperlink to the products_all page; that's why you wind up there after clicking the button.

You could probably write some custom code in an override of init_cart_handler.php (i.e. /includes/init_includes/overrides/init_cart_handler.php) that recognizes that a buy_now request came to the products_all page from the product_info page and sets the $goto variable to indicate that a return should happen to product_info. The $goto variable is the one used by the shopping_cart class to determine where to return after performing the cart-related function.

10 Dec 2012, 2:50 PM
#9
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Simple add to cart button in Product info page

The fun part is that the cart will have a record of the added product's id, but not the host product page. There is a snapshot() function that can be used to handle return navigation (used typically with the login function to get back to where you were) that might be able to be invoked.

11 Dec 2012, 1:34 PM
#10
macbos avatar

macbos

New Zenner

Join Date:
Jul 2006
Location:
Holland
Posts:
27
Plugin Contributions:
0

Re: Simple add to cart button in Product info page

gjh42:

The fun part is that the cart will have a record of the added product's id, but not the host product page. There is a snapshot() function that can be used to handle return navigation (used typically with the login function to get back to where you were) that might be able to be invoked.

Thank you both fore the help, i think show cart after adding a product is stil better then showing the all-product-listing page.

14 Dec 2012, 3:16 PM
#11
macbos avatar

macbos

New Zenner

Join Date:
Jul 2006
Location:
Holland
Posts:
27
Plugin Contributions:
0

Re: Simple add to cart button in Product info page

This worked for me:

/includes/classes/shopping_cart.php

Find:

//    zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
    zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters, $products_id) . 'products_id=' . $_GET['products_id']));
  }

Replace:

//    zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
      $back = sizeof($_SESSION['navigation']->path)-2;
      $goto = zen_href_link($_SESSION['navigation']->path[$back]['page'], zen_array_to_string($_SESSION['navigation']->path[$back]['get'], array('action')), $_SESSION['navigation']->path[$back]['mode']);
    zen_redirect($goto);
  }
14 Dec 2012, 6:09 PM
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Simple add to cart button in Product info page

Good to know that the navigation can be used there. Thanks for posting your fix.