The page you requested does not exist. A search for api function drupal bootstrap full 1 0 resulted in this page.
48 replies [Last post]
naturesimple's picture
Offline
Joined: 04/20/2008
Juice: 27

I've been trying out drupal and ubercart as a potential replacement for a Zen Cart store, and one of the features that I know my customers really like is the recently viewed products block.

I've been looking around the forums looking for something, and I feel like all of the pieces should be there, but I'm not really sure how to put them together.

I found a piece of code in the drupal forums (http://drupal.org/node/65679) that can be used to list recently viewed pages, but that doesn't seem to translate special characters (like 's or &s). I can read through php, but I'm definitely not a programmer. Ideally, I'd like to be able to list the product name and/or image and/or price in the block, and this code only lists a link to all recently visited pages (not just catalog products).

I also thought that there might be a cool solution for this by using a combination of worflow-ng, views, and content blocks, but I'm not sure how to put it all together.

If anyone has done this or could give me some pointers in the right direction, I'd really appreciate it. Generally I really like the flexibility of Ubercart, but there are a few things that I need to make sure I can do before I commit to rebuilding my store...

Thanks,
Jeremy
http://naturesimple.com

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15422
Re: Recently viewed products list?

Hey Jeremy, cool idea. I searched and that was the only snippet on Drupal.org that I could turn up, too. Sticking out tongue This might make for an interesting contributed module for whoever turns it out. That snippet is lacking at the very least a check_plain() around the title of the link... it's potentially vulnerable to an XSS attack as is. It also depends on the statistics module...

I think for what you're looking to accomplish, you'll need to track node views in some other table... You'll need a way to store the actual nid so you can more easily query the DB for product data and image paths. I'm not sure how making this into a Views filter would work, but I think you're right in assuming that's the way to go.

woc_art's picture
Offline
Joined: 03/26/2008
Juice: 63
Hi there, I've done

Hi there,

I've done something like this really easily with Views. All I needed was the Views module and the Views bonus pack so that I could layout everything in a grid. Now I have a block that looks almost identical to the catalog that shows the items sorted by recent page-views.

I'm really new to Drupal so I'm not sure if this will work. Here's the code I get when I try to export the view:

  $view = new stdClass();
  $view->name = 'featured_items';
  $view->description = 'Featured Items';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = 'Featured Items';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'bonus_grid';
  $view->url = 'Featured_Items';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '12';
  $view->block = TRUE;
  $view->block_title = 'Featured Items';
  $view->block_header = '';
  $view->block_header_format = '1';
  $view->block_footer = '';
  $view->block_footer_format = '1';
  $view->block_empty = '';
  $view->block_empty_format = '1';
  $view->block_type = 'bonus_grid';
  $view->nodes_per_block = '3';
  $view->block_more = TRUE;
  $view->block_use_page_header = FALSE;
  $view->block_use_page_footer = FALSE;
  $view->block_use_page_empty = FALSE;
  $view->sort = array (
    array (
      'tablename' => 'node_counter',
      'field' => 'daycount',
      'sortorder' => 'DESC',
      'options' => '',
    ),
  );
  $view->argument = array (
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'sortable' => '1',
      'options' => 'link',
    ),
    array (
      'tablename' => 'node_data_field_image_cache',
      'field' => 'field_image_cache_fid',
      'label' => '',
      'handler' => 'content_views_field_handler_ungroup',
      'options' => 'product_list_linked',
    ),
    array (
      'tablename' => 'uc_products',
      'field' => 'sell_price',
      'label' => '',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'uc_products',
      'field' => 'is_product',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node_counter, node, node_data_field_image_cache, uc_products);
  $views[$view->name] = $view;

I don't know if that's useful to you though. Hope this helped!

naturesimple's picture
Offline
Joined: 04/20/2008
Juice: 27
Re: Hi there, I've done

Thanks for the suggestion. This looks like a cool view to show the products that have been viewed the most times (and I like the bonus grid view). However, I don't think this accomplishes quite what I'm looking for, which is a listing of products that individual users have viewed during their current visit.

This isn't really a dealbreaker for me, especially since I don't think I can code a new module myself, but I appreciate the suggestion!

Jeremy
http://naturesimple.com

naturesimple's picture
Offline
Joined: 04/20/2008
Juice: 27
Recently viewed products module

I've been familiarizing myself with Ubercart and Drupal over the past few weeks, and I've put together a small module that will show recently viewed products for a user.

The module is basically a stripped down and modified version of the statistics modules. Product views are stored in the database and can be displayed in a basic block. The block displays the five most recently viewed products for a user if the user is logged in, and for the user's IP address if not logged in.

The module clears data from the database (if you have cron running) after three days, similar to the stats module.

There currently aren't any configuration pages, but you can modify the number of products to be displayed in the SQL statement within the module. If I venture further into module development, I think it would be cool to set options for the number of products to display, the length of time data get stored in the database, and possibly a better block display.

I would love some testing and feedback of the programming if anyone else is interested in this. This is my first attempt at putting together something like this, and my familiarity with drupal and ubercart coding standards is pretty basic, so I welcome any suggestions for improvement.

I have tried a few different ways of displaying the product thumbnail next to the name (as in the Upsell contrib), but nothing seems to work for me. I'm not sure if that's due to the way I'm storing the product info or what, but I'd really love feedback/suggestions on how to do that in particular.

Thanks!
Jeremy

AttachmentSize
uc_recent_products.zip 3.42 KB
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15422
Re: Recently viewed products module

Great work, Jeremy. I put it up on the Livetest and it works, though I'll make the following recommendations to point you in the right direction:

  1. Don't include version and project lines in your .info files. Drupal adds these automatically when it packages modules up for download from drupal.org (where you'll eventually want to host this module when it's done).
  2. I had to rename the table recent_products to uc_recent_products. It just looks like you forgot to update your install file. Smiling
  3. A couple notes about the database table you're making:
    • D5 and lower prefers the use of db_next_id() to keep track of IDs instead of AUTO_INCREMENT, primarily so it's easy to use across DB types. I'm not sure how strict this is. For examples, you can search against that function in Ubercart.
    • I'd add an index on the user's ID since you're going to be querying against that... and I'm not sure how the index on the timestamp affects things. Puzzled Will it actually provide a benefit?
    • Since timestamp is a reserved keyword for MySQL, you might consider calling this column created or something.
  4. I'm not sure about storing the host name in case the user isn't logged in. Other parts of Drupal and the cart module itself use the session ID if a user isn't found... this way you don't run into any trouble of folks on a network using the same IP and such. You can check the cart module for an example of how to use this, and it will also cut out the need for separate columns for UID and hostname.
  5. Your code style isn't that bad - you might review the control structures section of the Drupal coding standards. Also make sure you're using two spaces instead of a tab (you can probably configure your IDE to do this for you).
  6. You have some mismatched braces so that your hook_user() function is inside your hook_block() function.
  7. In terms of building the content, I'd recommend instead of adding the links to $block_content directly, make an array of the links and then use Drupal's theme system to theme them into an unordered list (Drupal uses a similar convention for several other utility blocks):
    <?php
      $items
    = array();
      while (
    $link = db_fetch_object($query)) {
       
    $items[] =  l(check_plain($link->title), 'node/' . $link->nid);
      }

      if (

    count($items) == 0) {  
        return;
      }

     

    $block['subject'] = t('Recently Viewed Products');
     
    $block['content'] = theme('item_list', $items);
      return
    $block;
    ?>
  8. Notice I added a check_plain() in there. It's part of Drupal's security measures to prevent XSS attacks in user entered strings, like node titles. See spefically Handle text in a secure fashion.
  9. I also added in a t() - you should wrap your string literals in this function so other folks can translate them w/ Drupal's translation stuff.

I hope this is all helpful. It's just things I've picked up as I've learned to do module development better... there's a lot to remember. Smiling

Also, are you sure you need to do the bootstrap in your hook_exit()? Was arg() not working properly without that?

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6841
Re: Re: Recently viewed products module

l() automatically does check_plain() on the link text, unless the $html flag is set. It's still a good habit to get into, though, to make sure your displayed strings are secure.

naturesimple's picture
Offline
Joined: 04/20/2008
Juice: 27
I've made some substantial

I've made some substantial updates to the module based on Ryan's suggestions and some digging through other modules and the documentation on the Drupal website (which has great documentation, even if it does take a while to navigate through for a novice!).
Here are the major updates:

  1. I added a check to restrict the tracking of page views to nodes only. Previously, if a catalog page had the same arg(1) as a product node, it would record that as a page view, and the rogue product would display on the list.
  2. I modified the database queries to use the session ID rather than user ID/hostname to store and retrieve product views. As Ryan suggested, this eliminates the need to store separate data for anonymous and logged in users.
    • I also updated the table structure to elimate the auto_increment and instead used db_next_id()
    • This change also means that any data collected from testing my initial upload will become worthless once you install this update. Thus, this update will delete your existing {uc_recent_products} table and regenerate the new table structure. I added an update function that deletes all columns and regenerates the table. I get an error returned when I run the update, even though the update seems to make all of the requested changes, but maybe I have something coded funny in the update?
  3. Using the session ID to track views also eliminated the need and the usefulness of the hook_user() funtion, so I removed that function.
  4. I built the block content using the standard code suggested by Ryan, and I added a theme to output the block contents in a table displaying the product thumbnail, product name, and sell price. I did not use check_plain() because it messed up the display of my product names that have special characters (e.g. & and 's). Since since check_plain() is already implemented in the l() in the theme, I'm assuming that will meet security needs (as mentioned above).
    • A .css file is included to allow custom styling of the block.
  5. I added a configuration form (located at admin/settings/recentproducts) that will allow to set the number of products to display in the block as well as the number of days to keep the product views before deleting them from the database (through cron).

If you'd like to see the module in action, you can browse through the catalog on my ubercart test site: http://naturesimple.com/ubercart/

One outstanding question: When a use logs in, a new session is created. This means that if a user is browsing through products before logging in, the user will lose the recent product listing upon login. Is there a way to convert data to the new session when a user logs in? I looked through uc_cart, figuring that would happen in there, but I haven't been able to figure it out yet...

As with my previous upload, I'd definitely appreciate any feedback or suggestions. I will upload the contribution to Drupal once I have had time to test a little more (and once I create a CVS account).

Thanks!
Jeremy

AttachmentSize
uc_recent_products.zip 4.98 KB
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15422
Excellent job there. I

Excellent job there. Laughing out loud

I don't have time to review the whole module again, but it sounds like you made some excellent progress! In answer to your question, check out the function uc_cart_user() in the cart module for its 'login' $op. You can see the update query in there I'm using to change the cart ID for an anonymous user's cart items to their user ID as they login.

In fact, I wish I had thought of this before, but you can use or at least mimic the function uc_cart_get_id() to get either the user ID if a user is logged in or the session ID if he isn't.

naturesimple's picture
Offline
Joined: 04/20/2008
Juice: 27
Re: Excellent job there. I

Thanks again Ryan - those are exactly the two functions that I was looking for. I haven't had a chance to get this logged as a contribution in Drupal, but I did make updates based on these functions.

Now, product views are tracked by session ID if a user is not logged in, and user ID if they are. When a user logs in, the products that they viewed before logging in will be updated so they are associated with the user ID instead of the session.

AttachmentSize
uc_recent_products.zip 3.18 KB
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15422
Re: Re: Excellent job there. I

Great job. If you're anything like me, I imagine all this learning has been fun. Smiling

naturesimple's picture
Offline
Joined: 04/20/2008
Juice: 27
Re: Recently viewed products list?

Thanks for the feedback. I'll take a look at this over the next couple of days and make some updates!

Jeremy

ericmalone's picture
Offline
Joined: 05/15/2008
Juice: 31
Good work! Marking for

Good work!

Marking for future reference.

mcneelycorp's picture
Offline
Joined: 10/26/2007
Juice: 72
Re: Recently viewed products list?

Thanks for the module. I ran into some T_LNUMBER errors with the .install file. Turned out to be the use of apostrophes instead of quotes.

AttachmentSize
uc_recent_products.tar 11.5 KB

===
Elvis McNeely
Blogging about Drupal: http://www.elvisblogs.org/drupal

ajwatt's picture
Offline
Joined: 10/27/2008
Juice: 2
error in install file?

Somewhere between posts #4 and #9 above, a bug was introduced into the .install file. After post #9, line 10 in uc_recent_products.install reads
rid int unsigned NOT NULL default '0ALTER TABLE {$table} ADD PRIMARY KEY $column ($column)',

But in the file attached in post #4 it reads rid int NOT NULL auto_increment,.

Could someone tell me what it should be? I changed mine so that it was "default '0'" and it seems to work now, but I want to be sure that is correct.

Andy

tcindie@drupal.org's picture
Offline
Getting busy with the Ubercode.
Joined: 05/15/2008
Juice: 440
ajwatt wrote:Somewhere
ajwatt wrote:

Somewhere between posts #4 and #9 above, a bug was introduced into the .install file. After post #9, line 10 in uc_recent_products.install reads
rid int unsigned NOT NULL default '0ALTER TABLE {$table} ADD PRIMARY KEY $column ($column)',

The error is default '0ALTER

should probably be this:
rid int unsigned NOT NULL default "0" ALTER TABLE {$table} ADD PRIMARY KEY $column ($column)',

EDIT: Just realized this is an exceptionally old thread, but this might help someone who's looking at it now I guess. Smiling

Follow me on twitter.

Insurrectus's picture
Offline
Spreading the word - Ubercart for president.
Joined: 08/22/2007
Juice: 364
Any plans for D6 U2 support for this module.

I'd be happy to help test.

backdrifting's picture
Offline
Joined: 10/04/2008
Juice: 373
Can we get this to work for D6?

I'm trying to get this module to work in Drupal 6 / UC 2. I updated the .info file so it can be recognized in my module admin list. However when I enable the module I get the following error:

user warning: Table 'msd.uc_recent_products' doesn't exist query: SELECT DISTINCT nid FROM uc_recent_products WHERE sid = '1' ORDER BY visit_time DESC LIMIT 5 in /var/www/msd/sites/all/modules/ubercart/uc_recent_products/uc_recent_products.module on line 75.

I also commented out this line in the module code since this was also throwing an error:

// $id = db_next_id('{uc_recent_products}_rid');

Any suggestions on how to get this working for D6 / UC2?

Thanks,

backdrifting

katiebot's picture
Offline
Joined: 11/08/2007
Juice: 2
Drupal 6

I've updated this module to work in Drupal 6 / Ubercart 2. I've also removed the tables for displaying the products in favour of CSS, so you'll need to copy the styles in the stylesheet to your themes stylesheet and apply your own styling, as I assume everyone will be using this in different ways. Let me know if there are any problems : )

AttachmentSize
uc_recent_products.tar.gz 2.1 KB
bladedmink's picture
Offline
Joined: 09/25/2009
Juice: 6
Re: Drupal 6

Have removed DISTINCT from the SELECT statement in uc_recent_products_block to make this work correctly.
Previously the products were not being displayed in order of last viewed.

OLD
------
$query = db_query_range("SELECT DISTINCT nid FROM {uc_recent_products} WHERE sid = '%s' ORDER BY visit_time DESC", uc_recent_products_get_id(), $from = 0, $count = $limit);

NEW
-----
$query = db_query_range("SELECT nid FROM {uc_recent_products} WHERE sid = '%s' ORDER BY visit_time DESC", uc_recent_products_get_id(), $from = 0, $count = $limit);

Also you need to update uc_recent_products_exit() to delete duplicates

// Delete duplicates
db_query('DELETE FROM {uc_recent_products} WHERE nid = %d', arg(1));

// Insert newly selected node view
db_query("INSERT INTO {uc_recent_products} (rid, nid, sid, visit_time) values(%d, %d, '%s', '%s')", $id, arg(1), uc_recent_products_get_id(), time());

Also functionality to choose the content types to index would be beneficial. Maybe add this within the uc_recent_products_form function
At the moment it's indexing everything.

btw this is a great ubercart module extra, why hasn't it been added as a Drupal Module Project on drupal.org?

dbh01's picture
Offline
Joined: 10/07/2009
Juice: 2
Better selection of most recent product

Rather than doing a distinct or simply just removing it....

I think a GROUP BY nid and HAVING_MAX(visit_time) will work better. Here is the query I'm using.

$query = db_query_range("SELECT nid FROM {uc_recent_products} WHERE sid = '%s' GROUP BY nid HAVING MAX(visit_time) ORDER BY visit_time DESC", uc_recent_products_get_id(), $from = 0, $count = $limit);

bladedmink's picture
Offline
Joined: 09/25/2009
Juice: 6
Fabulous I've just

Fabulous

I've just integrated this into a new site I developed.

See it here http://www.jips.com.au

birchy82's picture
Offline
Joined: 05/22/2009
Juice: 22
Re: Recently viewed products list?

Well I have working on my site, the module that was updated for 6, works well I did the code updates in the last few posts, but the only problem is that it shows when I clicked contact us, or shipping and returns in the recently viewed products block.

Any Idea's for a fix?

bladedmink's picture
Offline
Joined: 09/25/2009
Juice: 6
Display only the recent nodes of interest

Hi birchy. Sorry for not getting back sooner.

Yes, I noticed this problem where it was indexing all nodes
within Drupal and not just the Ubercart product nodes themselves.

You will need to update the uc_recent_products_exit function manually.

Here is the changes I made to the function to display only the recent product nodes
of interest.

Have a look at the SELECT cause in the function

Hope this points you in the right direction.

function uc_recent_products_exit() {
  global $user;
  //$id = db_last_insert_id('uc_recent_products', 'rid');

     if (arg(0) == 'node')
     {
         $count = db_result(db_query('SELECT count(*) FROM node node WHERE (node.type in (\'product\', \'dress\', \'bag\', \'accessory\', \'top\')) AND (node.nid = %d)', arg(1)));

         if ($count > 0)
         {
            //if (arg(0) == 'node' && db_result(db_query("SELECT nid FROM {uc_recent_products} WHERE nid = %d", arg(1))) && (module_invoke('throttle', 'status') == 0)) {
            if (arg(0) == 'node' && (module_invoke('throttle', 'status') == 0))
            {
                // Delete duplicates
               db_query('DELETE FROM {uc_recent_products} WHERE nid = %d', arg(1));

               // Insert newly selected node view
               db_query("INSERT INTO {uc_recent_products} (rid, nid, sid, visit_time) values(%d, %d, '%s', '%s')", $id, arg(1), uc_recent_products_get_id(), time());
            }
         }
     }
}

birchy82's picture
Offline
Joined: 05/22/2009
Juice: 22
Re: Display only the recent nodes of interest

Thanks a lot, i implemented it and it works wonderfully. You are a life saver.

Rocinant's picture
Offline
Joined: 12/11/2009
Juice: 2
Images link to node

Hi Bladedmink,

Thanks for your work on the 'recently viewed' product list. It works great on your site!
I have a question that is puzzling me for some time now: how do you link the product images to the nodes? The original module only links the titles to the nodes.
Or - even better - could you post your reworked module on the forum?

Thanks in advance!
Rocinant

kmonty@drupal.org's picture
Offline
Joined: 03/15/2010
Juice: 9
New Version

I did significant clean up and bug fixes.

Changes:
1) fixed errors with hook_block, made it not cache (previously cache per role, which had obvious problems).
2) Added a hook_nodeapi so deleted nodes / unpublished nodes were deleted from recent lists
3) fixed bug with hook_exit that caused people to arbitrarily lose nodes from their recent list
4) Fixed documentation/spacing to match drupal's coding standards.
5) optimized the code of hook_exit
6) Fixed a bug in hook_form

AttachmentSize
uc_recent_products_031510.tar.gz 2.32 KB
kmonty@drupal.org's picture
Offline
Joined: 03/15/2010
Juice: 9
Update.

Two new bug fixes:
1) Made it so *only* product nodes get added to the recent list (it was previously set so any nodes could get added. Doh!)
2) Made the product image a link

AttachmentSize
uc_recent_products_032910.tar.gz 2.35 KB
u280ks's picture
Offline
Joined: 12/19/2009
Juice: 17
Hi I've installed the latest

Hi
I've installed the latest update of uc_recent_products on Ubercart 2.2 and Drupal 6.16, added the block to display on the right side bar but for some reason I couldn't get it work.
Is there any configuration I should make after installing the module?

volocuga's picture
Offline
Joined: 02/09/2009
Juice: 68
Re: Update.
Quote:

Made it so *only* product nodes

Great but what if I have several product types?

How to check is node "ubercart node class" or not?

TimJFowler's picture
Offline
Joined: 07/09/2010
Juice: 5
I'm having a problem similar to Ven's

I'm using Drupal 6.17 and Ubercart 6.x-2.3

I've installed uc_recent_products_032910.tar.gz and get this error message -

" user warning: Table 'auboudoir.uc_recent_products' doesn't exist query: SELECT nid FROM uc_recent_products WHERE sid = '1' ORDER BY visit_time DESC LIMIT 0, 3 in /home/auboudoir/www/auboudoir.com/sites/all/modules/uc_recent_products/uc_recent_products.module on line 120. "

I attempted to add table uc_recent_products with the fields rid, nid, sid, visit_time according what I read in the uc_recent_products.install file. But, I wasn't successful (got the syntax wrong somewhere).

Any help would be appreciated,
Tim

joodas's picture
Offline
Joined: 05/13/2010
Juice: 33
Flag + Rules + Views

Hi there,

This is actually quite easy to accomplish using Flag, Rules and Views modules. You might want to have a look at the article I just wrote today:

http://jan.tomka.name/blog/list-recently-viewed-nodes-drupal

Cheers,
Jan

u280ks's picture
Offline
Joined: 12/19/2009
Juice: 17
Thanks a lot

Thank you Jan

It works perfect!

Is there a way to have this feature for anonymous users too?

joodas's picture
Offline
Joined: 05/13/2010
Juice: 33
Re: Thanks a lot

Although I haven't tried it (will have to give it a shot soon), in the article I mentioned Session API's support for Flag. I believe that's the way to go. Ideally, you'll only need to install Session API, set it up and your current set up should be working for anonymous users as well. Let me know how go. Cheers, Jan

joodas's picture
Offline
Joined: 05/13/2010
Juice: 33
Recently viewed content for anonymous users
  1. Install and enable Flag-6.x-2.x and Session API
  2. In your recently_viewed flag configuration, allow anonymous users to both flag and unflag.
  3. There's no step 3!

The thing is, it doesn't seem to be working 100% correct. Looks like a caching problem to me, will have look into it a bit closer. Anyway, give it a try and let me know what it's doing for you.

u280ks's picture
Offline
Joined: 12/19/2009
Juice: 17
Hi Jan Thanks a lot I've

Hi Jan
Thanks a lot
I've installed Session API and update it Flag to 6.x-2.0-beta3 on my test site and at a first glance everything seems to work fine.
I'll let you know as soon as I enable this feature on my live site or if I encounter any problem.

Thank you again for the great tutorial!

moondrop's picture
Offline
Joined: 03/24/2010
Juice: 253
Can't get recently viewed items to work

I did exactly as Joodas described above on the website and enabled the modules and the block, but for some reason nothing shows up at all. I'm not sure what I did wrong, but it's not working for me. I went step by step...any ideas??

I want my users to have recently viewed items (product title and image) in the block.

joodas's picture
Offline
Joined: 05/13/2010
Juice: 33
Re: Can't get recently viewed items to work

If you did exactly what the tutorial says, you might have forgotten to select your content type in either Flag or Views configuration. Also, I found the Flag relationship configuration in Views a bit tricky. It took a few takes for me to work it out. Anyway, send me a private message with detailed information and I can have a look.

volocuga's picture
Offline
Joined: 02/09/2009
Juice: 68
Re: Recently viewed products list?

The solution provided by joodas too complex imo. I'm using Views and Flag modules but if I need to install Rules (which is big baby)...Hm..Not sure

joodas's picture
Offline
Joined: 05/13/2010
Juice: 33
Re: Re: Recently viewed products list?

Rules is only required to re-flag and thus update the flagging timestamp. It shouldn't take more than a dozen lines of code to get Flag do it automatically.

Anyway, I haven't been able to find a decent solution to the "Recently viewed" problem for ages. This one seems to work okay and is pretty flexible, too. All that with only a few minutes of configuration. I definitely wouldn't call it complex.

Please, let me know what you end up using instead. Cheers.

volocuga's picture
Offline
Joined: 02/09/2009
Juice: 68
Re: Recently viewed products list?

I modified the latest version posted by kmonty (see #27)

Minor changes: replaced $node->type == 'product' with uc_product_is_product($node)
so now we can see all "products" nodes, not only nodes named "product"

works fine for me

AttachmentSize
uc_recent_products_mod.zip 3.02 KB
BriteSparkz's picture
Offline
Joined: 07/11/2010
Juice: 10
Re: Re: Recently viewed products list?

This is working quite well for me. I am not sure if this was posted above, but one modification that I made was to insert the image field name in place of the default that is within the module code. Is there any chance this will be released as a full fledged module?

SkidNCrashwell's picture
Offline
Joined: 09/25/2010
Juice: 12
VAT/Tax not showing

This module appears to do exactly what I want to do, show the last 5 items a visitor viewed on my site.

Except there's one (rather major!) issue I have. I have uc_vat installed on my site and the prices in the block are shown without VAT added, so in its current form, it’s not much good to me. Anyone have any ideas how I can get it to show VAT inclusive prices?

Thanks

SkidNCrashwell's picture
Offline
Joined: 09/25/2010
Juice: 12
Solution using Views

OK so I had another crack at this and I came up with another solution which some people may like to try and modify.

I'm storing the Node ID of the product page in hook_exit() (to avoid caching issues). I've written the code so that it checks the node id is a product, is a numeric value and the node is published. If so, it stores the ID in the session. I've also written it so that if the Node ID already exists in the session (perhaps someone is revisiting the page) then it bumps the ID to the top of the list.

Then I created a simple View to display the thumbnail ImageCache preset, the node title (both linked to the node) and the price. In order to use the Node IDs from the session, I'm using Views arguments and PHP code and all I do is return the session array, but implode the pieces with '+' to allow multiple view arguments. In order to get the nodes to display in the order from my string, I installed the Views Argument Sort module and set this as descending so the most recent nodes are the top of the list.

At present, I just created a simple block showing the 3 latest nodes, but I plan to create a page view to show all the nodes (I'm only storing a max of 30 in the session) too.

Feedback is more than welcome. You also may need to install the Semantic Views module to get this working as I use that, but there's nothing to stop you from changing it to a plain Unformatted view etc.

AttachmentSize
uc_recently_viewed.zip 4.42 KB
SkidNCrashwell's picture
Offline
Joined: 09/25/2010
Juice: 12
Small fix

The PHP code in the view argument should probably be

if (isset($_SESSION['uc_recently_viewed']) && is_array($_SESSION['uc_recently_viewed'])) {
  return implode($_SESSION['uc_recently_viewed'], '+');
}

To avoid warnings...

So the uc_recently_viewed.views_default.inc file should be this on line 173

      'default_argument_php' => 'if (isset($_SESSION[\'uc_recently_viewed\']) && is_array($_SESSION[\'uc_recently_viewed\'])) {
  return implode($_SESSION[\'uc_recently_viewed\'], \'+\');
}',

And line 17 of the module should be changed to

       if (isset($_SESSION['uc_recently_viewed']) && in_array($node->nid, $_SESSION['uc_recently_viewed'])) {
make-online-shop's picture
Offline
Joined: 01/01/2011
Juice: 216
Re: Solution using Views

Recent View products block ?

Hello,

Is it the latest update of your module ? Working well on D6 ?

I would also really like to remind my customers what products they have previously seen.

Thanks a lot.

manju1012's picture
Offline
Joined: 12/27/2010
Juice: 3
Plz Help Me

Hi Every one, This is Manjunath .
I am new to Drupal. I am working one shopping cart with ubecart.

I want listing the products based on catalog. Plz help me.

Thanks in advance.

Rgds

Manju

make-online-shop's picture
Offline
Joined: 01/01/2011
Juice: 216
Re: Recently viewed products list?

Easiest way to show LATEST VIEWED PRODUCTS list ?

Hi,

Can you tell me what is the easiest way to show the latest viewed products list now ?

Thanks a lot.

make-online-shop's picture
Offline
Joined: 01/01/2011
Juice: 216
Re: Re: Recently viewed products list?

No update ? I'm still looking ! Thanks.