kelly-v
9/28/2016 - 1:10 AM

Back in Stock

Back in Stock

{% if product.tags contains "bis-hidden" %}
  <p class="out-of-stock">{{ settings.out-of-stock-message }}</p>
{% else %}
  <div class="product-reorder">
    <h3>{{ settings.restock-notify-heading }}</h3>
    <p>{{ settings.restock-notify-message }}</p>
    <div class="restock-notify-form">
      <input type="email" id="notify_email"{% if customer.email != blank %} value="{{ customer.email }}"{% endif %}>
      <button id="notify_button">{{ settings.notify-me-button }}</button>
    </div>
  </div>
{% endif %}

<script>
  var notificationCallback = function(data) {
    var msg = '';
    if (data.status == 'OK') {
      msg = data.message; // just show the success message
    } else { // it was an error
      for (var k in data.errors) {  // collect all the error messages into a string
         msg += (k + " " + data.errors[k].join());
       }
    }
    alert(msg);
  }
  $('#notify_button').click(function(e) {
    e.preventDefault();
    var email = $('#notify_email').val(),
        productId = {{ product.id }},  // rendered by Liquid
        variantId = {{ product.variants.first.id }}; // rendered by Liquid
    BIS.create(email, variantId, productId).then(notificationCallback); // create the notification
  })
</script>