Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need help with redirect issue in shopping cart
Old 07-16-2009, 10:35 PM Need help with redirect issue in shopping cart
Skilled Talker

Posts: 62
Name: Andrew
Trades: 0
I have the most recent version of Zen Cart. On the front site of my cart, when an "add to cart" button is clicked for a product (even a product without attributes), the item amount is added to the cart successfully, but the user is redirected to the product info page. From what I've learned, this is how Zen Cart is designed to function.

I need to have a user stay on whatever page they are already on when they click an "add to cart button," rather than being redirected to the product info page (as Zen Cart now does). The whole idea is to give the user control of their cart experience, rather than redirecting them unnecessarily to another page (which I think will confuse more people than help them).

I customized much of the php code for the "add to cart" buttons already, but can't figure out how to prevent this redirect (no help on the Zen Cart forums). If you go the main page of my test site, you will see products with "add to cart" buttons. Feel free to test the process.

http://www.sarasotafarms.org/biz/

I'm getting more familiar with the Zen Cart php pages, but I cannot seem to find where this redirect is occurring in the code. Once I find this, I guess the next step will be altering the code to prevent the redirect. I'm not great at php, but I understand it enough to make minor adjustments and add snippets.

I once was using oscommerce, which Zen Cart was supposedly created from. In oscommerce, it was easy to adjust the code to prevent the "add to cart" button from redirecting to a category page.

Anyway, any suggestions greatly appreciated.

Here is the code for the page which the button is located:

Code:
<?php

/**

 * featured_products module - prepares content for display

 *

 * @package modules

 * @copyright Copyright 2003-2007 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: featured_products.php 6424 2007-05-31 05:59:21Z ajeh $

 */

if (!defined('IS_ADMIN_FLAG')) {

  die('Illegal Access');

}



// initialize vars

$categories_products_id_list = '';

$list_of_products = '';

$featured_products_query = '';

$display_limit = '';



if ( (($manufacturers_id > 0 && $_GET['filter_id'] == 0) || $_GET['music_genre_id'] > 0 || $_GET['record_company_id'] > 0) || (!isset($new_products_category_id) || $new_products_category_id == '0') ) {

  $featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id, pd.products_short_desc

                           from (" . TABLE_PRODUCTS . " p

                           left join " . TABLE_FEATURED . " f on p.products_id = f.products_id

                           left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id )

                           where p.products_id = f.products_id

                           and p.products_id = pd.products_id

                           and p.products_status = 1 and f.status = 1

                           and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";

} else {

  // get all products and cPaths in this subcat tree

  $productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit);



  if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) {

    // build products-list string to insert into SQL query

    foreach($productsInCategory as $key => $value) {

      $list_of_products .= $key . ', ';

    }

    $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma

    $featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id, pd.products_short_desc

                                from (" . TABLE_PRODUCTS . " p

                                left join " . TABLE_FEATURED . " f on p.products_id = f.products_id

                                left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id)

                                where p.products_id = f.products_id

                                and p.products_id = pd.products_id

                                and p.products_status = 1 and f.status = 1

                                and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'

                                and p.products_id in (" . $list_of_products . ")";

  }

}


$index_title = '<h2 class="centerBoxHeading">' . TABLE_HEADING_FEATURED_PRODUCTS . '</h2>';
if(!empty($featured_products_query)){
    if(INDEX_FEATURED_USE_PRODUCT_LISTING == '2')
        extract(index_listing($featured_products_query, MAX_DISPLAY_SEARCH_RESULTS_FEATURED, SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS, IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH, IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT, $new_products_category_id, TABLE_HEADING_FEATURED_PRODUCTS, 'zc_show_featured'));
    elseif(INDEX_FEATURED_USE_PRODUCT_LISTING == '3'){
        $listing_sql = $featured_products_query;
        $show_submit = zen_run_normal();
    
        $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
        'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
        'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
        'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
        'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
        'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
        'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE);
        
        /*                         ,
        'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW);
        */
        asort($define_list);
        reset($define_list);
        $column_list = array();
        foreach ($define_list as $key => $value)
        {
        if ($value > 0) $column_list[] = $key;
        }
        $productListingId = 'featuredProducts';
        $is_index_listing = true;
        require($template->get_template_dir('tpl_modules_product_listing.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_product_listing.php');
        $is_index_listing = false;
    }
    elseif(INDEX_FEATURED_USE_PRODUCT_LISTING == '1'){
        if ($featured_products_query != '') $featured_products = $db->ExecuteRandomMulti($featured_products_query, MAX_DISPLAY_SEARCH_RESULTS_FEATURED);
        $row = 0;
        $col = 0;
        $list_box_contents = array();
        
        $num_products_count = ($featured_products_query == '') ? 0 : $featured_products->RecordCount();
        
        // show only when 1 or more
        if ($num_products_count > 0) {
          if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS == 0) {
            $col_width = floor(100/$num_products_count);
          } else {
            $col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS);
          }
          while (!$featured_products->EOF) {

    $product_price = zen_get_products_display_price($featured_products->fields['products_id']);    
      $product_link=zen_href_link( zen_get_info_page(  $featured_products->fields['products_id']), 'products_id=' . $featured_products->fields['products_id']);
      $product_id=$featured_products->fields['products_id'];
      $product_addtocart=zen_href_link( $_GET['main_page'], 'products_id=' . $product_id .'&action=buy_now');
      $product_image=zen_image(DIR_WS_IMAGES . $featured_products->fields['products_image'], $featured_products->fields['products_name'], IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH, IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT);
      $product_name=$featured_products->fields['products_name'];
      $featured_products->fields['products_short_desc'] = zen_get_products_short_desc($featured_products->fields['products_id']);
      $lc_button2= zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($featured_products->fields['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $featured_products->fields['products_id']), 'post', 'enctype="multipart/form-data"') . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($featured_products->fields['products_id'])) . '" maxlength="6" size="1" /><br />' . zen_draw_hidden_field('products_id', $featured_products->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) . '</form>';

    if (!isset($productsInCategory[$featured_products->fields['products_id']])) $productsInCategory[$featured_products->fields['products_id']] = zen_get_generated_category_path_rev($featured_products->fields['master_categories_id']);
    

    $list_box_contents[$row][$col] = array('params' =>'class="centerBoxContentsFeatured centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',

    'text' => (($featured_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'cPath=' . $productsInCategory[$featured_products->fields['products_id']] . '&products_id=' . $featured_products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $featured_products->fields['products_image'], $featured_products->fields['products_name'], IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH, IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT) . '</a><br />') . '<div class="featured_name">' . '<a href="' . zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'cPath=' . $productsInCategory[$featured_products->fields['products_id']] . '&products_id=' . $featured_products->fields['products_id']) . '">' . $featured_products->fields['products_name'] . '</a></div>'
        . '<div class="products_short_desc">' . $featured_products->fields['products_short_desc'] . '</div><div class="clearBoth"></div>'
        . ' <div class="featured_prod_price">' . $product_price .'<br /><br />Enter Quantity:' . $lc_button2 . '<br /><a href="' . $product_link . '"><img src="/biz/includes/templates/farm/buttons/english/button_learn_more.gif" /></a></div>' );
        
            $col ++;
            if ($col > (SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS - 1)) {
              $col = 0;
              $row ++;
            }
            $featured_products->MoveNextRandom();
          }
        
          if ($featured_products->RecordCount() > 0) {
            $zc_show_featured = true;
          }
        }
    }
}

Last edited by andrew99; 07-21-2009 at 04:50 PM.. Reason: typo
andrew99 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-17-2009, 09:01 PM Re: Need help with redirect issue in shopping cart
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
In ZenCart, there is a file located: includes/init_includes/init_cart_handler.php that handles the add to cart actions. You can override this script by copying it to includes/init_includes/overrides/init_cart_handler.php and add the modification (shown below) in the middle. This method will use the navigation history to go back to the original page.

This is not tested, but it *should* work

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

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-17-2009, 09:31 PM Re: Need help with redirect issue in shopping cart
Skilled Talker

Posts: 62
Name: Andrew
Trades: 0
Wow! Thank you so much for this code snippet. I've been trying to solve this for two weeks, with no success. Quick question - will this keep the user on the same page if they are on a category page, all products page, sales page, etc, or will it only work if they are in the home page (index.php). Thanks again for the help!
andrew99 is offline
Reply With Quote
View Public Profile
 
Old 07-17-2009, 09:52 PM Re: Need help with redirect issue in shopping cart
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Quote:
Originally Posted by andrew99 View Post
Quick question - will this keep the user on the same page if they are on a category page, all products page, sales page, etc, or will it only work if they are in the home page (index.php). Thanks again for the help!
It should go to the original page where they first clicked the add product button by going to the last page from thier navigation history. That's what it should do, but like I said, I have not tested it.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-18-2009, 02:15 PM Re: Need help with redirect issue in shopping cart
Skilled Talker

Posts: 62
Name: Andrew
Trades: 0
mgraphic - I made the edit, but I can't seem to get the code you provided to work - still directing to the info page. I'm wondering if the redirect to the info page is being caused/overridden by

Code:
<a href="' . zen_href_link(zen_get_info_page
which is mentioned a couple times in the code (in the page above). I know it's possible to keep the user on the same page after a "buy now" is clicked, because this is what happens here:

http://www.sarasotafarms.org/biz2/in...e=products_all

I just can't figure out how to replicate this in the other pages of this cart. Let me know if you have any ideas. Thanks.

Last edited by andrew99; 07-19-2009 at 01:19 AM..
andrew99 is offline
Reply With Quote
View Public Profile
 
Old 07-19-2009, 05:12 PM Re: Need help with redirect issue in shopping cart
Skilled Talker

Posts: 62
Name: Andrew
Trades: 0
Good news! This code works. Thank you again mgraphic.

It makes the "buy now" button direct the user back to the page they were originally on when they clicked the button.

The only thing is that the code modification only seems to work with the Zen Cart "Single Listing Template" mod installed, but not without the mod (I tested it both ways). The "Single Listing Template" is a mod which allows the different mods in the cart to share styling.

Anyway, does anyone have any ideas how to configure the code to work without the "Single Listing Template" mod? I can't use the "Single Listing Template" mod with my site for other unrelated reasons.I have my site set up right now without the mod active:
http://www.sarasotafarms.org/biz

I'm learning php but I don't know enough to understand this yet. Thank you for any suggestions.

Last edited by andrew99; 07-20-2009 at 03:44 AM..
andrew99 is offline
Reply With Quote
View Public Profile
 
Old 07-21-2009, 03:29 PM Re: Need help with redirect issue in shopping cart
Skilled Talker

Posts: 62
Name: Andrew
Trades: 0
I keep trying different variations of the code suggested by mgraphic and still can't get it to work properly. I know there's hope because it worked with the other template arrangement I had set up. Yikes - been struggling for two weeks with this one. Any suggestion on what I can try? Thanks in advance for any isights.
andrew99 is offline
Reply With Quote
View Public Profile
 
Old 07-21-2009, 04:58 PM Re: Need help with redirect issue in shopping cart
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Do you have your own merchant account?
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 07-21-2009, 05:04 PM Re: Need help with redirect issue in shopping cart
Skilled Talker

Posts: 62
Name: Andrew
Trades: 0
Brian07002- yes, we have a merchant account, although we don't have it hooked up to the cart yet. We are trying to get the issue detailed in this post solved first. We are a non-profit humanitarian project. We set this cart up as a way to fund our research and projects.

Last edited by andrew99; 07-21-2009 at 05:07 PM..
andrew99 is offline
Reply With Quote
View Public Profile
 
Old 07-22-2009, 03:04 AM Re: Need help with redirect issue in shopping cart
Skilled Talker

Posts: 62
Name: Andrew
Trades: 0
Doesn't look like I'm going to get anywhere with this. Probably too program specific or too dependent on how I have my cart set up.

I thought of a simple idea to bypass the original issue. Same question/different approach. If I have this php code:

Code:
$lc_button2= zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($featured_products->fields['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $featured_products->fields['products_id']), 'post', 'enctype="multipart/form-data"') . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($featured_products->fields['products_id'])) . '" maxlength="6" size="1" /><br />' . zen_draw_hidden_field('products_id', $featured_products->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) . '</form>';
Is there a simple way to hardcode...
Code:
zen_href_link(zen_get_info_page($featured_products->fields['products_id']),
... so that the user is redirected back to the index page of the site instead of to the product info page (this is what the code does now).

By altering the code, I've gotten these results so far:

zen_href_link(FILENAME_DEFINE_MAIN_PAGE, - page not found
zen_href_link(FILENAME_DEFAULT, - goes to category page of cart
zen_href_link(FILENAME_FEATURED, - page not found
zen_href_link(FILENAME_FEATURED_PRODUCTS, - takes them to featured products page of cart
zen_href_link(FILENAME_PRODUCTS_ALL, - takes them to the all products page of cart

But I can't find a a way yet to send the user back to the home page (index.php) which is also were they originally came from. Any ideas on what I can put in here to get this effect?

I though someone here, even without a knowledge of Zen Cart, might have an idea to accomplish this. Any suggestions greatly appreciated.
andrew99 is offline
Reply With Quote
View Public Profile
 
Old 07-28-2009, 11:03 PM Re: Need help with redirect issue in shopping cart
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
In order to link to the home page, use:

zen_href_link(FILENAME_DEFAULT)

With no parameters
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need help with redirect issue in shopping cart
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.83210 seconds with 12 queries