Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 3.86 KB | None | 0 0
  1. $('#button-quote').on('click', function() {
  2.     $.ajax({
  3.         url: 'index.php?route=extension/total/shipping/quote',
  4.         type: 'post',
  5.         data: 'country_id=' + $('select[name=\'country_id\']').val() + '&zone_id=' + $('select[name=\'zone_id\']').val() + '&postcode=' + encodeURIComponent($('input[name=\'postcode\']').val()),
  6.         dataType: 'json',
  7.         beforeSend: function() {
  8.             $('#button-quote').button('loading');
  9.         },
  10.         complete: function() {
  11.             $('#button-quote').button('reset');
  12.         },
  13.         success: function(json) {
  14.             $('.alert, .text-danger').remove();
  15.  
  16.             if (json['error']) {
  17.                 if (json['error']['warning']) {
  18.                     $('.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">&times;</button></div>');
  19.  
  20.                     $('html, body').animate({ scrollTop: 0 }, 'slow');
  21.                 }
  22.  
  23.                 if (json['error']['country']) {
  24.                     $('select[name=\'country_id\']').after('<div class="text-danger">' + json['error']['country'] + '</div>');
  25.                 }
  26.  
  27.                 if (json['error']['zone']) {
  28.                     $('select[name=\'zone_id\']').after('<div class="text-danger">' + json['error']['zone'] + '</div>');
  29.                 }
  30.  
  31.                 if (json['error']['postcode']) {
  32.                     $('input[name=\'postcode\']').after('<div class="text-danger">' + json['error']['postcode'] + '</div>');
  33.                 }
  34.             }
  35.  
  36.             if (json['shipping_method']) {
  37.                 $('#modal-shipping').remove();
  38.  
  39.                 html  = '<div id="modal-shipping" class="modal">';
  40.                 html += '  <div class="modal-dialog">';
  41.                 html += '    <div class="modal-content">';
  42.                 html += '      <div class="modal-header">';
  43.                 html += '        <h4 class="modal-title"><?php echo $text_shipping_method; ?></h4>';
  44.                 html += '      </div>';
  45.                 html += '      <div class="modal-body">';
  46.  
  47.                 for (i in json['shipping_method']) {
  48.                     html += '<p><strong>' + json['shipping_method'][i]['title'] + '</strong></p>';
  49.  
  50.                     if (!json['shipping_method'][i]['error']) {
  51.                         for (j in json['shipping_method'][i]['quote']) {
  52.                             html += '<div class="radio">';
  53.                             html += '  <label>';
  54.  
  55.                             if (json['shipping_method'][i]['quote'][j]['code'] == '<?php echo $shipping_method; ?>') {
  56.                                 html += '<input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" checked="checked" />';
  57.                             } else {
  58.                                 html += '<input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" />';
  59.                             }
  60.  
  61.                             html += json['shipping_method'][i]['quote'][j]['title'] + ' - ' + json['shipping_method'][i]['quote'][j]['text'] + '</label></div>';
  62.                         }
  63.                     } else {
  64.                         html += '<div class="alert alert-danger">' + json['shipping_method'][i]['error'] + '</div>';
  65.                     }
  66.                 }
  67.  
  68.                 html += '      </div>';
  69.                 html += '      <div class="modal-footer">';
  70.                 html += '        <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $button_cancel; ?></button>';
  71.  
  72.                 <?php if ($shipping_method) { ?>
  73.                 html += '        <input type="button" value="<?php echo $button_shipping; ?>" id="button-shipping" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary" />';
  74.                 <?php } else { ?>
  75.                 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" />';
  76.                 <?php } ?>
  77.  
  78.                 html += '      </div>';
  79.                 html += '    </div>';
  80.                 html += '  </div>';
  81.                 html += '</div> ';
  82.  
  83.                 $('body').append(html);
  84.  
  85.                 $('#modal-shipping').modal('show');
  86.  
  87.                 $('input[name=\'shipping_method\']').on('change', function() {
  88.                     $('#button-shipping').prop('disabled', false);
  89.                 });
  90.             }
  91.         },
  92.         error: function(xhr, ajaxOptions, thrownError) {
  93.             alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
  94.         }
  95.     });
  96. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement