I think many Zen Cart users would find this very helpful.
I have several customized "but now" buttons in different modules and product_listing.php.
For weeks, I've been trying to configure our site to when a "buy now" button is clicked on any page, rather than being directed to the product info page, the user remains on the page they were on when they clicked the buy now button.
I've discovered how to do this on the "featured products" and "all products" pages from the admin, but couldn't get any of my modules or other pages to do this (with my lacking-in-skill code edits).
A coder from another site suggested to put the code below in init_cart_handler.php
The idea of the code is to redirect a user, after they click a buy now button, back to the page they originally clicked the buy now button on. This puts the user in control instead of being redirected to a page they may not want to be on/which may confuse them.
As you can see on my test site, I have buy now codes in my "featured Products" module on the front page of my site:
https://www.sarasotafarms.org/biz
I tested the code, but can't get it to work yet. I would love to get suggestions from anyone who knows more about php/Zen Cart.
Code:<?php /** * initialise and handle cart actions * see {@link http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials#InitSystem wikitutorials} for more details. * * @package initSystem * @copyright Copyright 2003-2005 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: init_cart_handler.php 4528 2006-09-16 01:12:14Z ajeh $ */ if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } if (isset($_GET['action'])) { /** * redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled */ if ($session_started == false) { zen_redirect(zen_href_link(FILENAME_COOKIE_USAGE)); } if (DISPLAY_CART == 'true') { $goto = FILENAME_SHOPPING_CART; $parameters = array('action', 'cPath', 'products_id', 'pid', 'main_page'); } else { $goto = $_GET['main_page']; if ($_GET['action'] == 'buy_now') { $parameters = array('action', 'products_id'); // Begin modification: } else if ($_GET['action'] == 'add_product') { if (sizeof($_SESSION['navigation']->path)-1 > 0) { $key = sizeof($_SESSION['navigation']->path)-1; $goto = $_SESSION['navigation']->path[$key]['page']; $parameters = array('action'); $_GET = $_SESSION['navigation']->path[$key]['get']; } else { $goto = FILENAME_DEFAULT; $parameters = array('action', 'products_id', 'main_page'); } // End modification } else { $parameters = array('action', 'pid', 'main_page'); } } /** * require file containing code to handle default cart actions */ require(DIR_WS_INCLUDES . 'main_cart_actions.php'); } ?>



