Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recently Viewed


leolll

Recommended Posts

I've read posts of people running into complexities while trying to make a ?Recently Viewed? infobox. The main problem being that a database table would have to store the customer?s ID and products viewed, and that this table would balloon in size and have to be deleted periodically.

 

My question is why not store their last three products viewed in a session variable and not deal with the above problem.

 

I'm not a php expert so if the above doesn't make sense, don't be too harsh. :lol:

 

Leo

Link to comment
Share on other sites

Thanks Meltus, you've made that really easy to follow & a great mod too. :D

 

Has anyone managed to add images to this contribution? This is the query I'm using

$recent_info = tep_db_query("select p.products_id, p.products_image from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . $recently_viewed . "' and pd.products_id = '" . $recently_viewed . "' and pd.language_id = '" . $languages_id . "'");

$recent_info_values = tep_db_fetch_array($product_info);

$recent_image = $recent_info_values['products_image'];

, but I can't get the image into the array for the infobox contents.

$info_box_contents[] = array('align' => 'left',

                                'text'  => $counter . '. <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $recent, 'NONSSL') . '">' . tep_get_products_name($recent) . '</a>' 

                               );

I've tried following the way the image is added in the what's new box, but that doesn't work.

Where am I going wrong?

Link to comment
Share on other sites

you are almost there .....

 

foreach ($recent_products as $recent) {



       if ((strlen($recent) >0) && ($counter < 10)) {

$recent_info = tep_db_query("select  p.products_image from " . TABLE_PRODUCTS . " p where p.products_id = '" . $recent. "'");

$recent_info_values = tep_db_fetch_array($recent_info);

               $counter++;

                if (strlen($counter) < 2) {

     $counter = '0' . $counter;

   }

       $info_box_contents[] = array('align' => 'left',

                                'text'  => $counter . '. <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $recent, 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . $recent_info_values['products_image'],  tep_get_products_name($recent)) . '<br>' . tep_get_products_name($recent) . '</a>'

                               );

               }

       }

   new infoBox($info_box_contents);

 

that will put a picture and the name underneath. I imagine it would look pretty cool as a row of about 5 in the header or footer on some sites.

Link to comment
Share on other sites

Thanks Meltus, I was missing out the $recent_info_values = tep_db_fetch_array($recent_info); :roll: I'm still having problems trying to get them to show as rows. I'd like to try 2 rows of 5 as the maximum. This is what I have so far, but I get an error 3 lines up from the bottom of this code

foreach ($recent_products as $recent) {



       if ((strlen($recent) >0) && ($counter < 10)) {

$recent_info = tep_db_query("select  p.products_image from " . TABLE_PRODUCTS . " p where p.products_id = '" . $recent. "'");

$recent_info_values = tep_db_fetch_array($recent_info);

               $counter++;

                if (strlen($counter) < 2) {

     $counter = '0' . $counter;

         $row = 0;

   }

       $info_box_contents[] = array('align' => 'left',

                                'text'  => $row++,

                                'text'  => $counter . '. <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $recent, 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . $recent_info_values['products_image'], tep_get_products_name($recent)) . '<br>' . tep_get_products_name($recent) . '</a>'

                               );

                                   $col ++;

   if ($col > 4) {

     $col = 0;

     if ((($row / 2) == floor($row / 2)))

               }

       }

   new infoBox($info_box_contents);

Parse error: parse error, unexpected '}' in /home/virtual/site131/fst/var/www/html/includes/boxes/recently_viewed.php on line 48
Getting rid of the } just produces more errors.
Link to comment
Share on other sites

You seem to be short a }, plus try adding {} to the if statement, like this:

foreach ($recent_products as $recent) {

 if ((strlen($recent) >0) && ($counter < 10)) {

   $recent_info = tep_db_query("select  p.products_image from " . TABLE_PRODUCTS . " p where p.products_id = '" . $recent. "'");

   $recent_info_values = tep_db_fetch_array($recent_info);

   $counter++;

   if (strlen($counter) < 2) {

     $counter = '0' . $counter;

     $row = 0;

   }

   $info_box_contents[] = array('align' => 'left',

                                'text'  => $row++,

                                'text'  => $counter . '. <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $recent, 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . $recent_info_values['products_image'], tep_get_products_name($recent)) . '<br>' . tep_get_products_name($recent) . '</a>'

                               );

   $col ++;

   if ($col > 4) {

     $col = 0;

     $row++;

     if (($row % 2) == 0) {  // if an even row



     } else { // it's an odd row



     }

   }

 }

}

new infoBox($info_box_contents);

For the logic to work, you need to increment $row; however, I only guessed as to location. I also changed the indentation and the test in the if. I find it more readable this way. YMMV. Hopefully this code will at least parse for you.

 

Good luck,

Matt

Link to comment
Share on other sites

<!-- recently_viewed //-->

         <tr>

           <td>

<?php

define('MAX_COLS', 3);

define('MAX_ROWS', 3);



 if (strlen($recently_viewed>1)) {

   $info_box_contents = array();

   $info_box_contents[] = array('align' => 'left',

                                'text'  => 'RECENTLY VIEWED'

                               );

   new infoBoxHeading($info_box_contents, false, false);



$counter = 0;

   $info_box_contents = array();

   $recent_products = split(';',$recently_viewed);



$rows=0;

$cols=0;

foreach ($recent_products as $recent) {  if ((strlen($recent) >0) && ($counter < (MAX_ROWS*MAX_COLS)) && ($cols<MAX_COLS)) {    

 $recent_info = tep_db_query("select  p.products_image from " . TABLE_PRODUCTS . " p where p.products_id = '" . $recent. "'");

 $recent_info_values = tep_db_fetch_array($recent_info);

 $counter++;

 if (strlen($counter) < 2) {

   $counter = '0' . $counter;

 }

 $info_box_contents[$rows][$cols] = array('align' => 'left',

         'params' =>'class="productListing-data"',                                 'text'  => $counter . '. <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $recent, 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . $recent_info_values['products_image'], tep_get_products_name($recent)) . '<br>' . tep_get_products_name($recent) . '</a>'

      	 );

 $rows++;

 if ($rows >= MAX_ROWS) {

   $rows = 0;

   $cols++;

 }

  }

}

new tableBox($info_box_contents,true);

 }?>

           </td>

         </tr>

<!-- recently_viewed_eof //-->

 

that just finishes off what matt started ...

Link to comment
Share on other sites

FANTASTIC - thanks Matt & Matt! (sorry for getting you confused)

 

Being picky, I've tweeked it a little so that it fills across the rows, rather than down the columns.

      $cols++;

     if ($cols >= MAX_COLS) {

       $cols = 0;

       $rows++;

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

Hi,

 

I just installed the 'recently viewed' contribution (for a text list, not for images) -- great idea! My problem is that it only shows the current product in the list.

 

As I navigate through the categories to view another product, the list is empty (box actually disappears). When I finally land on another product, again, the current product is the only one shown in the list.

 

Any suggestions on getting all viewed items to show?

 

(my site is http://www.giftsthatdelight.com)

 

Thanks!

 

Caroline

Link to comment
Share on other sites

  • 1 year later...

Nice contribution but what I'd really like to do is display the recently viewed products inline on the product_info page.

 

How would I go about doing this?

Most Valuable OsCommerce Contributions:

Also Purchased (AP) Preselection (cuts this resource hogging query down to nothing) -- Contribution 3294

FedEx Automated Labels -- Contribution 2244

RMA Returns system -- Contribution 1136

Sort Products By Dropdown -- Contribution 4312

Ultimate SEO URLs -- Contribution 2823

Credit Class & Gift Voucher -- Contribution 282

Cross-Sell -- Contribution 5347

Link to comment
Share on other sites

  • 3 weeks later...

I can't get this to work, after installed it shows nothing...

 

in catalog/product_info.php
----------------------------

insert this code ...

if (!tep_session_is_registered('recently_viewed'))
?{
?tep_session_register('recently_viewed');
?$recently_viewed = $HTTP_GET_VARS['products_id'] . ';';
?//$recently_viewed = "";
?}
$check_not_duplicate = $HTTP_GET_VARS['products_id'];
$temp_recent = $recently_viewed;
if (!ereg($check_not_duplicate, $temp_recent ) )
$recently_viewed = $HTTP_GET_VARS['products_id'] . ';' . $recently_viewed;


I put it just before 

$product_info_query = tep_db_query("select

or $product_info = tep_db_query("select ?on some versions


but it isn't that important.

 

"but it isn't that important" Does that mean that peice of code doesn't need to be added?

 

Cheers..

Edited by Vince76
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...