X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Recently Viewed Mod (https://forum.x-cart.com/showthread.php?t=36753)

MoonDog 01-14-2008 09:59 PM

Recently Viewed Mod
 
2 Attachment(s)
Here is a mod that will display up to four recently view products with icons and price that the customer has looked at. It doesn't use the db or php. It's strictly javascript and cookies. The default cookie is set to expire in 30 days, so that whenever the customer returns to your site within the 30 days, it will still show the four last viewed items that the customer has looked at. The time of expiry can be set for any amount of time, days or years.
I can't take full credit for this mod, since a lot of this code was grabbed from the internet. Unfortunately, I don't remember where I got these different codes, but thanks to those who created them. All I did was piece these codes together so that this will work in x-cart. I've tried this code for v4.1.8 and v4.1.9 and it seems to work O.K.

There's still a lot of room for improvement, so please feel free to add and contribute to this mod.

In customer/home.tpl add the following code between the <head> and </head> tags:
Code:


{literal}
<script type="text/javascript">
 function setCookie(name, value) {
 var today = new Date()
 var expires = new Date()
 expires.setTime(today.getTime() + 1000*60*60*24*30)
 document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +";path=/"
}
 function getCookie(Name) {
 var search = Name + "="
 if(document.cookie.length > 0) {
 offset = document.cookie.indexOf(search)
 if(offset != -1) {
 offset += search.length
 end = document.cookie.indexOf(";", offset)
 if(end == -1) end = document.cookie.length
 return unescape(document.cookie.substring(offset, end))}
 else return ""
 }
}
</script>
{/literal}

Now add these two lines of code in home.tpl wherever you want the Recently Viewed box to display(NOTE: this mod will not display recently viewed items when the menu box is on left side but only on the right side of your webpage or at the bottom(see Qdox post #36)).
If you want to use this mod on the left side just continue with the instructions and then go to post #42 to add the other code needed to make this work on the left column.
Code:


<br />
{include file="customer/main/recently_viewed.tpl"}

For instance: if you want to display the Recently Viewed box after the the news box, then find the {include file="news.tpl"} code and place the above code below it. Just make sure that this menu box is displayed on the right side of your webpage.

Add the following code to the end of your customer/main/product.tpl file:
Code:


<script type="text/javascript">
prodImage='<img src="{$product.tmbn_url}"/>';
prodName='<{$product.product}>';
var p0=('<br/><a href="'+document.URL+'">'+prodImage+'<br/>{$product.product}</a><br/>${$product.taxed_price}<br/>');
</script>

Create a customer/main/recently_viewed.tpl file by using the following code:
Code:


{capture name=menu}
<div class="recently">
{literal}
 <script type="text/javascript">
  if (p0){
  }
  else {var p0=null;
  }
  var p1=getCookie("p1");
  var p2=getCookie("p2");
  var p3=getCookie("p3");
  var p4=getCookie("p4");
  if (p1){
  }
  else {document.write("You have no recently viewed items.")
  }
  if (p1 !=null) {document.write(p1)}
  if (p2) {document.write(p2)}
  if (p3) {document.write(p3)}
  if (p4) {document.write(p4)}
  if(p0 !=null && p0 != p1 && p0 != p2 && p0 != p3 && p0 !=p4){
  setCookie("p1",p0)
  setCookie("p2",p1)
  setCookie("p3",p2)
  setCookie("p4",p3)
  }
 </script>
{/literal}
</div>
{/capture}
{include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title="Recently Viewed" menu_content=$smarty.capture.menu}

And finally, add the following code to the end of your skin1.css file:
Code:


.recently {text-align:center;}
.recently img {text-decoration:none;width:80px;height:auto;}
.recently a{text-decoration:none;color:black;}

And that should be it.

Update: Added attachment of before a product has been viewed and after viewing 2 products.
Also updated added code from post#7
Updated to inform that menu box will not work when displayed on the left side of the webpage. You will need to add the code that is posted on post #42 to display this mod on the left column.

Note: to set the day for when you want the cookie to expire, find this line of code:
Code:

expires.setTime(today.getTime() + 1000*60*60*24*30)
The number thirty at the end of that line is the number of days until the cookie expires. You can set it to any number of days you want. 7 is one week and 365 is one year.

- MoonDog -

JDam 01-14-2008 10:36 PM

Re: Recently Viewed Mod
 
Great mod MoonDog!

Very simple and easy to install - works great with 4.1.9

Having the ability to make a quick change in product image size in CSS is great - I changed mine from 80 to 70 pixels.

Thanks again! :-)

ProMuscles 01-15-2008 08:21 AM

Re: Recently Viewed Mod
 
Moondog the greatest mod contributor since... well Thanks for your hard work!

mike_turbo 01-17-2008 02:21 AM

Re: Recently Viewed Mod
 
I put this code in but the price was showing in $ my default is in ё.

Also when i added it came up with nullnullnull under the prices ?

Any advise.

Freakmode 01-17-2008 03:41 AM

Re: Recently Viewed Mod
 
mike_turbo

The $ comes from this entry in

customer/main/product.tpl file:

This line after the break.

var p0=('<br/><a href="'+document.URL+'">'+prodImage+'<br/>{$product.product}</a><br/>${$product.taxed_price}<br/>');

MoonDog 01-17-2008 06:57 PM

Re: Recently Viewed Mod
 
Hi mike_turbo,

Quote:


I put this code in but the price was showing in $ my default is in ё.
Also when i added it came up with nullnullnull under the prices ?
Any advise.

Try this; repace the code you added in product.tpl with the following code:

Code:


<script type="text/javascript">
prodImage='<img src="{$product.tmbn_url}"/>';
prodName='<{$product.product}>';
var p0=('<br/><a href="'+document.URL+'">'+prodImage+'<br/>{$product.product}</a><br/>ё{$product.price}<br/>');
</script>

It's almost exactly like the code in post #1 except for the code highlited in red.

Let me know if this works for you.


- MoonDog -

MoonDog 01-17-2008 11:37 PM

Re: Recently Viewed Mod
 
Instead of showing an empty Recentlly Viewed box on the homepage before the customer has viewed any products; you can add the following code to your recently_viewed.tpl file:

find:
Code:


  var p1=getCookie("p1");
  var p2=getCookie("p2");
  var p3=getCookie("p3");
  var p4=getCookie("p4");

and after the above line of code, add the following lines of code:
Code:


  if (p1){
  }
  else {document.write("You have no recently viewed items.")
  }

And that should take care of that.

Update: Post #1 has been updated to reflect this change

- MoonDog -

RichieRich 01-19-2008 08:23 AM

Re: Recently Viewed Mod
 
is there a demo or anyone like to share how they implemented?

Freakmode 01-19-2008 08:37 AM

Re: Recently Viewed Mod
 
We use it its great

http://www.jobananas.com

Thanks MoonDog

MoonDog 01-19-2008 11:58 PM

Re: Recently Viewed Mod
 
Great job 01bodyjewellery. I like the way it looks on your site.

I've updated post #1 for those of you who want to adjust the expiry date from 30 days to any number of days you want. At 30 days, the customer will see the last 4 recently viewed items everytime they log on to your site for the next 30 days. After that, the cookie gets reset again for 30 days. You can change this from a millisecond to any number of years.

- MoonDog -

Freakmode 01-20-2008 12:12 AM

Re: Recently Viewed Mod
 
No thank you MoonDog

When I get 10 minutes I need to look at the pricing line so that the currency $ changes when you select £GBP, Euro, Dollar or AUS

Its not a big task just need a few minutes spare.

With you being a programmer type would you be able to fix this one?

http://forum.x-cart.com/showthread.php?t=7748

RichieRich 01-21-2008 05:56 AM

Re: Recently Viewed Mod
 
suggestion: there should be an option to clear the recently viewed with a javascript link at the bottom

sales@webosusa.com 01-21-2008 07:05 AM

Re: Recently Viewed Mod
 
Two things.

Fist: Does not seen to work on my website. Take a look on www.webosbr.com
Second: I add two labels for multi-lenguage website "lbl_no_recently_viewed_items" and "lbl_recently_viewed". The "lbl_recently_viewed" i put this line
Code:

{include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_recently_viewed menu_content=$smarty.capture.menu}
and works fine but i cannot make work for the "lbl_no_recently_viewed_items". Maybe i am doing something wrong. Any ideas?

Thanks!

ProMuscles 01-21-2008 08:18 AM

Re: Recently Viewed Mod
 
[quote=sales@webosusa.com]

well it is other things going on with your site. price match link give no access error. And the tab More on product.tpl gives a funky layout.

rick2003 01-21-2008 09:02 AM

Re: Recently Viewed Mod
 
I try to have the recently viewed product in my product.tpl,

http://www.lywoo.com/product.php?productid=61&cat=4&page=

however, it didn't work at all, I follow every steps. Could anyone help me do it.



rick2003 01-21-2008 10:40 AM

Recent viewed product
 
Hi, Every one,

I have recently implemented the "recently viwed item" mod,

http://forum.x-cart.com/showthread.php?t=36753

However, i want to display the product in the product detail page,

therefore, i have the code placed undet product.tpl, It works,

Howevre, how do i change the layout to be "horizontal display",

Now all viewed is listed vertically,

please see http://www.lywoo.com/product.php?productid=30&cat=12&page=

Recently View is in the bottom.

Please someone help.

balinor 01-21-2008 10:42 AM

Re: Recently Viewed Mod
 
No need for a new thread on the topic Rick, I've moved this to the thread that actually discusses the mod.

PremiumPonyParts 01-21-2008 12:21 PM

Re: Recently Viewed Mod
 
Ive so far implemented the mod and beleive I have set it up correctly but it seems as though no cookie is being made. Any thoughts to this?

congiothoang 01-22-2008 02:37 PM

Re: Recently Viewed Mod
 
Great Mod. Thanks for sharing!

Unfortunately, I can't use it since I have XC SEO installed on my site and it seem not working with this XC SEO mods together.

Any advices everyone ???

Freakmode 01-22-2008 10:34 PM

Re: Recently Viewed Mod
 
Not sure about an issue with XC SEO - we use CDSEO and it works fine

sales@webosusa.com 01-23-2008 03:22 PM

Re: Recently Viewed Mod
 
I manage put together. This is for who use tables as well.

The code below
Code:

==================================================
<script type="text/javascript">
 prodImage='<img src="{$product.tmbn_url}"/>';
 prodName='<{$product.product}>';
 var p0=('<br/><a href="'+document.URL+'">'+prodImage+'<br/>{$product.product}</a><br/>${$product.taxed_price}<br/>');
 </script>
==================================================

But before right after the last DIV tag before the {/if} that you made for the tables like below
Code:

==================================================
....
 
 <div class="tabber" id="mytabber">
 {if $active_modules.Magnifier ne "" && ($config.Magnifier.magnifier_image_popup ne 'Y' || $js_enabled ne 'Y')}
 <div class="tabbertab">
 <h2>Product Magnifier</h2>
 {include file="modules/Magnifier/product_magnifier.tpl" productid=$product.productid}
 </div>
 {/if}
 {if $config.Appearance.send_to_friend_enabled eq 'Y'}
 <div class="tabbertab">
 <h2>{$lng.lbl_send_to_friend}</h2>
 {include file="customer/main/send_to_friend.tpl" }
 </div>
 {/if}
 {if $active_modules.Detailed_Product_Images ne "" && ($config.Detailed_Product_Images.det_image_popup ne 'Y' || $js_enabled ne 'Y')}
 <div class="tabbertab">
 <h2>{$lng.lbl_detailed_images}</h2>
 {include file="modules/Detailed_Product_Images/product_images.tpl" }</div>
 {/if}
 
 <div class="tabbertab" id="description">
 <h2>{$lng.lbl_full_description}</h2>
 {include file="customer/main/full_description.tpl"}</div>
 
 <div class="tabbertab">
 <h2>{$lng.lbl_more_tabs}</h2>
 <div class="tabber" id="mytabber">
 {if $active_modules.Recommended_Products ne ""}
 <div class="tabbertab tabbertabdefault">
 <h2>{$lng.module_name_Recommended_Products}</h2>
 {include file="modules/Recommended_Products/recommends.tpl" }</div>
 {/if}
 {if $active_modules.Customer_Reviews ne ""}
 <div class="tabbertab tabbertabdefault">
 <h2>{$lng.lbl_customer_reviews}</h2>
 {include file="modules/Customer_Reviews/vote_reviews.tpl" }</div>
 {/if}
 <div class="tabbertab">
 <h2>{$lng.lbl_more_tabs}</h2>
 <div class="tabber" id="mytabber">
 
 {if $active_modules.Upselling_Products ne ""}
 <div class="tabbertab">
 <h2>{$lng.lbl_related_products}</h2>
 {include file="modules/Upselling_Products/related_products.tpl" }{include file="customer/pricematch.tpl"}</div>
 
 {/if}</div></div></div>
  </div>
 
  <script type="text/javascript">
 prodImage='<img src="{$product.tmbn_url}"/>';
 prodName='<{$product.product}>';
 var p0=('<br/><a href="'+document.URL+'">'+prodImage+'<br/>{$product.product}</a><br/>${$product.taxed_price}<br/>');
 </script>

{/if}
 
 {if $active_modules.Product_Options ne '' && $product_options ne '' && ($product.product_type ne "C" || !$active_modules.Product_Configurator)}
 <script type="text/javascript" language="JavaScript 1.2">
 <!--
 check_options();
 -->
 </script>
 
 {/if}

==================================================


Thanks for this MOD. Greats! Cya!

Warwick 01-23-2008 03:52 PM

Re: Recently Viewed Mod
 
Is this working with 4.1.3? I tried it but can't get it to show any recent products ... any ideas?

And is it possible to get the "You have no recently viewed items." multi language as well, I tried to put {$lng.lbl_my_text} in the javascript but I'm sure that's not working.

sales@webosusa.com 01-23-2008 04:32 PM

Re: Recently Viewed Mod
 
Try without the " " symbol.

Code:

  else {document.write({$lng.lbl_my_text})
or like this
Code:


  else {document.write($lng.lbl_my_text)


I cannot try anymore because always show my latest viewed and i had the idea after.

How can i "kill" the last views? so i can tast this?

Cya!

sales@webosusa.com 01-23-2008 05:57 PM

Re: Recently Viewed Mod
 
Question? On Internet Explorer 7 over does not show the Recently Viewed Products

Any ideas?


Cya!

Warwick 01-23-2008 10:06 PM

Re: Recently Viewed Mod
 
Quote:

Originally Posted by sales@webosusa.com
Try without the " " symbol.

Code:

  else {document.write({$lng.lbl_my_text})
or like this
Code:


  else {document.write($lng.lbl_my_text)




Thanks, did try that but both don't work, probably while it is in a javascript piece of code?

MoonDog 01-23-2008 10:14 PM

Re: Recently Viewed Mod
 
Warwick & sales@webosusa.com

Quote:

And is it possible to get the "You have no recently viewed items." multi language as well, I tried to put {$lng.lbl_my_text} in the javascript but I'm sure that's not working.
Try this:

Place the following code in your skin1/customer/home.tpl file between the <head> and </head> tags:
Code:


<script type="text/javascript">
var myText="{$lng.lbl_my_text}";
</script>

Of course instead of {$lng.lbl_my_text}, you need to create your own language variable in the admin side.


Then open skin1/customer/main/recently_viewed.tpl and edit the following line:

From this...
Code:

  else {document.write("You have no recently viewed items.")
To this:
Code:

  else {document.write(myText)

- MoonDog -

MoonDog 01-23-2008 10:45 PM

Re: Recently Viewed Mod
 
For those of you who are unable to see your recently viewed items, make sure that you have enabled your cookie settings in your browser.

In Firefox it's located in the top menu bar Tools>Options...>Privacy tab and just enable 'Accept cookies from sites' and then select one of the three selections in the dropdown box.

In Internet Explorer it's at the top menu bar Tools>Internet Options...>Privacy tab and then just adjust the slider to medium.

--------------------------------------------------

For those who want to clear their recently viewed items, just delete the cookies from your browser.

In Internet Explorer go to the top menu bar Tools>Internet Options> and click on the 'Delete Cookies' button. You might have to close your browser and re-open it.

In Firefox go to the top menu bar Tools>Options>Privacy tab and then select from the downdown box by 'Keep until:' to 'I close Firefox'. Then close your browser and re-open it.

Hope this helps.

- MoonDog -

Warwick 01-23-2008 10:48 PM

Re: Recently Viewed Mod
 
Thanks MoonDog, it isn't working yet but I'm getting there I feel.

Now it literally shows:
{$lng.lbl_my_text}

I tried removing the " around them but no good.

p.s. I have my cookies enabled but no recent products appear :(

MoonDog 01-24-2008 06:53 PM

Re: Recently Viewed Mod
 
Warwick,
Quote:

Now it literally shows:
{$lng.lbl_my_text}

The most likely cause for this problem is that you have the javascript code enclosed in {literal} and {/literal} tags. Make sure that you are not enclosing it with these tags.

The same goes for the javascript code in the product.tpl file. Don't use the literal tags for the javascript code you placed there. You will not receive any javascript errors by not using them.

You will need the {literal} and {/literal} tags for the other javascript code as was posted in post #1.

Good luck.

- MoonDog -

Warwick 01-24-2008 10:54 PM

Re: Recently Viewed Mod
 
That did it, thanks! :)

Now only if it would show recently viewed products, javascript is enabled, have to investigate some more :(

Warwick 01-24-2008 11:05 PM

Re: Recently Viewed Mod
 
You have otherwise any idea why it wouldn't show recently viewed products?

Warwick 01-24-2008 11:24 PM

Re: Recently Viewed Mod
 
Could it be related to the fact that I use DSEFU PRO?

MoonDog 01-25-2008 12:21 AM

Re: Recently Viewed Mod
 
Warwick,
Quote:


You have otherwise any idea why it wouldn't show recently viewed products?

This mod works like this:
First of all, click on a product and view the product details.

Then select another product and then view the product details for this product.

Now look to see if you have an thumbnail, product title and product price displayed in your recently view box. If everything works it should display the first viewed product.

If nothing shows up, then make sure that you have cookies enabled in your browser. See post #27 how to turn it on.

Repeat the first two steps by reviewing two product details and see if there is anything now in the recently viewed box. If not, then most likely it's the code in your product.tpl file.

Make sure that you have used the product.tpl file and not the products.tpl file. The second file has the letter s after product.

Re-install the javascript code from post #1 to the very end of the product.tpl file. Make sure that there are no {literal} and {/literal} tags surrounding this code.

Now repeat the first two steps again to see if this works on the recently viewed box.

Hope this works.

Quote:


Could it be related to the fact that I use DSEFU PRO?

Since I don't use DSEFU PRO, I'm not sure if this is affecting this mod or not.
I do know that 01bodyjewellery from post #20 is using CDSEO and I think it's similar and it's not affecting his site.
Or maybe someone that uses DSEFU PRO and installed this mod can let us know if they have it working together.

Good luck.

- MoonDog -

Warwick 01-25-2008 12:41 AM

Re: Recently Viewed Mod
 
Thanks for all your help and efforts, I tried all more than once but simply can't get it to show any recently viewed products. Seems I have to pass this mod :(

sales@webosusa.com 01-25-2008 10:29 AM

Re: Recently Viewed Mod
 
Works great now. Thanks!.

Cya!

Qdox 01-25-2008 02:58 PM

Re: Recently Viewed Mod
 
Nice addition to my collection of mods, Good Work.
For those interested to have it horizontally use this:

1- Add to skin1.css
Quote:


/* Recently Viewed Items */
.recently {text-align:center;background-color:transparent}
.recently img {text-decoration:none;width:80px;height:auto;}
.recently a{text-decoration:none;color:black;}
.box1{float:left;width:25%}
.box2{float:left;width:25%}
.box3{float:left;width:24%}


2- Create the recently_viewed.tpl with this:
Quote:

{capture name=menu}
<div class="recently">
{literal}
<script type="text/javascript">
if (p0){
}
else {var p0=null;
}
var p1=getCookie2("p1");
var p2=getCookie2("p2");
var p3=getCookie2("p3");
var p4=getCookie2("p4");
if (p1){
}
else {document.write("You have no recently viewed items.")
}
if (p1 !=null) {document.write('<div class="box1">'+p1+'</div>')}
if (p2) {document.write('<div class="box2">'+p2+'</div>')}
if (p3) {document.write('<div class="box2">'+p3+'</div>')}
if (p4) {document.write('<div class="box3">'+p4+'</div>')}
if(p0 !=null && p0 != p1 && p0 != p2 && p0 != p3 && p0 !=p4){
setCookie2("p1",p0);
setCookie2("p2",p1);
setCookie2("p3",p2);
setCookie2("p4",p3);
}
</script>
{/literal}
</div>
{/capture}
{include file="dialog.tpl" dingbats="dingbats_categorie.gif" title="Recently Viewed" content=$smarty.capture.menu extra='width="100%"'}



Please note that I used the dialog.tpl instead of the menu.tpl. If you need to use the menu.tpl copy the code from the post#1.
Another I put my javascript functions on common.js, so I had to rename them.

congiothoang 01-26-2008 08:58 AM

Re: Recently Viewed Mod
 
First, I want to say this is a great mod. Unfortunately, I can't get it to work. I thought becuase of XC SEO but when I disable XC SEO, it still not working (Plus, somebody else using the CD SEO and it works fine)

One more thing, I try to view source code of the product page and notice that there is no javascript display (notice that I did check to make sure that I place the code in correct file which is product.tpl )

THis piece of code did not display in the view source code:
{******************* Recently View Mods *********************}
<script type="text/javascript">
prodImage='<img src="{$product.tmbn_url}"/>';
prodName='<{$product.product}>';
var p0=('<br/><a href="'+document.URL+'">'+prodImage+'<br/>{$product.product}</a><br/>${$product.taxed_price}<br/>');
</script>
{******************* END Recently View Mods *********************}


If you guys can help me out, here is the link to my site:

http://www.loyalgifts.com


Thanks a lot for your help guys!

Warwick 01-26-2008 09:03 AM

Re: Recently Viewed Mod
 
Quote:

First, I want to say this is a great mod. Unfortunately, I can't get it to work. I thought becuase of XC SEO but when I disable XC SEO, it still not working (Plus, somebody else using the CD SEO and it works fine)
Similarity to me (also having trouble getting it to work) is that you have X-Cart Pro as well, maybe that is causing trouble, a long shot but who knows?

MoonDog 01-26-2008 07:30 PM

Re: Recently Viewed Mod
 
congiothoang and Warwick,

I think I found the problem that might be causing anything to display on the Recently View menu box. I was viewing congiothoang's source code to see what might be causing the problem and I noticed that the include recently_viewed file is called before the product.tpl is called. The product.tpl has the javascript code that is required for the recently_viewed to display the recently viewed product. Therefore, nothing is showing up.

So in order for the Recently Viewed mod to work, the menu box has to be located on the right side or at the bottom of the product page like in Qdox post #36. This mod will not work if it's located on the left side with the other menu boxes.

My sincere apology for those who had problems when installing this mod on the left side of their webpage. :oops: Try it on the right side or on the bottom and it should work.

I'll update post #1 to reflect this change.

On another note, I installed XC SEO and it's working perfectly with this mod.

I hope this fixes your problems.


- MoonDog -

pegpub 01-27-2008 09:58 AM

Re: Recently Viewed Mod
 
Moondog,

Any chance of modifying this so it will work in the left column? I have a 2 column layout and would love to have this feature.


All times are GMT -8. The time now is 03:16 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.