Advertisement
Guest User

Untitled

a guest
Jul 11th, 2021
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. {% comment %}
  2. Source: https://gist.github.com/carolineschnapp/9122054
  3. If you are not on a collection page, do define which collection to use in the order form.
  4. Use the following assign statement, replace 'your-collection-handle-here' with your collection handle.
  5. {% assign collection = collections.related %}
  6. Use the assign statement outside of this comment block at the top of your template.
  7. {% endcomment %}
  8.  
  9. {% paginate collection.products by 100 %}
  10.  
  11. <form action="/cart" method="post">
  12.  
  13. {% if collection.products_count > 0 %}
  14. <div>
  15. <h1>{% if template contains 'page' %}{{ page.title }}{% else %}{{ collection.title }}{% endif %}</h1>
  16. <input type="submit" value="Add to the cart" />
  17. </div>
  18. {% else %}
  19. <h1>{% if template contains 'page' %}{{ page.title }}{% else %}{{ collection.title }}{% endif %}</h1>
  20. {% endif %}
  21.  
  22. {% if template contains 'page' and page.content.size > 0 %}
  23. <div class="rte">
  24. {{ page.content }}
  25. </div>
  26. {% elsif collection.description.size > 0 %}
  27. <div class="rte">
  28. {{ collection.description }}
  29. </div>
  30. {% endif %}
  31.  
  32. {% if collection.products_count > 0 %}
  33.  
  34. <table>
  35. <tbody>
  36. {% for product in collection.products %}
  37. {% if product.available %}
  38. {% for variant in product.variants %}
  39. {% if variant.available %}
  40. <tr class="{% cycle 'pure-table-odd', '' %}">
  41. <td>
  42. <a href="{{ variant.url | collection }}">
  43. <img src="{{ variant.image | default: product.featured_image | img_url: 'small' }}" alt="{{ variant.title | escape }}" />
  44. </a>
  45. </td>
  46. <td>
  47. <a href="{{ variant.url | collection }}">
  48. {{ product.title }}{% unless variant.title contains 'Default' %} - {{ variant.title }}{% endunless %}{% unless variant.sku == blank %} - {{ variant.sku }}{% endunless %}
  49. </a>
  50. </td>
  51. <td>
  52. {{ variant.price | money }}
  53. </td>
  54. <td style="text-align:right;">
  55. <input name="updates[{{ variant.id }}]" onfocus="this.select()" class="quantity field" min="0" {% unless variant.inventory_management == blank or variant.inventory_policy == 'continue' %} max="{{ variant.inventory_quantity }}" {% endunless %} type="text" value="0" tabindex="1" />
  56. </td>
  57. </tr>
  58. {% endif %}
  59. {% endfor %}
  60. {% endif %}
  61. {% endfor %}
  62. </tbody>
  63. </table>
  64.  
  65. <div>
  66. <input type="submit" value="Add to the cart" />
  67. </div>
  68.  
  69. {% else %}
  70. <p>There are no products in this view.</p>
  71. {% endif %}
  72.  
  73. </form>
  74.  
  75. {% endpaginate %}
  76.  
  77. {% if collection.products_count > 0 %}
  78. <script>
  79. jQuery(function($) {
  80. $('table .quantity:first').focus();
  81. $('[max]').change(function() {
  82. var max = parseInt($(this).attr('max'), 10);
  83. var value = parseInt($(this).val(), 10) || 0;
  84. if (value > max) {
  85. alert('We only have ' + max + ' of this item in stock');
  86. $(this).val(max);
  87. }
  88. });
  89. });
  90. </script>
  91. {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement