Guest User

Untitled

a guest
Mar 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. {% comment %}
  2. Set the extension of your color files below. Use 'png', 'jpeg', 'jpg' or 'gif'.
  3. {% endcomment %}
  4.  
  5. {% assign file_extension = 'png' %}
  6.  
  7. {% if swatch == blank %}
  8. <div class="swatch error">
  9. <p>You must include the snippet swatch.liquid with the name of a product option.</p>
  10. <p>Use: <code>{% raw %}{% include 'swatch' with 'name of your product option here' %}{% endraw %}</code></p>
  11. <p>Example: <code>{% raw %}{% include 'swatch' with 'Color' %}{% endraw %}</code></p>
  12. </div>
  13. {% else %}
  14.  
  15. {% assign found_option = false %}
  16. {% assign is_color = false %}
  17. {% assign option_index = 0 %}
  18.  
  19. {% for option in product.options %}
  20. {% if option == swatch %}
  21. {% assign found_option = true %}
  22. {% assign option_index = forloop.index0 %}
  23. <style>
  24. label[for="product-select-option-{{ option_index }}"] { display: none; }
  25. #product-select-option-{{ option_index }} { display: none; }
  26. #product-select-option-{{ option_index }} + .custom-style-select-box { display: none !important; }
  27. </style>
  28. <script>$(window).load(function() { $('.selector-wrapper:eq({{ option_index }})').hide(); });</script>
  29. {% assign downcased_option = swatch | downcase %}
  30. {% if downcased_option contains 'color' or downcased_option contains 'colour' %}
  31. {% assign is_color = true %}
  32. {% endif %}
  33. {% endif %}
  34. {% endfor %}
  35.  
  36. {% unless found_option %}
  37. <div class="swatch error">
  38. <p>You included the snippet swatch.liquid with the name of a product option — <code>'{{ swatch }}'</code> — that does not belong to your product.</p>
  39. <p>Use <code>{% raw %}{% include 'swatch' with 'name of your product option here' %}{% endraw %}</code></p>
  40. <p>Example: <code>{% raw %}{% include 'swatch' with 'Color' %}{% endraw %}</code></p>
  41. <p><strong>This is case-sensitive!</strong> Do not put in <code>'color'</code> if your product option name is <code>'Color'</code>.</p>
  42. </div>
  43. {% else %}
  44. <div class="swatch clearfix" data-option-index="{{ option_index }}">
  45. <div class="header">{{ swatch }}</div>
  46. {% assign values = '' %}
  47. {% for variant in product.variants %}
  48. {% assign value = variant.options[option_index] %}
  49. {% unless values contains value %}
  50. {% assign values = values | join: ',' %}
  51. {% assign values = values | append: ',' | append: value %}
  52. {% assign values = values | split: ',' %}
  53. <div data-value="{{ value | escape }}" class="swatch-element {% if is_color %}color {% endif %}{{ value | handle }} {% if variant.available %}available{% else %}soldout{% endif %}">
  54. {% if is_color %}
  55. <div class="tooltip">{{ value }}</div>
  56. {% endif %}
  57. <input id="swatch-{{ option_index }}-{{ value | handle }}" type="radio" name="option-{{ option_index }}" value="{{ value | escape }}"{% if forloop.first %} checked{% endif %} {% unless variant.available %}disabled{% endunless %} />
  58. {% if is_color %}
  59. <label for="swatch-{{ option_index }}-{{ value | handle }}" style="background-color: {{ value | split: ' ' | last | handle }}; background-image: url({{ value | handle | append: '.' | append: file_extension | asset_url }})">
  60. <img class="crossed-out" src="{{ 'soldout.png' | asset_url }}" />
  61. </label>
  62. {% else %}
  63. <label for="swatch-{{ option_index }}-{{ value | handle }}">
  64. {{ value }}
  65. <img class="crossed-out" src="{{ 'soldout.png' | asset_url }}" />
  66. </label>
  67. {% endif %}
  68. </div>
  69. {% endunless %}
  70. {% if variant.available %}
  71. <script>
  72. jQuery('.swatch[data-option-index="{{ option_index }}"] .{{ value | handle }}').removeClass('soldout').addClass('available').find(':radio').removeAttr('disabled');
  73. </script>
  74. {% endif %}
  75. {% endfor %}
  76. </div>
  77.  
  78. {% endunless %}
  79.  
  80. {% endif %}
Add Comment
Please, Sign In to add comment