Advertisement
geszn

product-grid-item.liquid

Mar 20th, 2021
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.86 KB | None | 0 0
  1. <!-- /snippets/product-grid-item.liquid -->
  2. {% comment %}
  3.  
  4. This snippet is used to showcase each product during the loop,
  5. 'for product in collection.products' in collection.liquid.
  6.  
  7. A liquid variable (grid_item_width) is set just before the this
  8. snippet is included to change the size of the container.
  9. Once the variable is set on a page, all future instances of this
  10. snippet will use that width. Overwrite the variable to adjust this.
  11.  
  12. Example
  13. - assign grid_item_width = 'large--one-quarter medium--one-half'
  14.  
  15. {% endcomment %}
  16.  
  17. {% unless grid_item_width %}
  18. {% assign grid_item_width = 'large--one-third medium--one-half' %}
  19. {% endunless %}
  20.  
  21. {% unless width %}
  22. {%- assign width = 310 -%}
  23. {% endunless %}
  24. {% unless height %}
  25. {%- assign height = 415 -%}
  26. {% endunless %}
  27.  
  28. {% assign on_sale = false %}
  29. {% if product.compare_at_price > product.price %}
  30. {% assign on_sale = true %}
  31. {% endif %}
  32.  
  33. {% assign sold_out = true %}
  34. {% if product.available %}
  35. {% assign sold_out = false %}
  36. {% endif %}
  37.  
  38. {%- assign variant = product.selected_or_first_available_variant -%}
  39.  
  40. {% capture img_id_class %}ProductImage-{{ product.featured_media.id }}{% endcapture %}
  41. {% capture img_wrapper_id %}ProductImageWrapper-{{ product.featured_media.id }}{% endcapture %}
  42. {%- assign featured_image = product.featured_media.preview_image %}
  43. {%- assign img_url = featured_image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' -%}
  44.  
  45. <div class="grid__item grid-product {{ grid_item_width }}{% if sold_out %} is-sold-out{% endif %} {% if forloop.last %}desktop-hide{% endif %}">
  46. <div class="grid-product__wrapper">
  47. <div class="grid-product__image-wrapper">
  48. <a class="grid-product__image-link{% unless featured_image.src == blank %} grid-product__image-link--loading{% endunless %}" href="{{ product.url | within: collection }}" data-image-link>
  49. {% if featured_image.src == blank %}
  50. <img class="grid-product__image" src="{{ featured_image.src | img_url: '1024x' }}" alt="{{ featured_image.alt | escape }}">
  51. {% else %}
  52. {% include 'image-style' with image: featured_image, small_style: true, width: width, height: height, wrapper_id: img_wrapper_id, img_id_class: img_id_class %}
  53. <div id="{{ img_wrapper_id }}" class="product--wrapper">
  54. <div style="padding-top:{{ 1 | divided_by: featured_image.aspect_ratio | times: 100 }}%;">
  55. <img class="product--image {{ img_id_class }}"
  56. data-src="{{ img_url }}"
  57. data-widths="[180, 370, 590, 740, 900, 1080, 1296, 1512, 1728, 2048]"
  58. data-aspectratio="{{ featured_image.aspect_ratio }}"
  59. data-sizes="auto"
  60. alt="{{ featured_image.alt | escape }}"
  61. data-image>
  62. </div>
  63. </div>
  64. <noscript>
  65. <img class="grid-product__image" src="{{ featured_image.src | img_url: '1024x' }}" alt="{{ featured_image.alt | escape }}">
  66. </noscript>
  67. {% endif %}
  68. </a>
  69. {% if sold_out %}
  70. <div class="grid-product__sold-out">
  71. <p>{{ 'products.product.sold_out_html' | t }}</p>
  72. </div>
  73. {% elsif on_sale %}
  74. <div class="grid-product__on-sale">
  75. {% capture saved_amount %}{{ product.compare_at_price | minus: product.price | money_without_trailing_zeros }}{% endcapture %}
  76. <p>{{ 'products.general.save_html' | t: saved_amount: saved_amount }}</p>
  77. </div>
  78. {% endif %}
  79. </div>
  80.  
  81. <a href="{{ product.url | within: collection }}" class="grid-product__meta">
  82. <span class="grid-product__title">{{ product.title }}</span>
  83. {% comment %}Start automatically added Judge.me widget{% endcomment %}
  84. {% render 'judgeme_widgets', widget_type: 'judgeme_preview_badge', concierge_install: true, product: product %}
  85. {% comment %}End automatically added Judge.me widget{% endcomment %}
  86.  
  87. <span class="grid-product__price-wrap">
  88. <span class="long-dash">—</span>
  89. <span class="grid-product__price">
  90. {% if on_sale %}
  91. <span class="visually-hidden">{{ 'products.general.sale_price' | t }}</span>
  92. {% else %}
  93. <span class="visually-hidden">{{ 'products.general.regular_price' | t }}</span>
  94. {% endif %}
  95. {% if product.price_varies %}
  96. {{ product.price_min | money_without_trailing_zeros }}
  97. <span class="icon-fallback-text">
  98. <span class="icon icon-plus grid-product__price-min" aria-hidden="true"></span>
  99. <span class="fallback-text">+</span>
  100. </span>
  101. {% else %}
  102. {{ product.price | money_without_trailing_zeros }}
  103. {% endif %}
  104. </span>
  105.  
  106. {%- if product.price_varies == false and variant.unit_price_measurement -%}
  107. {%- capture unit_price_separator -%}
  108. <span aria-hidden="true">/</span><span class="visually-hidden">&nbsp;{{ 'general.accessibility.unit_price_separator' | t }}&nbsp;</span>
  109. {%- endcapture -%}
  110.  
  111. {%- capture unit_price_base_unit -%}
  112. <span>
  113. {%- if variant.unit_price_measurement.reference_value != 1 -%}
  114. {{- variant.unit_price_measurement.reference_value -}}
  115. {%- endif -%}
  116. {{ variant.unit_price_measurement.reference_unit }}
  117. </span>
  118. {%- endcapture -%}
  119. <span class="product-unit-price">
  120. <span class="visually-hidden">{{ 'products.general.unit_price' | t }}</span>
  121. <span>{{ variant.unit_price | money }}</span>{{- unit_price_separator -}}{{- unit_price_base_unit -}}
  122. </span>
  123. {%- endif -%}
  124. </span>
  125. {% if section.settings.product_vendor_enable %}
  126. <p class="grid-product__vendor">{{ product.vendor }}</p>
  127. {% endif %}
  128. </a>
  129. </div>
  130. </div>
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement