Thought I'd share a solution I found for this. I couldn't find a better way of doing it. Requires the toolkit module
It's now implemented on our site facewest.co.uk. Currently only shows recently viewed products on the homepage, although they can easily go on any page.
It uses a cookie to store the value of the last X number of products viewed. So works when a customer comes back a few days later.
This code needs to go on each PROD page in the Head Tag:
<mvt:comment> Read the Cookie "RecentlyViewed" and Set the variable "RecentlyViewed" to be the value of that cookie
</mvt:comment>
<mvt:item name="toolkit" param="vacreate|cookies|s.http_cookie|;" />
<mvt:foreach iterator="cookie" array="cookies">
<mvt:item name="toolkit" param="gettoken|l.all_settings:cookie,=,1|name" />
<mvt:item name="toolkit" param="gettoken|l.all_settings:cookie,=,2|value" />
<mvt:if expr="g.name EQ 'RecentlyViewed'">
<mvt:item name="toolkit" param="vassign|RecentlyViewed|value" />
</mvt:if>
</mvt:foreach>
<mvt:comment> If the current product code is not part of that list than add it to the front and a comma. And outputs variable RecentlyViewedNew</mvt:comment>
<mvt:item name="toolkit" param="sassign|comma|," />
<mvt:if expr="l.settings:product:code CIN RecentlyViewed">
<mvt:item name="toolkit" param="vassign|RecentlyViewedNew|RecentlyViewed" />
<mvt:else>
<mvt:item name="toolkit" param="vassign|RecentlyViewedNew|l.all_settings:pr oduct:code" />
<mvt:item name="toolkit" param="concat|RecentlyViewedNew|RecentlyViewedNew| comma" />
<mvt:item name="toolkit" param="concat|RecentlyViewedNew|RecentlyViewedNew| RecentlyViewed" />
</mvt:if>
<mvt:comment> Now Trim String to make it contain just the last 4 items viewed</mvt:comment>
<mvt:item name="toolkit" param="sassign|RecentlyViewedTrimmed|" />
<mvt:item name="toolkit" param="vquick|pcount|RecentlyViewedNew" />
<mvt:item name="toolkit" param="sassign|counter|1" />
<mvt:item name="toolkit" param="sassign|one|1" />
<mvt:foreach iterator="quicklist" array="quicklists">
<mvt:if expr="Counter LE '4'">
<mvt:item name="toolkit" param="math_add|counter|counter|one" />
<mvt:item name="toolkit" param="concat|RecentlyViewedTrimmed|RecentlyViewed Trimmed|l.all_settings:quicklist:code" />
<mvt:item name="toolkit" param="concat|RecentlyViewedTrimmed|RecentlyViewed Trimmed|comma" />
<mvt:else>
</mvt:if>
</mvt:foreach>
<mvt:comment> Now set cookie to make it contain just the last 4 items viewed</mvt:comment>
<meta http-equiv="set-cookie" content="RecentlyViewed=&mvte:global:RecentlyViewe dTrimmed;; expires=Sat, 25-Nov-2023 12:00:00 GMT;">
Then on any page you want to show the recently viewed product you use:
<mvt:comment> Shows Recently Viewed Products </mvt:comment>
<mvt:item name="toolkit" param="vacreate|cookies|s.http_cookie|;" />
<mvt:foreach iterator="cookie" array="cookies">
<mvt:item name="toolkit" param="gettoken|l.all_settings:cookie,=,1|name" />
<mvt:item name="toolkit" param="gettoken|l.all_settings:cookie,=,2|value" />
<mvt:if expr="g.name EQ 'RecentlyViewed'">
<mvt:item name="toolkit" param="vassign|RecentlyViewed|value" />
</mvt:if>
</mvt:foreach>
<mvt:if expr="g.RecentlyViewed">
<mvt:item name="toolkit" param="vquick|pcount|RecentlyViewed" />
<mvt:foreach iterator="quicklist" array="quicklists">
Use whatever code here to display your products as per your layouts, this is documented in the toolkit Quick / VQuick function.
</mvt:foreach>
</mvt:if>
Hope that helps someone else.
If any one can see why that's a rubbish solution and there is a better way then please let me know.
Jake
It's now implemented on our site facewest.co.uk. Currently only shows recently viewed products on the homepage, although they can easily go on any page.
It uses a cookie to store the value of the last X number of products viewed. So works when a customer comes back a few days later.
This code needs to go on each PROD page in the Head Tag:
<mvt:comment> Read the Cookie "RecentlyViewed" and Set the variable "RecentlyViewed" to be the value of that cookie
</mvt:comment>
<mvt:item name="toolkit" param="vacreate|cookies|s.http_cookie|;" />
<mvt:foreach iterator="cookie" array="cookies">
<mvt:item name="toolkit" param="gettoken|l.all_settings:cookie,=,1|name" />
<mvt:item name="toolkit" param="gettoken|l.all_settings:cookie,=,2|value" />
<mvt:if expr="g.name EQ 'RecentlyViewed'">
<mvt:item name="toolkit" param="vassign|RecentlyViewed|value" />
</mvt:if>
</mvt:foreach>
<mvt:comment> If the current product code is not part of that list than add it to the front and a comma. And outputs variable RecentlyViewedNew</mvt:comment>
<mvt:item name="toolkit" param="sassign|comma|," />
<mvt:if expr="l.settings:product:code CIN RecentlyViewed">
<mvt:item name="toolkit" param="vassign|RecentlyViewedNew|RecentlyViewed" />
<mvt:else>
<mvt:item name="toolkit" param="vassign|RecentlyViewedNew|l.all_settings:pr oduct:code" />
<mvt:item name="toolkit" param="concat|RecentlyViewedNew|RecentlyViewedNew| comma" />
<mvt:item name="toolkit" param="concat|RecentlyViewedNew|RecentlyViewedNew| RecentlyViewed" />
</mvt:if>
<mvt:comment> Now Trim String to make it contain just the last 4 items viewed</mvt:comment>
<mvt:item name="toolkit" param="sassign|RecentlyViewedTrimmed|" />
<mvt:item name="toolkit" param="vquick|pcount|RecentlyViewedNew" />
<mvt:item name="toolkit" param="sassign|counter|1" />
<mvt:item name="toolkit" param="sassign|one|1" />
<mvt:foreach iterator="quicklist" array="quicklists">
<mvt:if expr="Counter LE '4'">
<mvt:item name="toolkit" param="math_add|counter|counter|one" />
<mvt:item name="toolkit" param="concat|RecentlyViewedTrimmed|RecentlyViewed Trimmed|l.all_settings:quicklist:code" />
<mvt:item name="toolkit" param="concat|RecentlyViewedTrimmed|RecentlyViewed Trimmed|comma" />
<mvt:else>
</mvt:if>
</mvt:foreach>
<mvt:comment> Now set cookie to make it contain just the last 4 items viewed</mvt:comment>
<meta http-equiv="set-cookie" content="RecentlyViewed=&mvte:global:RecentlyViewe dTrimmed;; expires=Sat, 25-Nov-2023 12:00:00 GMT;">
Then on any page you want to show the recently viewed product you use:
<mvt:comment> Shows Recently Viewed Products </mvt:comment>
<mvt:item name="toolkit" param="vacreate|cookies|s.http_cookie|;" />
<mvt:foreach iterator="cookie" array="cookies">
<mvt:item name="toolkit" param="gettoken|l.all_settings:cookie,=,1|name" />
<mvt:item name="toolkit" param="gettoken|l.all_settings:cookie,=,2|value" />
<mvt:if expr="g.name EQ 'RecentlyViewed'">
<mvt:item name="toolkit" param="vassign|RecentlyViewed|value" />
</mvt:if>
</mvt:foreach>
<mvt:if expr="g.RecentlyViewed">
<mvt:item name="toolkit" param="vquick|pcount|RecentlyViewed" />
<mvt:foreach iterator="quicklist" array="quicklists">
Use whatever code here to display your products as per your layouts, this is documented in the toolkit Quick / VQuick function.
</mvt:foreach>
</mvt:if>
Hope that helps someone else.
If any one can see why that's a rubbish solution and there is a better way then please let me know.
Jake
Comment