Guest User

Untitled

a guest
Nov 15th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. {% comment %} this code goes at the footer {% endcomment %}
  2. {% if template.name == 'product' %}
  3. {{ 'option_selection.js' | shopify_asset_url | script_tag }}
  4. <style>
  5. .selector-wrapper {
  6. display: none !important;
  7. }
  8. </style>
  9. <script>
  10.  
  11. var selectCallback = function(variant, selector) {
  12. if (variant) {
  13. if (variant.available) {
  14. $('.devStock').text(variant.inventory_quantity);
  15. console.log('yo: '+variant.inventory_quantity);
  16. // Selected a valid variant that is available.
  17. //$('#add').removeClass('disabled').removeAttr('disabled').val('Add to Cart').fadeTo(200,1);
  18. } else {
  19. // Variant is sold out.
  20. $('.devStock').text(variant.inventory_quantity);
  21. }
  22. } else {
  23. // variant doesn't exist.
  24. $('#add').val('Unavailable').addClass('disabled').attr('disabled', 'disabled').fadeTo(200,0.5);
  25. }
  26. }
  27. // initialize multi selector for product
  28. jQuery(function($) {
  29. new Shopify.OptionSelectors("product-select", { product: {{ product | json }}, onVariantSelected: selectCallback });
  30.  
  31. $('.option-value-input').on('change', function(){
  32. setTimeout(function(){
  33. var currentVar = location.href;
  34. currentVar = currentVar.split('=')[1];
  35.  
  36. prodGetter(currentVar);
  37.  
  38.  
  39. }, 300);
  40. });
  41.  
  42.  
  43. var product_handle = '{{ product.handle }}';
  44. function prodGetter(currentVar){
  45. var disID = currentVar;
  46. jQuery.getJSON('/products/'+product_handle+'.js', function(product) {
  47. var xx = product.variants;
  48. var i;
  49. for (i = 0; i < xx.length; i++) {
  50. var thisIDx = xx[i].id;
  51. if( disID == thisIDx){
  52. console.log(xx[i].inventory_quantity);
  53. $('.devStock').text(xx[i].inventory_quantity);
  54. }
  55. }
  56. });
  57. }
  58.  
  59. });
  60. </script>
  61. {% endif %}
Add Comment
Please, Sign In to add comment