Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('#button-quote').on('click', function() {
- $.ajax({
- url: 'index.php?route=extension/total/shipping/quote',
- type: 'post',
- data: 'country_id=' + $('select[name=\'country_id\']').val() + '&zone_id=' + $('select[name=\'zone_id\']').val() + '&postcode=' + encodeURIComponent($('input[name=\'postcode\']').val()),
- dataType: 'json',
- beforeSend: function() {
- $('#button-quote').button('loading');
- },
- complete: function() {
- $('#button-quote').button('reset');
- },
- success: function(json) {
- $('.alert, .text-danger').remove();
- if (json['error']) {
- if (json['error']['warning']) {
- $('.breadcrumb').after('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error']['warning'] + '<button type="button" class="close" data-dismiss="alert">×</button></div>');
- $('html, body').animate({ scrollTop: 0 }, 'slow');
- }
- if (json['error']['country']) {
- $('select[name=\'country_id\']').after('<div class="text-danger">' + json['error']['country'] + '</div>');
- }
- if (json['error']['zone']) {
- $('select[name=\'zone_id\']').after('<div class="text-danger">' + json['error']['zone'] + '</div>');
- }
- if (json['error']['postcode']) {
- $('input[name=\'postcode\']').after('<div class="text-danger">' + json['error']['postcode'] + '</div>');
- }
- }
- if (json['shipping_method']) {
- $('#modal-shipping').remove();
- html = '<div id="modal-shipping" class="modal">';
- html += ' <div class="modal-dialog">';
- html += ' <div class="modal-content">';
- html += ' <div class="modal-header">';
- html += ' <h4 class="modal-title"><?php echo $text_shipping_method; ?></h4>';
- html += ' </div>';
- html += ' <div class="modal-body">';
- for (i in json['shipping_method']) {
- html += '<p><strong>' + json['shipping_method'][i]['title'] + '</strong></p>';
- if (!json['shipping_method'][i]['error']) {
- for (j in json['shipping_method'][i]['quote']) {
- html += '<div class="radio">';
- html += ' <label>';
- if (json['shipping_method'][i]['quote'][j]['code'] == '<?php echo $shipping_method; ?>') {
- html += '<input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" checked="checked" />';
- } else {
- html += '<input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" />';
- }
- html += json['shipping_method'][i]['quote'][j]['title'] + ' - ' + json['shipping_method'][i]['quote'][j]['text'] + '</label></div>';
- }
- } else {
- html += '<div class="alert alert-danger">' + json['shipping_method'][i]['error'] + '</div>';
- }
- }
- html += ' </div>';
- html += ' <div class="modal-footer">';
- html += ' <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $button_cancel; ?></button>';
- <?php if ($shipping_method) { ?>
- html += ' <input type="button" value="<?php echo $button_shipping; ?>" id="button-shipping" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary" />';
- <?php } else { ?>
- html += ' <input type="button" value="<?php echo $button_shipping; ?>" id="button-shipping" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary" disabled="disabled" />';
- <?php } ?>
- html += ' </div>';
- html += ' </div>';
- html += ' </div>';
- html += '</div> ';
- $('body').append(html);
- $('#modal-shipping').modal('show');
- $('input[name=\'shipping_method\']').on('change', function() {
- $('#button-shipping').prop('disabled', false);
- });
- }
- },
- error: function(xhr, ajaxOptions, thrownError) {
- alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement