Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. {% assign heading = 'We Also Recommand' %}
  2.  
  3. <div id="title">{{ heading }}</div>
  4. <ul class="related-products">
  5. {% for prod in collections.all.products %}
  6. {% for item in cart.items %}
  7. {% if item.product.tags contains prod.handle %}
  8. <li class="related-item {{ prod.handle }}" style="display:none">
  9. <h3 class="name">
  10. <a href="{{ prod.url }}" title="{{ prod.title | escape }}">{{ prod.title }}</a>
  11. </h3>
  12. <div class="price">
  13. <a href="{{ prod.url }}" title="{{ prod.title | escape }}">{{ prod.price | money }}</a>
  14. </div>
  15.  
  16. <div class="image">
  17. <a href="{{ prod.url | within: collection }}" title="{{ product.title | escape }}">{{ prod.featured_image | product_img_url: image_size | img_tag }}</a>
  18. </div>
  19. <div class="copy">
  20. {{ prod.description | stip_html | truncatewords: 15 }}
  21. </div>
  22. <div class="more"><a href="{{ prod.url }}" title="{{ prod.title | escape }}">View</a></div>
  23. <div class="clear"></div>
  24. </li>
  25. {% endif %}
  26. {% endfor %}
  27. {% endfor %}
  28.  
  29. <script>
  30.  
  31. var Total_item = $("li.related-item").length, // Total number of raltaed item to choose from
  32. item_toshow = 3, // total items to show in your cart page
  33. array = [], // array with index number of all available items
  34. shuffle = [], // array with shuffled index number
  35. rnd;
  36.  
  37. for (i = 0; i < Total_item; i++) {
  38. array[i] = i;
  39. }
  40.  
  41. for (i = 0; i < Total_item; i++) { // pick numbers
  42. rnd = Math.floor(Math.random() * array.length);
  43. shuffle[i] = array.splice(rnd,1)[0]; // remove the selected number from the array and get it in another variable
  44. }
  45.  
  46. for (i = 0; i < item_toshow; i++){
  47. $("li.related-item").slice(shuffle[i],shuffle[i]+1).show();
  48. }
  49.  
  50.  
  51. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement