Solution using Views

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
Recently viewed products list? By: naturesimple (48 replies) Sun, 04/20/2008 - 15:02