Skip to content

Instantly share code, notes, and snippets.

@mivajenn
Created April 9, 2015 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mivajenn/69251c519da2374a0e1c to your computer and use it in GitHub Desktop.
Save mivajenn/69251c519da2374a0e1c to your computer and use it in GitHub Desktop.
$('.edit-options').on('click', function(e) {
e.preventDefault();
var productCode = $(this).attr('data-product'),
qty = $(this).attr('data-quantity'),
baskline = $(this).attr('data-basketline'),
errors = 0,
eoURl = location.protocol + '//' + location.host + '/mm5/merchant.mvc?Screen=PROD&Product_Code=' + productCode + '&qty=' + qty + '&baskline=' + baskline + '&editoptions=1';
$.get(eoURl, function(data) {
$('#options-modal .modal-content').html(data);
}).done(function() {
$('#options-modal').modal('show');
$('#change-options').on('click', function(e) {
$(this).html('Processing');
$(this).attr('disabled', 'disabled');
var cform = $('#purchase-form'),
cformData = cform.serialize(),
cformUrl = cform.attr('action'),
cformMethod = cform.attr('method'),
responseMsg = $('#ajax-message');
$.ajax({
url: cformUrl + '&request=AJAX',
type: cformMethod,
data: cformData,
success: function(data, textStatus, jqXHR) {
if (data.search(/id="BASK"/i) != -1) {
// Re-Initialize Attribute Machine (if it is active)
if (typeof attrMachCall !== 'undefined') {
attrMachCall.Initialize();
};
} else if(data.search(/id="JS_PLMT"/i) != -1) {
responseMsg.html('We do not have enough of the Size/Color you have selected. Please review your options.').fadeIn().delay(3000).fadeOut();
errors = 1;
} else if(data.search(/id="JS_POUT"/i) != -1) {
responseMsg.html('The Size/Color you have selected is out of stock. Please review your options or check back later.').fadeIn().delay(3000).fadeOut();
errors = 1;
} else {
responseMsg.html('Unable to add to cart. Please review options.').fadeIn().delay(3000).fadeOut();
errors = 1;
};
cform.data('formstatus', 'idle');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
}
}).done(function() {
if (errors == 1) {
$('#change-options').html('Change Options');
$('#change-options').removeAttr('disabled');
} else {
$('#remove-form').submit();
}
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment