Skip to content

Instantly share code, notes, and snippets.

@philcon93
Last active November 21, 2016 04:09
Show Gist options
  • Save philcon93/255909d79f6b4a32559e7db49b8d19d7 to your computer and use it in GitHub Desktop.
Save philcon93/255909d79f6b4a32559e7db49b8d19d7 to your computer and use it in GitHub Desktop.

Using $.addNotifyBackInStock function on product thumbnails

JS

Input Fields:

'full_name': 'from_name', 'email_address': 'from',

$.do_ajax function to the 'Add' api.

$(document).ready(function() {
var currentSKU = '';
$(".js-notify-submit").click(function(){
if (currentSKU){
console.log(currentSKU)
$.addNotifyBackInStock(currentSKU, '');
}
})
$(".btn-notify").click(function(){
currentSKU = $(this).attr('data-sku');
});
// The above will not work on browsing history because of varnish. Target something outside the b@se PRODUCT_HISTORY function to get the event to work.
$('.browsing-history').on('click', '.btn-notify', function(){
currentSKU = $(this).attr('data-sku');
});
});
<div class="modal fade notifymodal" id="notifymodal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Notify me when back in stock</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Your Name</label>
<input placeholder="Jane Smith" name="from_name" id="from_name" type="text" class="form-control" value="[%NOHTML%][@FROM_NAME@][%END NOHTML%]">
</div>
<div class="form-group">
<label>Your Email Address</label>
<input placeholder="[email protected]" name="from" id="from" type="email" class="form-control" value="[%NOHTML%][@FROM@][%END NOHTML%]">
</div>
</div>
<div class="modal-footer">
<input class="btn btn-danger" type="button" data-dismiss="modal" value="Cancel">
<input class="btn btn-success js-notify-submit" type="button" data-dismiss="modal" value="Save My Details">
</div>
</div><!-- /.modal-content -->
</div>
</div>
<a class="btn btn-default btn-block btn-notify" data-sku="[@sku@]" data-toggle="modal" data-target="#notifymodal" title="Notify Me When Back In Stock" data-loading-text="<i class='fa fa-spinner fa-spin' style='font-size: 14px'></i>">Notify Me <span class="hidden-xs hidden-md">When Back In Stock</span></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment