/store/catalog/view/theme/boilerplate/template/total/shipping.tpl

https://github.com/elleeott/WPOC-boilerplate · Smarty Template · 145 lines · 130 code · 15 blank · 0 comment · 19 complexity · 91534da846f9a853e41f9002dbe1fbc9 MD5 · raw file

  1. <div>
  2. <div class="cart-heading"><?php echo $heading_title; ?></div>
  3. <div class="cart-content">
  4. <p><?php echo $text_shipping; ?></p>
  5. <table id="shipping">
  6. <tr>
  7. <td><span class="required">*</span> <?php echo $entry_country; ?></td>
  8. <td><select name="country_id" onchange="$('select[name=\'zone_id\']').load('index.php?route=total/shipping/zone&country_id=' + this.value + '&zone_id=<?php echo $zone_id; ?>');">
  9. <option value=""><?php echo $text_select; ?></option>
  10. <?php foreach ($countries as $country) { ?>
  11. <?php if ($country['country_id'] == $country_id) { ?>
  12. <option value="<?php echo $country['country_id']; ?>" selected="selected"><?php echo $country['name']; ?></option>
  13. <?php } else { ?>
  14. <option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
  15. <?php } ?>
  16. <?php } ?>
  17. </select></td>
  18. </tr>
  19. <tr>
  20. <td><span class="required">*</span> <?php echo $entry_zone; ?></td>
  21. <td><select name="zone_id">
  22. </select></td>
  23. </tr>
  24. <tr>
  25. <td><span class="required">*</span> <?php echo $entry_postcode; ?></td>
  26. <td><input type="text" name="postcode" value="<?php echo $postcode; ?>" /></td>
  27. </tr>
  28. </table>
  29. <a id="button-quote" class="button button-secondary"><span><?php echo $button_quote; ?></span></a>
  30. <div id="quote" style="display: none;"></div>
  31. <input type="hidden" name="shipping_method" value="<?php echo $code; ?>" />
  32. </div>
  33. </div>
  34. <script type="text/javascript"><!--
  35. $('#button-quote').bind('click', function() {
  36. $.ajax({
  37. type: 'POST',
  38. url: 'index.php?route=total/shipping/quote',
  39. data: 'country_id=' + $('select[name=\'country_id\']').val() + '&zone_id=' + $('select[name=\'zone_id\']').val() + '&postcode=' + encodeURIComponent($('input[name=\'postcode\']').val()),
  40. dataType: 'json',
  41. beforeSend: function() {
  42. $('.success, .warning').remove();
  43. $('#button-quote').attr('disabled', true);
  44. $('#button-quote').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
  45. },
  46. complete: function() {
  47. $('#button-quote').attr('disabled', false);
  48. $('.wait').remove();
  49. },
  50. success: function(json) {
  51. $('.error').remove();
  52. if (json['redirect']) {
  53. location = json['redirect'];
  54. }
  55. if (json['error']) {
  56. if (json['error']['warning']) {
  57. $('#basket').before('<div class="warning">' + json['error']['warning'] + '</div>');
  58. }
  59. if (json['error']['country']) {
  60. $('#shipping select[name=\'country_id\'] + br').after('<span class="error">' + json['error']['country'] + '</span>');
  61. }
  62. if (json['error']['zone']) {
  63. $('#shipping select[name=\'zone_id\'] + br').after('<span class="error">' + json['error']['zone'] + '</span>');
  64. }
  65. if (json['error']['postcode']) {
  66. $('#shipping input[name=\'postcode\']').after('<span class="error">' + json['error']['postcode'] + '</span>');
  67. }
  68. }
  69. if (json['shipping_methods']) {
  70. html = '';
  71. html += '<table>';
  72. for (i in json['shipping_methods']) {
  73. html += '<tr>';
  74. html += ' <td colspan="3"><b>' + json['shipping_methods'][i]['title'] + '</b></td>';
  75. html += '</tr>';
  76. if (!json['shipping_methods'][i]['error']) {
  77. for (j in json['shipping_methods'][i]['quote']) {
  78. html += '<tr>';
  79. if (json['shipping_methods'][i]['quote'][j]['code'] == $('input[name=\'shipping_method\']').attr('value')) {
  80. html += '<td><input type="radio" name="shipping_method" value="' + json['shipping_methods'][i]['quote'][j]['code'] + '" id="' + json['shipping_methods'][i]['quote'][j]['code'] + '" checked="checked" /></td>';
  81. } else {
  82. html += '<td><input type="radio" name="shipping_method" value="' + json['shipping_methods'][i]['quote'][j]['code'] + '" id="' + json['shipping_methods'][i]['quote'][j]['code'] + '" /></td>';
  83. }
  84. html += ' <td><label for="' + json['shipping_methods'][i]['quote'][j]['code'] + '">' + json['shipping_methods'][i]['quote'][j]['title'] + '</label></td>';
  85. html += ' <td><label for="' + json['shipping_methods'][i]['quote'][j]['code'] + '">' + json['shipping_methods'][i]['quote'][j]['text'] + '</label></td>';
  86. html += '</tr>';
  87. }
  88. } else {
  89. html += '<tr>';
  90. html += ' <td colspan="3"><div class="error">' + json['shipping_methods'][i]['error'] + '</div></td>';
  91. html += '</tr> ';
  92. }
  93. }
  94. html += '</table>';
  95. html += '<a id="button-shipping" class="button button-primary"><span><?php echo $button_shipping; ?></span></a>';
  96. $('#quote').html(html);
  97. $('#quote').slideDown('slow');
  98. }
  99. }
  100. });
  101. });
  102. $('#button-shipping').live('click', function() {
  103. $.ajax({
  104. type: 'POST',
  105. url: 'index.php?route=total/shipping/calculate',
  106. data: 'shipping_method=' + $('input[name=\'shipping_method\']:checked').attr('value'),
  107. dataType: 'json',
  108. beforeSend: function() {
  109. $('.warning').remove();
  110. $('#button-shipping').attr('disabled', true);
  111. $('#button-shipping').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
  112. },
  113. complete: function() {
  114. $('#button-shipping').attr('disabled', false);
  115. $('.wait').remove();
  116. },
  117. success: function(json) {
  118. if (json['error']) {
  119. $('#shipping').before('<div class="warning">' + json['error'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
  120. }
  121. if (json['redirect']) {
  122. location = json['redirect'];
  123. }
  124. }
  125. });
  126. });
  127. //--></script>
  128. <script type="text/javascript"><!--
  129. $('select[name=\'zone_id\']').load('index.php?route=total/shipping/zone&country_id=<?php echo $country_id; ?>&zone_id=<?php echo $zone_id; ?>');
  130. //--></script>