Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Jun 2009
    Posts
    43
    Plugin Contributions
    0

    Default Must See - This would be great!

    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');
    }
    ?>

  2. #2
    Join Date
    Feb 2005
    Location
    Lansing, Michigan USA
    Posts
    20,021
    Plugin Contributions
    3

    Default Re: Must See - This would be great!

    First, you have your entire site secured under SSL, which will not only slow your site down, but is unnecessary and causes the secure/non-secure error on all of your pages in IE. Seems to be caused by the 'Go' image in your Login area in the header.

    When I click 'Add to Cart' in the Featured Products listing, it does 'add to cart', but it still takes me to the product info page, so I'm not sure what you mean by: I've discovered how to do this on the "featured products" and "all products" pages from the admin ...

  3. #3
    Join Date
    Jun 2009
    Posts
    43
    Plugin Contributions
    0

    Default Re: Must See - This would be great!

    stevesh - thanks for pointing out the SSL issues to me. I think I got them fixed. I've been working mainly in firefox lately and overlooked them.

    As far as "I've discovered how to do this on the "featured products" and "all products" pages from the admin ..."

    ...with the settings in admin, without any code modifications, I was able to get the buy now buttons in the featured products/all products pages to keep the user on the original page, even after they added an item to the cart with a buy now button. You can see the functionality here buy clicking a buy now button:

    http://www.sarasotafarms.org/biz2/in...tured_products

    My issue is that on my actual site (http://www.sarasotafarms.org/biz), I use custom buy now button codes which do not keep the user on the page - they redirect the user to the product info page when a buy now button is clicked. I'm trying to avoid the user being redirected in this way.

    Just hard coding the buttons to control where the user ends up is tricky, because the same modules are on different pages. For example, if I was able to hard code the "featured products" module to redirect to the home page when a buy now button is clicked, the user would be redirected regardless if they were originally on the home page, in the categories listing, etc. I hope that made sense.

    Anyway, the code I posted at the begging of this post was an idea (from another coder) that would 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.

    Only problem is that the code doesn't work yet. I was trying to see if anyone here with better skill in php/zen cart might have any suggestions. My guess is that many Zen Cart users would appreciate this.

    Please let me know if you or anyone else has any ideas/suggestions. Thank you.

  4. #4
    Join Date
    Jun 2009
    Posts
    43
    Plugin Contributions
    0

    Default Re: Must See - This would be great!

    Good news! This code works. It makes the "buy now" button direct the user back to the page they were originally on when they clicked the button.

    The only custom button codes I found in this forum don't do this automatically - they send the user to the product info page. The only custom code I found was thankfully provided by Ajeh in this post:
    http://www.zen-cart.com/forum/showthread.php?t=105757

    Anyway, the only thing is that the code modification (posted at the beginning of this post) only seems to work with the "Single Listing Template" mod installed, but not without the mod (I tested it both ways).

    Anyone have any ideas how to configure the code to work without the "Single Listing Template" mod? Thank you for any suggestions.

 

 

Similar Threads

  1. User must be logged in to see large images
    By tawnos in forum General Questions
    Replies: 1
    Last Post: 8 Dec 2010, 03:51 AM
  2. Cross Sell Install Trouble - SQL Error - help would be great!
    By steveo3279 in forum All Other Contributions/Addons
    Replies: 4
    Last Post: 25 Jan 2008, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg