Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / Displaying Product Viewed in Product Listing Page

Displaying Product Viewed in Product Listing Page

Views: 2,477

Results 21 to 37 of 37
18 Apr 2015, 4:07 PM
#21
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Displaying Product Viewed in Product Listing Page

So far, I have not found why this code works perfectly for me and not for you ...

Could you again post the file that you customized for the products_listing and we can see if there is some other typo in there?

18 Apr 2015, 4:20 PM
#22
eric_chen avatar

eric_chen

New Zenner

Join Date:
May 2012
Posts:
39
Plugin Contributions:
0

Re: Displaying Product Viewed in Product Listing Page

Sure! Please refer to following code of products_listing.php in my store:

<?php
/**
 * product_listing module
 *
 * @package modules
 * @copyright Copyright 2003-2006 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: product_listing.php 4655 2006-10-02 01:02:38Z ajeh $
 * UPDATED TO WORK WITH COLUMNAR PRODUCT LISTING For Zen Cart v1.3.6 - 10/25/2006
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
// Column Layout Support originally added for Zen Cart v 1.1.4 by Eric Stamper - 02/14/2004
// Upgraded to be compatible with Zen-cart v 1.2.0d by Rajeev Tandon - Aug 3, 2004
// Column Layout Support (Grid Layout) upgraded for v1.3.0 compatibility DrByte 04/04/2006
//
if (!defined('PRODUCT_LISTING_LAYOUT_STYLE')) define('PRODUCT_LISTING_LAYOUT_STYLE','rows');
if (!defined('PRODUCT_LISTING_COLUMNS_PER_ROW')) define('PRODUCT_LISTING_COLUMNS_PER_ROW',3);
$row = 0;
$col = 0;
$list_box_contents = array();
$title = '';
$max_results = (PRODUCT_LISTING_LAYOUT_STYLE=='columns' && PRODUCT_LISTING_COLUMNS_PER_ROW>0) ? (PRODUCT_LISTING_COLUMNS_PER_ROW * (int)(MAX_DISPLAY_PRODUCTS_LISTING/PRODUCT_LISTING_COLUMNS_PER_ROW)) : MAX_DISPLAY_PRODUCTS_LISTING;
$show_submit = zen_run_normal();
$listing_split = new splitPageResults($listing_sql, $max_results, 'p.products_id', 'page');
$how_many = 0;
// Begin Row Layout Header
if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') {		// For Column Layout (Grid Layout) add on module
  $list_box_contents[0] = array('params' => 'class="productListing-rowheading"');
  $zc_col_count_description = 0;
  $lc_align = '';
  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
    switch ($column_list[$col]) {
      case 'PRODUCT_LIST_MODEL':
        $lc_text = TABLE_HEADING_MODEL;
        $lc_align = '';
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_NAME':
        $lc_text = TABLE_HEADING_PRODUCTS;
        $lc_align = '';
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_MANUFACTURER':
        $lc_text = TABLE_HEADING_MANUFACTURER;
        $lc_align = '';
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_PRICE':
        $lc_text = TABLE_HEADING_PRICE;
        $lc_align = 'right' . (PRODUCTS_LIST_PRICE_WIDTH > 0 ? '" width="' . PRODUCTS_LIST_PRICE_WIDTH : '');
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_QUANTITY':
        $lc_text = TABLE_HEADING_QUANTITY;
        $lc_align = 'right';
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_WEIGHT':
        $lc_text = TABLE_HEADING_WEIGHT;
        $lc_align = 'right';
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_IMAGE':
        $lc_text = TABLE_HEADING_IMAGE;
        $lc_align = 'center';
        $zc_col_count_description++;
        break;
    }
    if ( ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
      $lc_text = zen_create_sort_heading($_GET['sort'], $col+1, $lc_text);
    }
    $list_box_contents[0][$col] = array('align' => $lc_align,
                                        'params' => 'class="productListing-heading"',
                                        'text' => $lc_text );
  }
} // End Row Layout Header used in Column Layout (Grid Layout) add on module
/////////////  HEADER ROW ABOVE /////////////////////////////////////////////////
$num_products_count = $listing_split->number_of_rows;
if ($listing_split->number_of_rows > 0) {
  $rows = 0;
  // Used for Column Layout (Grid Layout) add on module
  $column = 0;	
  if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
    if ($num_products_count < PRODUCT_LISTING_COLUMNS_PER_ROW || PRODUCT_LISTING_COLUMNS_PER_ROW == 0 ) {
      $col_width = floor(100/$num_products_count) - 0.5;
    } else {
      $col_width = floor(100/PRODUCT_LISTING_COLUMNS_PER_ROW) - 0.5;
    }
  }
  // Used for Column Layout (Grid Layout) add on module
  $listing = $db->Execute($listing_split->sql_query);
  $extra_row = 0;
  while (!$listing->EOF) {
    if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') { // Used in Column Layout (Grid Layout) Add on module
      $rows++;
      if ((($rows-$extra_row)/2) == floor(($rows-$extra_row)/2)) {
        $list_box_contents[$rows] = array('params' => 'class="productListing-even"');
      } else {
        $list_box_contents[$rows] = array('params' => 'class="productListing-odd"');
      }
      $cur_row = sizeof($list_box_contents) - 1;
    }   // End of Conditional execution - only for row (regular style layout)
    $product_contents = array(); // Used For Column Layout (Grid Layout) Add on module
    for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
      $lc_align = '';
      switch ($column_list[$col]) {

	[B]  case 'PRODUCT_LIST_MODEL':
        $lc_align = '';
//      $lc_text = $listing->fields['products_model'];
        $lc_text = $listing->fields['products_model'] .
 ( zen_products_lookup($listing->fields['products_id'], 'products_viewed') > 0 ? '<li>' . 'Views: ' . zen_products_lookup($listing->fields['products_id'], 'products_viewed') . '</li>' : '') . ' - ' . $listing->fields['products_id'] . '<br />';
        break;[/B]
        case 'PRODUCT_LIST_NAME':
          $lc_align = '';
          if (isset($_GET['manufacturers_id'])) {
            $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;
          } else {
            $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';
          }
          break;
        case 'PRODUCT_LIST_MANUFACTURER':
          $lc_align = '';
          $lc_text = '<a href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing->fields['manufacturers_id']) . '">' . $listing->fields['manufacturers_name'] . '</a>';
          break;
        case 'PRODUCT_LIST_PRICE':
          $lc_price = zen_get_products_display_price($listing->fields['products_id']) . '<br />';
          $lc_align = 'right';
          $lc_text =  $lc_price;
          // more info in place of buy now
          $lc_button = '';
          if (zen_has_product_attributes($listing->fields['products_id']) or PRODUCT_LIST_PRICE_BUY_NOW == '0') {
            $lc_button = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>';
          } else {
            if (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART != 0) {
            if (
                // not a hide qty box product
                $listing->fields['products_qty_box_status'] != 0 &&
                // product type can be added to cart
                zen_get_products_allow_add_to_cart($listing->fields['products_id']) != 'N'
                &&
                // product is not call for price
                $listing->fields['product_is_call'] == 0
                &&
                // product is in stock or customers may add it to cart anyway
                ($listing->fields['products_quantity'] > 0 || SHOW_PRODUCTS_SOLD_OUT_IMAGE == 0) ) {
                    $how_many++;
                  }
            // hide quantity box
            if ($listing->fields['products_qty_box_status'] == 0) {
              $lc_button = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT, 'class="listingBuyNowButton"') . '</a>';
            } else {
              $lc_button = TEXT_PRODUCT_LISTING_MULTIPLE_ADD_TO_CART . "<input type=\"text\" name=\"products_id[" . $listing->fields['products_id'] . "]\" value=\"0\" size=\"4\" />";
            }
          } else {
// qty box with add to cart button
            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>';
            } else {
              $lc_button = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT, 'class="listingBuyNowButton"') . '</a>';
            }
            }
          }
          $the_button = $lc_button;
        $products_link = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>';
          $lc_text .= '<br />' . zen_get_buy_now_button($listing->fields['products_id'], $the_button, $products_link) . '<br />' . zen_get_products_quantity_min_units_display($listing->fields['products_id']);
          $lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '<br />' : '') : '');
          break;
        case 'PRODUCT_LIST_QUANTITY':
          $lc_align = 'right';
          $lc_text = $listing->fields['products_quantity'];
          break;
        case 'PRODUCT_LIST_WEIGHT':
          $lc_align = 'right';
          $lc_text = $listing->fields['products_weight'];
          break;
        case 'PRODUCT_LIST_IMAGE':
          $lc_align = 'center';
        if ($listing->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) {
          $lc_text = '';
        } else {
          if (isset($_GET['manufacturers_id'])) {
          $lc_text = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'products_id=' . $listing->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</a>';
          } else {
          $lc_text = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</a>';
          }
        }
          break;
      }
      $product_contents[] = $lc_text; // Used For Column Layout (Grid Layout) Option
      if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') {
        $list_box_contents[$rows][$col] = array('align' => $lc_align,
                                                'params' => 'class="productListing-data"',
                                                'text'  => $lc_text);
      }
    }
    // add description and match alternating colors
    //if (PRODUCT_LIST_DESCRIPTION > 0) {
    //  $rows++;
    //  if ($extra_row == 1) {
    //    $list_box_description = "productListing-data-description-even";
    //    $extra_row=0;
    //  } else {
    //    $list_box_description = "productListing-data-description-odd";
    //    $extra_row=1;
    //  }
    //  $list_box_contents[$rows][] = array('params' => 'class="' . $list_box_description . '" colspan="' . $zc_col_count_description . '"',
    //  'text' => zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION));
    //}
    // Following code will be executed only if Column Layout (Grid Layout) option is chosen
    if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
      $lc_text = implode('<br />', $product_contents);
      $list_box_contents[$rows][$column] = array('params' => 'class="centerBoxContentsProducts centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
                                                 'text'  => $lc_text);
      $column ++;
      if ($column >= PRODUCT_LISTING_COLUMNS_PER_ROW) {
        $column = 0;
        $rows ++;
      }
    }
    // End of Code fragment for Column Layout (Grid Layout) option in add on module
    $listing->MoveNext();
  }
  $error_categories = false;
} else {
  $list_box_contents = array();
  $list_box_contents[0] = array('params' => 'class="productListing-odd"');
  $list_box_contents[0][] = array('params' => 'class="productListing-data"',
                                  'text' => TEXT_NO_PRODUCTS);
  $error_categories = true;
}
if (($how_many > 0 and $show_submit == true and $listing_split->number_of_rows > 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == 1 or  PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == 3) ) {
  $show_top_submit_button = true;
} else {
  $show_top_submit_button = false;
}
if (($how_many > 0 and $show_submit == true and $listing_split->number_of_rows > 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART >= 2) ) {
  $show_bottom_submit_button = true;
} else {
  $show_bottom_submit_button = false;
}
  if ($how_many > 0 && PRODUCT_LISTING_MULTIPLE_ADD_TO_CART != 0 and $show_submit == true and $listing_split->number_of_rows > 0) {
  // bof: multiple products
    echo zen_draw_form('multiple_products_cart_quantity', zen_href_link(FILENAME_DEFAULT, zen_get_all_get_params(array('action')) . 'action=multiple_products_add_product'), 'post', 'enctype="multipart/form-data"');
  }
?>

I made a red highlight on the customized area. Thanks.

18 Apr 2015, 4:27 PM
#23
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Displaying Product Viewed in Product Listing Page

So far, your code works for me in the original products_listing.php ...

Unfortunately I have to go and won't be back until tomorrow

18 Apr 2015, 4:46 PM
#24
eric_chen avatar

eric_chen

New Zenner

Join Date:
May 2012
Posts:
39
Plugin Contributions:
0

Re: Displaying Product Viewed in Product Listing Page

OK, thank you! I will wait for some updated solution. Have a nice weekend!

19 Apr 2015, 2:34 PM
#25
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Displaying Product Viewed in Product Listing Page

So far, I still cannot see why this is not working on your site ...

I even took your exact file and loaded it on my site and it works fine ... :blink:

You might need someone to actually look through your site and see if they can spot what is going on ...

Also, check in your FTP program and look at the dates/times of the file:
/includes/modules/product_listing.php

and make sure that the one on the server matches the one on your computer ... or, delete the file on the server and reload the one from your computer to the server to ensure that your change, customized file is actually on the server ...

20 Apr 2015, 3:15 AM
#26
eric_chen avatar

eric_chen

New Zenner

Join Date:
May 2012
Posts:
39
Plugin Contributions:
0

Re: Displaying Product Viewed in Product Listing Page

Nice day! I'm sured that the old file on the server was replaced by the customized file, but it still got same viewed report on product listing page.

I also took the code and tested on initial Zencart with zcen template (not do any change), but it still didn't work and got same result as I did.

So I think that the problem should not be caused by my site and template.

Here, had any buddy ever met the same issue? The following is for looking back the focus of the problem in the thread again:

On the products_listing.php:
/includes/modules/your_template_dir/product_listing.php
I put and replaced following customized code:

  case 'PRODUCT_LIST_MODEL':
        $lc_align = '';
//      $lc_text = $listing->fields['products_model'];
        $lc_text = $listing->fields['products_model'] .
[B] ( zen_products_lookup($listing->fields['products_id'], 'products_viewed') > 0 ? '<li>' . 'Views: ' . zen_products_lookup($listing->fields['products_id'], 'products_viewed') . '</li>' : '') . '<br />'[/B];
        break;

I'd like to show the products_viewed counter report under the product model or buy now button in prodcut listing page,
but each product shows same viewed count report which is exactly from the first product (products_id with 1) in my store.

Does any buddy have interesting to take a test on your Zencart store, by the customized code in red highlight? Or does some buddy who are good at PHP or famliar with Zencart try to do some other changes for the code to look up correct "products viewed report on product listing page"?...

20 Apr 2015, 1:04 PM
#27
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Displaying Product Viewed in Product Listing Page

I used that code and it works fine ...

Just as a test, let's change the text from Views to Fred Views to ensure the code is running:

  case 'PRODUCT_LIST_MODEL':
        $lc_align = '';
//      $lc_text = $listing->fields['products_model'];
        $lc_text = $listing->fields['products_model'] .
 ( zen_products_lookup($listing->fields['products_id'], 'products_viewed') > 0 ? '<li>' . '[B]Fred[/B] Views: ' . zen_products_lookup($listing->fields['products_id'], 'products_viewed') . '</li>' : '') . '<br />';
        break;

I am still not seeing why you are not getting the right response using the custom code ... but this will at least ensure that the right custom code is running ...

20 Apr 2015, 2:45 PM
#28
eric_chen avatar

eric_chen

New Zenner

Join Date:
May 2012
Posts:
39
Plugin Contributions:
0

Re: Displaying Product Viewed in Product Listing Page

I just tested again, and ensure that the code is running. Please refer to following screen shot (the first flow under a category):

Attachment #15198

It is an example. In fact, all items in my store show “Fred Views: 12”. The views 12 is the exactly viewed count report of the first Product with Product_ID 1 in my store. So far I just don't know why the code only could look up the view report of the first product (product_id 1), but could not identify different views report with related products.

Maybe is it refered to my host system? But I think that it should be impossible. How Strange!!!

20 Apr 2015, 4:20 PM
#29
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Displaying Product Viewed in Product Listing Page

Okay you can take out Fred ... but I am really confused on what this isn't working ...

We could test if the function is not working right and sure this to see if the right products_model using:

  case 'PRODUCT_LIST_MODEL':
        $lc_align = '';
//      $lc_text = $listing->fields['products_model'];
        $lc_text = $listing->fields['products_model'] .
 ( zen_products_lookup($listing->fields['products_id'], 'products_viewed') > 0 ? '<li>' . 'Views: ' . zen_products_lookup($listing->fields['products_id'], 'products_viewed') . '</li>' : '') . ' - ' . zen_products_lookup($listing->fields['products_id'], 'products_model') . '<br />';
        break;

This will show the model twice and they should match ...

20 Apr 2015, 5:57 PM
#30
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Displaying Product Viewed in Product Listing Page

Just wanted to interject a thought here.. Not sure what the OP's objective is, but wanted to point out that hit counters are a notoriously BAD way to encourage conversion sales.. It's the opposite as a matter of fact.. It's a screaming advertisement to site visitors about how many people MAY or MAY NOT have been to your site. It may not paint the picture most site owners are after when implementing these solutions, which is that your site is a trusted source for whatever product your site is selling.. "Trusted" based solely on nothing more than the number of times a "visitor" clicked off a counter on the site.. IMHO showing featured, or best seller products is a much better way to communicate this message..

21 Apr 2015, 4:28 PM
#31
eric_chen avatar

eric_chen

New Zenner

Join Date:
May 2012
Posts:
39
Plugin Contributions:
0

Re: Displaying Product Viewed in Product Listing Page

DivaVocals:

Just wanted to interject a thought here.. Not sure what the OP's objective is, but wanted to point out that hit counters are a notoriously BAD way to encourage conversion sales.. It's the opposite as a matter of fact.. It's a screaming advertisement to site visitors about how many people MAY or MAY NOT have been to your site. It may not paint the picture most site owners are after when implementing these solutions, which is that your site is a trusted source for whatever product your site is selling.. "Trusted" based solely on nothing more than the number of times a "visitor" clicked off a counter on the site.. IMHO showing featured, or best seller products is a much better way to communicate this message..

Thank you for your kind advise. It might be... Here I just would like to achieve the function, so as to make sure the code doesn't have a bug to work in Zencart.

I just tested in my store by the code again and indeed it looks up correct model, and twice are match. But it just could not get correct product view report.

So far, still could not get working code, maybe I have to give up the funtion...

21 Apr 2015, 4:30 PM
#32
eric_chen avatar

eric_chen

New Zenner

Join Date:
May 2012
Posts:
39
Plugin Contributions:
0

Re: Displaying Product Viewed in Product Listing Page

Thank you for your kind advise. It might be... Here I just would like to achieve the function, so as to make sure the code doesn't have any bug to work in Zencart.

I just tested in my store by the code again and indeed it looks up correct model, and twice are match. But it just could not get correct product view report.

So far, still could not get working code, maybe I have to give up the funtion...

21 Apr 2015, 5:00 PM
#33
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Displaying Product Viewed in Product Listing Page

Because this is driving me nuts ... let's try getting the products_viewed another way ...

Edit the file:
/includes/modules/pages/index/main_template_vars.php

and add the code in RED:

  // always add quantity regardless of whether or not it is in the listing for add to cart buttons
  if (PRODUCT_LIST_QUANTITY < 1) {
    $select_column_list .= 'p.products_quantity, ';
  }

[B]// bof: force products_viewed
$select_column_list .= 'pd.products_viewed,';
// eof: force products_viewed
[/B]
  // set the product filters according to selected product type

Then in the file:
/includes/modules/your_templates_dir/products_listing.php

use this code for the Case:

  case 'PRODUCT_LIST_MODEL':
        $lc_align = '';
[B]//[/B]      $lc_text = $listing->fields['products_model'];
[B]        $lc_text = $listing->fields['products_model'] .
 ( $listing->fields['products_viewed'] > 0 ? '<li>' . 'Views: ' . $listing->fields['products_viewed'] . '</li>' : '') . '<br />';
[/B]        break;

What this does is get the info from the database when all the other data is gathered so that the products_viewed is available like the other information in the listing ...

21 Apr 2015, 5:19 PM
#34
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Displaying Product Viewed in Product Listing Page

Eric Chen:

Thank you for your kind advise. It might be... Here I just would like to achieve the function, so as to make sure the code doesn't have a bug to work in Zencart.

I just tested in my store by the code again and indeed it looks up correct model, and twice are match. But it just could not get correct product view report.

So far, still could not get working code, maybe I have to give up the funtion...
Invest your time into building effective sites with good content.. Site counters are passes, notoriously inaccurate and will not provide the benefit you think they will.

Dump That Free Hit Counter And Start TrackingIt seems that every other web site we visit has some sort of hit counter on the main page, supposedly telling us how many people have been there before us. This week we’re going to address this popular trend, explain why you don’t need one, and what you should be doing instead.
Most Internet marketers will normally implement a hit counter on their site for one or both of two reasons — to give them a rough estimate of the number of visitors, and/or to give visitors the impression that their site is popular and thus worthy of a good look.
Let’s consider the first reason. There is nothing wrong with wanting to know how many people have visited your web site, in fact it’s something that you really do need to know. But putting a visible hit counter on your home page is not the answer, especially not one of those free services.
For one thing, the free services require you to in some way promote their site. For another, they are normally slow and increase the time it takes for your pages to load. But most importantly, a hit counter doesn’t provide you with all of the information you need.
Just look at any of the top web sites on the Internet. We promise that you will not find a visible hit counter on any of them! That alone should tell you that the common hit counter is worthless. If a visible counter was worthwhile, don’t you think Yahoo or Infoseek would have one?

You just can’t win with a visible hit counter. If your site does not get many visitors, all it’s going to do is make sure that the visitors you do get know that they are not visiting a popular site. If anything, all this will do is discourage them from exploring your web site in detail.
On the other hand, maybe your site gets 50,000 visitors a day and you think that letting people know this via a hit counter is a good idea. Not really. If your web site gets lots of traffic it is because you are doing something right, and having a hit counter isn’t going to affect this.
Unfortunately, what normally happens is that the misguided Internet marketer will set up a visible hit counter on their home page and then artificially inflate their visitor count. This is done in the hopes that it will impress people, but it’s a terribly bad idea and does not work.
In the early days of the web it was "cool" to have a hit counter on your home page, but they are so commonplace these days that no one pays them any attention anyway. No matter what your reason for using a visible hit counter, we say dump it and start tracking!

25 Apr 2015, 7:26 AM
#35
eric_chen avatar

eric_chen

New Zenner

Join Date:
May 2012
Posts:
39
Plugin Contributions:
0

Re: Displaying Product Viewed in Product Listing Page

Ajeh:

Because this is driving me nuts ... let's try getting the products_viewed another way ...

Edit the file:
/includes/modules/pages/index/main_template_vars.php

and add the code in RED:

// always add quantity regardless of whether or not it is in the listing for add to cart buttons
if (PRODUCT_LIST_QUANTITY < 1) {
$select_column_list .= 'p.products_quantity, ';
}

[B]// bof: force products_viewed
$select_column_list .= 'pd.products_viewed,';
// eof: force products_viewed
[/B]

// set the product filters according to selected product type

> 
> Then in the file:
> /includes/modules/your_templates_dir/products_listing.php
> 
> use this code for the Case:
> ```
  case 'PRODUCT_LIST_MODEL':
        $lc_align = '';
[B]//[/B]      $lc_text = $listing->fields['products_model'];
[B]        $lc_text = $listing->fields['products_model'] .
 ( $listing->fields['products_viewed'] > 0 ? '<li>' . 'Views: ' . $listing->fields['products_viewed'] . '</li>' : '') . '<br />';
[/B]        break;

What this does is get the info from the database when all the other data is gathered so that the products_viewed is available like the other information in the listing ...

Wonderful!!! It is working now by inserting the new code programmed in another way. Appreciated...

25 Apr 2015, 7:30 AM
#36
eric_chen avatar

eric_chen

New Zenner

Join Date:
May 2012
Posts:
39
Plugin Contributions:
0

Re: Displaying Product Viewed in Product Listing Page

DivaVocals:

Invest your time into building effective sites with good content.. Site counters are passes, notoriously inaccurate and will not provide the benefit you think they will.

Thank you again for your kind advise. I will follow it, although now the new code fulfilled the function of products viewed report on products listing page. Anyway, appreciated for all of yours.

25 Apr 2015, 1:29 PM
#37
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Displaying Product Viewed in Product Listing Page

Eric Chen:

Wonderful!!! It is working now by inserting the new code programmed in another way. Appreciated...

It is really odd that you could not get the function zen_products_lookup to work for the products_viewed but could for everything else ...

The direct adding of the products_viewed to the SELECT does work around the problem, but you should not have had to do that ...

NOTE: just a reminder, it is a good time to upgrade to Zen Cart v1.5.4 to get your code up to date!