Advertisement
Guest User

afterpay snipit

a guest
Jun 19th, 2018
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.22 KB | None | 0 0
  1. {% comment %}
  2.  
  3. Rich snippets (itemscope, itemtype, etc.) for products are a theme requirement,
  4. and allow search engines to easily understand what the content is.
  5.  
  6. For more information on these Scheme.org tags, visit:
  7. - http://schema.org/docs/gs.html
  8.  
  9. {% endcomment %}
  10.  
  11. {% comment %}
  12. Check if the product is sold out and set a variable to be used below.
  13. {% endcomment %}
  14. {% assign sold_out = true %}
  15. {% if product.available %}
  16. {% assign sold_out = false %}
  17. {% endif %}
  18.  
  19. <div itemscope itemtype="http://schema.org/Product" id="ProductSection" data-section-id="{{ section.id }}" data-section-type="product-template" data-zoom-enable="{{ section.settings.product_image_zoom_enable }}" data-enable-history-state="true">
  20.  
  21. <div class="product-single__header text-center">
  22. <meta itemprop="url" content="{{ shop.url }}{{ product.url }}">
  23. <meta itemprop="image" content="{{ product.featured_image.src | img_url: 'grande' }}">
  24.  
  25. {% if collection.handle %}
  26. <a href="{{ collection.url }}" class="collection-title text-center" item-prop="collection">{{ collection.title }}</a>
  27. {% endif %}
  28.  
  29. <h1 itemprop="name" class="product-single__title{% if section.settings.product_vendor_enable %} wvendor{% endif %}">{{ product.title }}</h1>
  30. {% if section.settings.product_vendor_enable %}
  31. <p class="product-single__vendor">{{ product.vendor | link_to_vendor }}</p>
  32. {% endif %}
  33. <hr class="hr--small">
  34.  
  35. {% comment %}
  36. Optionally show the 'compare at' or original price of the product.
  37. {% endcomment %}
  38.  
  39. <div class="h2 product-single__price">
  40. {% if product.compare_at_price_max > product.price %}
  41. <span class="visuallyhidden compare-price-a11y">{{ 'products.general.sale_price' | t }}</span>
  42. {% else %}
  43. <span class="visuallyhidden price-a11y">{{ 'products.general.regular_price' | t }}</span>
  44. {% endif %}
  45. <span class="product-price" {% if product.compare_at_price > product.price %} class="on-sale"{% endif %}>
  46. {{ product.price | money }}
  47. </span>
  48. {% include 'inventory-table' %}
  49.  
  50. <!-- Begin Afterpay Liquid Snippet for Shopify v2.2.0 -->
  51. {% assign afterpay_minimum_value_in_cents = 4 %}
  52. {% assign afterpay_maximum_value_in_cents = 100000 %}
  53. {% assign afterpay_logo_theme = 'colour' %}
  54. {% assign afterpay_count_eligible_variants = 0 %}
  55. {% assign afterpay_supported_currencies = 'AUD, NZD' | split: ', ' %}
  56. {% if afterpay_supported_currencies contains shop.currency %}
  57. {% for afterpay_variant in product.variants %}
  58. {% if afterpay_variant.available and afterpay_variant.price >= afterpay_minimum_value_in_cents and afterpay_variant.price <= afterpay_maximum_value_in_cents %}
  59. {% assign afterpay_count_eligible_variants = afterpay_count_eligible_variants | plus: 1 %}
  60. {% endif %}
  61. {% endfor %}
  62. {% endif %}
  63. <script type="text/javascript">
  64. (
  65. function(i,s,o,g,r,a,m){
  66. i['GoogleAnalyticsObject']=r;
  67. i[r]=i[r]||function(){
  68. (i[r].q=i[r].q||[]).push(arguments);
  69. },i[r].l=1*new Date();
  70. a=s.createElement(o),m=s.getElementsByTagName(o)[0];
  71. a.async=1;
  72. a.src=g;
  73. m.parentNode.insertBefore(a,m);
  74. }
  75. )(window,document,'script','https://www.google-analytics.com/analytics.js','afterpay_ga');
  76. afterpay_ga('create', 'UA-108913162-1', 'auto');
  77. afterpay_ga('send', 'event', 'Liquid Snippet', 'Report Version', '2.2.0');
  78. afterpay_ga('send', 'event', 'Theme', 'Report Name', {{ theme.name | json }});
  79. afterpay_ga('send', 'event', 'Shop', 'Report Currency', {{ shop.currency | json }});
  80. </script>
  81. {% if afterpay_count_eligible_variants > 0 %}
  82. <p class="afterpay-paragraph" style="display:{% if product.selected_or_first_available_variant.available and product.selected_or_first_available_variant.price >= afterpay_minimum_value_in_cents and product.selected_or_first_available_variant.price <= afterpay_maximum_value_in_cents %}block{% else %}none{% endif %};" data-product-id="{{ product.id }}">
  83. or make 4 interest-free payments of
  84. <strong><span class="afterpay-instalments">${{ product.selected_or_first_available_variant.price | divided_by: 4.0 | round | money_without_currency }}&nbsp;{{ shop.currency }}</span></strong>
  85. fortnightly with
  86. <a style="display:inline-block; margin-bottom:10px;" href="https://www.afterpay.com/terms" target="_blank">
  87. <img style="vertical-align:middle;" src="https://static.afterpay.com/integration/product-page/logo-afterpay-{{ afterpay_logo_theme }}.png" srcset="https://static.afterpay.com/integration/product-page/logo-afterpay-{{ afterpay_logo_theme }}.png 1x, https://static.afterpay.com/integration/product-page/logo-afterpay-{{ afterpay_logo_theme }}@2x.png 2x, https://static.afterpay.com/integration/product-page/logo-afterpay-{{ afterpay_logo_theme }}@3x.png 3x" width="100" height="21" alt="Afterpay" />
  88. <span style="font-size:12px;"><u>More info</u></span>
  89. </a>
  90. </p>
  91. {% if product.price_varies or afterpay_count_eligible_variants < product.variants.size %}
  92. <script type="text/javascript">
  93. if (typeof Afterpay === 'undefined') {
  94. var Afterpay = {products:[]};
  95. Afterpay.loadScript = function(url, callback) {
  96. var script = document.createElement('script');
  97. script.type = 'text/javascript';
  98. if (script.readyState) { // I.E.
  99. script.onreadystatechange = function() {
  100. if (script.readyState == 'loaded' || script.readyState == 'complete') {
  101. script.onreadystatechange = null;
  102. callback();
  103. }
  104. };
  105. } else { // Others
  106. script.onload = function() {
  107. callback();
  108. };
  109. }
  110. script.src = url;
  111. document.getElementsByTagName('head')[0].appendChild(script);
  112. };
  113. Afterpay.init = function($) {
  114. $('body').on('change', $('form[action^="/cart/add"]'), function(event) {
  115. var $form = $(event.target).closest('form');
  116. var $afterpay_paragraph = null;
  117. var should_show_instalments = false;
  118. var selected_variant_id = parseInt($('input[name=id]:checked, select[name=id], input[name=id], hidden[name=id]', $form).val(), 10);
  119. if (isNaN(selected_variant_id)) {
  120. var $variant_options = $form.find('input[name=id][value], select[name=id] option[value], hidden[name=id][value]').filter(function(index, element) {
  121. return $(element).attr('value').match(/^[1-9][0-9]*$/);
  122. });
  123. $variant_options.each(function(index, element) {
  124. $.each(Afterpay.products, function(product_index, product) {
  125. $.each(product.variants, function(variant_index, variant) {
  126. if (variant.id == $(element).val()) {
  127. $afterpay_paragraph = $('.afterpay-paragraph[data-product-id=' + product.id + ']');
  128. return false;
  129. }
  130. });
  131. if ($afterpay_paragraph !== null) {
  132. return false;
  133. }
  134. });
  135. if ($afterpay_paragraph !== null) {
  136. return false;
  137. }
  138. });
  139. } else if (selected_variant_id > 0) {
  140. $.each(Afterpay.products, function(product_index, product) {
  141. $.each(product.variants, function(variant_index, variant) {
  142. if (variant.id == selected_variant_id) {
  143. $afterpay_paragraph = $('.afterpay-paragraph[data-product-id=' + product.id + ']');
  144. if (variant.available && variant.price >= {{ afterpay_minimum_value_in_cents }} && variant.price <= {{ afterpay_maximum_value_in_cents }}) {
  145. should_show_instalments = true;
  146. $afterpay_paragraph.find('.afterpay-instalments').html('$' + (Math.round(variant.price / 4) / 100).toFixed(2) + '&nbsp;{{ shop.currency }}');
  147. }
  148. }
  149. });
  150. });
  151. }
  152. if ($afterpay_paragraph !== null) {
  153. if (should_show_instalments) {
  154. $afterpay_paragraph.show();
  155. } else {
  156. $afterpay_paragraph.hide();
  157. }
  158. }
  159. });
  160. };
  161. if (typeof jQuery === 'undefined' || parseFloat(jQuery.fn.jquery) < 1.7) {
  162. Afterpay.loadScript('https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', function() {
  163. var jQuery_1_12_4 = jQuery.noConflict(true);
  164. Afterpay.init(jQuery_1_12_4);
  165. });
  166. } else {
  167. Afterpay.init(jQuery);
  168. }
  169. }
  170. Afterpay.products.push({{ product | json }});
  171. </script>
  172. {% endif %}
  173. {% endif %}
  174. <!-- End Afterpay Liquid Snippet for Shopify v2.2.0 -->
  175. {% if product.compare_at_price_max > product.price %}
  176. <span class="visuallyhidden price-a11y">{{ 'products.general.regular_price' | t }}</span>
  177. <del class="compare-price">{{ product.compare_at_price_max | money }}</del>
  178. {% endif %}
  179. </div>
  180. </div>
  181.  
  182. <div class="grid product-single">
  183. <div class="grid-item large--one-half text-center">
  184. <div class="product-single__photos">
  185. {% assign featured_image = product.selected_or_first_available_variant.featured_image | default: product.featured_image %}
  186.  
  187. {% for image in product.images %}
  188. {% capture img_id %}ProductImage-{{ image.id }}{% endcapture %}
  189. {% capture img_wrapper_id %}ProductImageWrapper-{{ image.id }}{% endcapture %}
  190. {%- assign img_url = image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' -%}
  191. {% include 'image-style' with image: image, small_style: false, width: 480, height: 480, wrapper_id: img_wrapper_id, img_id: img_id %}
  192.  
  193. <div id="{{ img_wrapper_id }}" class="product-single__image-wrapper js{% unless featured_image == image %} hide{% endunless %}" data-image-id="{{ image.id }}">
  194. <div style="padding-top:{{ 1 | divided_by: image.aspect_ratio | times: 100}}%;">
  195. <img id="{{ img_id }}"
  196. class="product-single__image lazyload{% unless featured_image == image %} lazypreload{% endunless %}"
  197. data-src="{{ img_url }}"
  198. data-widths="[180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 2048]"
  199. data-aspectratio="{{ image.aspect_ratio }}"
  200. data-sizes="auto"
  201. {% if section.settings.product_image_zoom_enable %} data-zoom="{{ image | img_url: '1024x1024' }}"{% endif %}
  202. alt="{{ image.alt | escape }}">
  203. </div>
  204. </div>
  205. {% else %}
  206. <img src="{{ image | img_url: 'large' }}">
  207. {% endfor %}
  208.  
  209. <noscript>
  210. <img src="{{ featured_image | img_url: 'large' }}" alt="{{ featured_image.alt | escape }}">
  211. </noscript>
  212. </div>
  213.  
  214. {% comment %}
  215. Create thumbnails if we have more than one product image
  216. {% endcomment %}
  217. {% if product.images.size > 1 %}
  218. <ul class="product-single__thumbs grid-uniform" id="productThumbs">
  219.  
  220. {% for image in product.images %}
  221. <li class="grid-item one-quarter">
  222. <a href="{{ image.src | img_url: '1024x1024' }}" class="product-single__thumb" data-image-id="{{ image.id }}">
  223. <img src="{{ image.src | img_url: 'compact' }}" alt="{{ image.alt | escape }}">
  224. </a>
  225. </li>
  226. {% endfor %}
  227.  
  228. </ul>
  229. {% endif %}
  230. </div>
  231.  
  232. <div class="grid-item large--one-half">
  233.  
  234. <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  235.  
  236. {% comment %}
  237. Get first variant, or deep linked one
  238. {% endcomment %}
  239. {% assign variant = product.selected_or_first_available_variant %}
  240.  
  241. <meta itemprop="priceCurrency" content="{{ shop.currency }}">
  242. <meta itemprop="price" content="{{ variant.price | divided_by: 100.00 }}">
  243.  
  244. <link itemprop="availability" href="http://schema.org/{% if variant.available %}InStock{% else %}OutOfStock{% endif %}">
  245.  
  246. {% comment %}
  247. ID addToCartForm is a selector for the ajaxify cart plugin
  248. {% endcomment %}
  249. <form action="/cart/add" method="post" enctype="multipart/form-data" id="addToCartForm-{{ section.id }}">
  250.  
  251. {% comment %}
  252. Add product variants as a dropdown.
  253. - By default, each variant (or combination of variants) will display as its own <option>
  254. - To separate these into multiple steps, which we suggest, use option_selection.js (see below)
  255.  
  256. You can leverage jQuery to add a callback on page load and each time the select element changes:
  257. - Include option_selection.js (as seen at the bottom of this file)
  258. - This allows you to use JavaScript anytime the variant dropdown changes
  259. - This also separates out your variant options (ie. size, color, etc.) to separate select elements
  260.  
  261. For more information on products with multiple options, visit:
  262. - http://docs.shopify.com/support/your-website/themes/can-i-make-my-theme-use-products-with-multiple-options#update-product-liquid
  263. {% endcomment %}
  264. <div class="product-single__variants">
  265. <select name="id" id="ProductSelect-{{ section.id }}" class="product-single__variants">
  266. {% for variant in product.variants %}
  267. {% if variant.available %}
  268.  
  269. {% comment %}
  270. Note: if you use option_selection.js, your <select> tag will be overwritten, meaning what you have inside <option> will not reflect what you coded below.
  271. {% endcomment %}
  272. <option {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %} data-sku="{{ variant.sku }}" value="{{ variant.id }}">{{ variant.title }} - {{ variant.price | money_with_currency }}</option>
  273.  
  274. {% else %}
  275. <option disabled="disabled">
  276. {{ variant.title }} - {{ 'products.product.sold_out' | t }}
  277. </option>
  278. {% endif %}
  279. {% endfor %}
  280. </select>
  281. </div>
  282.  
  283. <div class="grid--uniform product-single__addtocart">
  284. {% if section.settings.product_qty_enable %}
  285. {% unless sold_out %}<label>{{ 'products.product.quantity' | t }}</label>{% endunless %}
  286. <input type="number" id="quantity" name="quantity" value="1" min="1" class="quantity-selector">
  287. {% endif %}
  288. <button type="submit" name="add" id="addToCart-{{ section.id }}" class="btn btn--large btn--full">
  289. <span class="add-to-cart-text">{{ 'products.product.add_to_cart' | t }}</span>
  290. </button>
  291. </div>
  292.  
  293. </form>
  294.  
  295. </div>
  296.  
  297. <div class="product-single__desc rte" itemprop="description">
  298. {{ product.description }}
  299. </div>
  300. {% if section.settings.share_enable %}
  301. {% include 'social-sharing' %}
  302. {% endif %}
  303. <div id="shopify-product-reviews" data-id="{{product.id}}">{{ product.metafields.spr.reviews }}</div>
  304. </div>
  305. </div>
  306. {% if section.settings.related_products_enable %}
  307. {% include 'related-products' %}
  308. {% endif %}
  309. </div>
  310.  
  311. {% unless product == empty %}
  312. <script type="application/json" id="ProductJson-{{ section.id }}">
  313. {{ product | json }}
  314. </script>
  315. {% endunless %}
  316.  
  317. {% schema %}
  318. {
  319. "name": "Product page",
  320. "settings": [
  321. {
  322. "type": "checkbox",
  323. "id": "product_vendor_enable",
  324. "label": "Show product vendor"
  325. },
  326. {
  327. "type": "checkbox",
  328. "id": "product_image_zoom_enable",
  329. "label": "Enable image zoom"
  330. },
  331. {
  332. "type": "checkbox",
  333. "id": "related_products_enable",
  334. "label": "Show related products"
  335. },
  336. {
  337. "type": "checkbox",
  338. "id": "product_qty_enable",
  339. "label": "Show quantity selector"
  340. },
  341. {
  342. "type": "checkbox",
  343. "id": "share_enable",
  344. "label": "Enable product sharing"
  345. }
  346. ]
  347. }
  348. {% endschema %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement