Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,42 @@
(function ($, undefined) {
$(document).ready(function () {

var $section = $('#product-stock-alert'),
$pseId = $('#pse-id'),
$alertPseId = $('#stock-alert-id'),
$pseSelector = $('select.pse-option'),
$cartSubmit = $('#pse-submit'),
$notify = $('#product-stock-notify')
var section = $('#product-stock-alert'),
pseId = $('#pse-id'),
alertPseId = $('#stock-alert-id'),
pseSelector = $('select.pse-option'),
cartSubmit = $('#pse-submit'),
notify = $('#product-stock-notify')
;

/* Check if add to cart is disabled or not */
var checkStock = function checkStock() {
if ($cartSubmit.prop("disabled")) {
$section.removeClass('hidden');
if (cartSubmit.prop("disabled")) {
section.removeClass('hidden');
} else {
$section.addClass('hidden');
section.addClass('hidden');
}
};

var saveStockAlert = function saveStockAlert($form) {
var saveStockAlert = function saveStockAlert(form) {

$alertPseId.val($pseId.val());
alertPseId.val(pseId.val());

$.ajax({
url: $form.attr('action'),
type: $form.attr('method'),
data: $form.serializeArray(),
url: form.attr('action'),
type: form.attr('method'),
data: form.serializeArray(),
dataType: 'json'
}).done(function(data, textStatus, jqXHR){
$notify.removeClass('hidden alert-success alert-warning');
notify.removeClass('hidden alert-success alert-warning');
if (data.success) {
$notify
notify
.addClass('alert-success')
.html(data.message)
;
$('#stock-alert-email').val("");
} else {
$notify
notify
.addClass('alert-warning')
.html(data.message)
;
Expand All @@ -48,12 +48,12 @@

};

$pseSelector.on('change', function(ev) {
pseSelector.on('change', function(ev) {
checkStock();
});

$section.on('submit', 'form', function(ev) {
event.preventDefault();
section.on('submit', 'form', function(ev) {
ev.preventDefault();

saveStockAlert($(this));
});
Expand All @@ -63,4 +63,4 @@
});
})(jQuery);

</script>
</script>