Advertisement
Guest User

new customify

a guest
Jul 18th, 2018
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.41 KB | None | 0 0
  1. <div id="left-side"> {{ customify-widget }}</div>
  2. <div id="right-side">
  3. <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  4. <link itemprop="availability" href="http://schema.org/InStock">
  5. <meta itemprop="priceCurrency" content="{{ shop.currency }}">
  6. <link itemprop="availability" href="http://schema.org/{% if product.available %}InStock{% else %}OutOfStock{% endif %}">
  7. <h1 itemprop="name">{{ product.title }}</h1> {% assign form_grid = false %} {% if form_method == "standard" or product.variants.size == 1 %}
  8. <div class="customify-form-row"> <span id="ProductPrice" class="customify-price" itemprop="price" content="{{ product.price | divided_by: 100.00 }}"> <span id="variant_price" >{{ product.price | money }}</span> </span>{% if product.compare_at_price > product.price %} <span id="PriceA11y" class="visually-hidden">Price</span> <s id="compare_price" class="product-single__sale-price"> {{ product.compare_at_price_max | money }} </s> {% endif %}</div>
  9. <form name="customify_form" id="customify_form" action="/cart/add" method="post" enctype="multipart/form-data">
  10. <input type="file" id="customify-upload" style="display: none" />
  11. <input type="hidden" id="customify_id" name="properties[customify_id]" /> {% if product.variants.size == 1 %}
  12. <input type="hidden" value="{{ product.variants.first.id }}" name="id" />{% else %}
  13. <select name="id" id="productSelect" class="product-single__variants"> {% for variant in product.variants %} {% if variant.available %}
  14. <option data-sku="{{ variant.sku }}" value="{{ variant.id }}">{{ variant.title }} - {{ variant.price | money_with_currency }}</option>{% else %}
  15. <option disabled="disabled"> {{ variant.title }} - Sold Out</option> {% endif %} {% endfor %} </select>{% endif %}{{ product_color_grid }}{{ customify_text_widget }}
  16. <div class="customify-form-row">
  17. <label for="Quantity">Quantity</label>
  18. <input type="number" id="Quantity" name="quantity" value="1" min="1" class="quantity-selector">
  19. </div>
  20. <div class="customify-form-row">
  21. <label id="note-label" for="note">Note</label>
  22. <textarea id="note" name="properties[customify_note]"></textarea>
  23. </div>
  24. <div class="customify-form-row">
  25. <button id="back-product" style="display: none; margin-right: 10px; " type="button" class="btn"> <span>&laquo; BACK</span> </button>
  26. <button type="submit" name="add" id="customify-addtocart" class="btn"> <span id="AddToCartText">ADD TO CART</span> </button>
  27. </div>
  28. </form>
  29. <div class="customify-form-row"> {{ product.description }}</div> {% else %} {% assign form_grid = true %}
  30. <div id="customify-variant-table">
  31. <input type="file" id="customify-upload" style="display: none" />{{ product_color_grid }}{{ customify_text_widget }}
  32. <table width="100%" border="0" cellspacing="0" cellpadding="0" name="id" style="display:block;!important">
  33. <tbody>
  34. <tr class="{% cycle 'rx','ry' %}">{% for option in product.options %}
  35. <th>{{ option }}</th> {% endfor %}
  36. <th scope="col" class="center">Price</th>
  37. <th scope="col" style="width: 80px;" class="textright">Quantity</th>
  38. </tr> {% for variant in product.variants %} {% if variant.available %}
  39. <tr class="{% cycle 'xx','yy' %}" id="variant_tr-{{ variant.id }}"> {% for option in product.options %}
  40. <td class='text'>{{ variant.options[forloop.index0] }}</td> {% endfor %}
  41. <td value="{{ variant.id }}" title="" class="center">{{ variant.price | money }} {% if variant.compare_at_price > variant.price %} <del>{{ variant.compare_at_price | money }}</del>{% endif %}</td>
  42. <td> {% if variant.available %}
  43. <input data-idx="{{ variant.id }}" class='qty_input' type="text" value="0" name="qty_{{variant.id}}" id="qty_{{ variant.id}}" /> {% else %} Sold {% endif %}</td>
  44. </tr> {% endif %} {% endfor %}</tbody>
  45. </table>
  46. <div class="msg-info" style="display: none; padding: 10px 0px;"></div>
  47. </div>
  48. <div class="customify-form-row">
  49. <button id="back-product" style="display: none; margin-right: 10px; " type="button" class="btn"> <span>&laquo; BACK</span> </button>
  50. <button type="submit" name="add" id="customify-addtocart" class="btn"> <span id="AddToCartText">ADD TO CART</span> </button>
  51. </div> {% endif %}</div>
  52. </div>{% if form_grid %}
  53. <br />
  54. <div class="customify-form-row"> {{ product.description }}</div>
  55. <script type="text/javascript">
  56. var the_form = $("#customify-variant-table");
  57. success_div = the_form.find(".msg-info");
  58.  
  59. function add_to_cart_mass(t) {
  60. Shopify.queue = [];
  61. var i = 0;
  62. the_form.find('.qty_input').each(function() {
  63. idx = $(this).attr('data-idx');
  64. qty = $(this).val() * 1;
  65. if (qty > 0) {
  66. Shopify.queue.push({
  67. variant_id: idx,
  68. quantity: qty,
  69. properties: {
  70. 'customify_id': t
  71. }
  72. });
  73. i++;
  74. }
  75. });
  76. if (i > 0) Shopify.moveAlong();
  77. }
  78. Shopify.moveAlong = function() {
  79. if (Shopify.queue.length) {
  80. $('#customify-addtocart').attr('disable', true).html("<span id='AddToCartText'>Processing..</span>");
  81. var request = Shopify.queue.shift();
  82. Shopify.addItem(request.variant_id, request.quantity, request.properties, Shopify.moveAlong);
  83. } else {
  84. success_div.html('<span>Item(s) Added to the Cart!</span> <a href="/cart">View cart</a>').fadeIn(300).delay(7000).fadeOut(300);
  85. $('#customify-addtocart').attr('disable', false).html("<span id='AddToCartText'>" + add_to_cart_text + "</span>");
  86. window.location = "/cart"
  87. }
  88. };
  89. Shopify.addItem = function(id, qty, properties, callback) {
  90. var params = {
  91. quantity: qty,
  92. id: id
  93. };
  94. if (properties != false) {
  95. params.properties = properties;
  96. }
  97. $.ajax({
  98. type: 'POST',
  99. url: '/cart/add.js',
  100. dataType: 'json',
  101. data: params,
  102. success: function() {
  103. if (typeof callback === 'function') {
  104. callback();
  105. }
  106. },
  107. error: function() {}
  108. });
  109. }
  110. </script> {% else %} {{ "option_selection.js" | shopify_asset_url | script_tag }}
  111. <script type="text/javascript">
  112. $(document).ready(function() {
  113. function getUrlParams(e, n) {
  114. n || (n = window.location.href), e = e.replace(/[\[\]]/g, "\$&");
  115. var r = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"),
  116. a = r.exec(n);
  117. return a ? a[2] ? decodeURIComponent(a[2].replace(/\+/g, " ")) : "" : null
  118. }
  119. var variant_id = getUrlParams("variant");
  120. $("select[name='id']").val(variant_id);
  121. console.log("script proceed");
  122. var selectCallback2 = function(variant, selector) {
  123. $("#variant_price").html(Shopify.formatMoney(variant.price, "{{ shop.money_with_currency_format }}"));
  124. $("#compare_price").html(Shopify.formatMoney(variant.compare_at_price, "{{ shop.money_with_currency_format }}"));
  125. if (variant.inventory_management == "shopify" && variant.inventory_policy == "deny" && variant.old_inventory_quantity == 0) {
  126. $("#customify-addtocart").prop("disabled", true);
  127. $("#recreation-button").hide();
  128. $("#AddToCartText").text("SOLD OUT");
  129. } else {
  130. $("#recreation-button").show();
  131. $("#customify-addtocart").prop("disabled", false);
  132. }
  133. };
  134. jQuery(function($) {
  135. new Shopify.OptionSelectors("productSelect", {
  136. product: {{ product | json }},
  137. onVariantSelected: selectCallback2,
  138. enableHistoryState: true
  139. }); {{ %
  140. if product.options.size == 1 and product.options.first != "Title" %
  141. }}$(".selector-wrapper:eq(0)").prepend('<label for="productSelect-option-0">{{ product.options.first | escape }}</label>'); {{ % endif %
  142. }} {{ %
  143. if product.variants.size == 1 and product.variants.first.title contains "Default" %
  144. }}
  145. $(".selector-wrapper").hide(); {{ % endif %
  146. }}
  147. });
  148. });
  149.  
  150. function add_to_cart(t) {
  151. document.getElementById("customify_id").value = t;
  152. document.getElementById("customify_form").submit();
  153. }
  154. $(window).on("load", function() {
  155. $("#customify_form div").removeClass("selectreplace");
  156. });
  157. </script> {% endif %}
  158. <script type="text/javascript">
  159. $(document).ready(function() {
  160. if ($("#main-container").parents(".customify-back").length > 0) {
  161. $("#back-product").show().attr("onclick", "window.location='{{ product.url }}'");
  162. }
  163. });
  164. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement