leolll Posted July 18, 2003 Share Posted July 18, 2003 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 Quote Link to comment Share on other sites More sharing options...
Guest Posted July 18, 2003 Share Posted July 18, 2003 i have just released a contribution for recently viewed products here ... http://www.oscommerce.com/community/contributions,1363 Quote Link to comment Share on other sites More sharing options...
Guest Posted July 21, 2003 Share Posted July 21, 2003 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? Quote Link to comment Share on other sites More sharing options...
Guest Posted July 22, 2003 Share Posted July 22, 2003 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. Quote Link to comment Share on other sites More sharing options...
Guest Posted July 22, 2003 Share Posted July 22, 2003 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. Quote Link to comment Share on other sites More sharing options...
Guest Posted July 22, 2003 Share Posted July 22, 2003 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 Quote Link to comment Share on other sites More sharing options...
Guest Posted July 22, 2003 Share Posted July 22, 2003 Well it parses now, thanks to Meltus, but I still can't get it into rows. Any suggestions please, anyone? Quote Link to comment Share on other sites More sharing options...
Guest Posted July 22, 2003 Share Posted July 22, 2003 <!-- 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 ... Quote Link to comment Share on other sites More sharing options...
Guest Posted July 22, 2003 Share Posted July 22, 2003 in case it isn't obvious - you just need to set MAX_ROWS and MAX_COLS to what ever you need Quote Link to comment Share on other sites More sharing options...
Guest Posted July 22, 2003 Share Posted July 22, 2003 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++; Quote Link to comment Share on other sites More sharing options...
sgflowers Posted July 22, 2003 Share Posted July 22, 2003 can you add the image mods to the contribution Quote Link to comment Share on other sites More sharing options...
Guest Posted July 22, 2003 Share Posted July 22, 2003 tis already there ;-) Quote Link to comment Share on other sites More sharing options...
Guest Posted July 30, 2003 Share Posted July 30, 2003 is this MS2 compatible or should it work with both, i actually want to use it with an older store :) Quote Link to comment Share on other sites More sharing options...
Guest Posted July 30, 2003 Share Posted July 30, 2003 Can't say if it works with MS2, but it works well with loaded5/ MS1. 8) Quote Link to comment Share on other sites More sharing options...
Guest Posted September 2, 2003 Share Posted September 2, 2003 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 Quote Link to comment Share on other sites More sharing options...
homewetbar Posted October 1, 2004 Share Posted October 1, 2004 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? Quote 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 More sharing options...
Vince76 Posted October 20, 2004 Share Posted October 20, 2004 (edited) 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 October 20, 2004 by Vince76 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.