shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

shipping.twig (8453B)


      1 <div class="panel panel-default">
      2   <div class="panel-heading">
      3     <h4 class="panel-title"><a href="#collapse-shipping" class="accordion-toggle" data-toggle="collapse" data-parent="#accordion">{{ heading_title }} <i class="fa fa-caret-down"></i></a></h4>
      4   </div>
      5   <div id="collapse-shipping" class="panel-collapse collapse">
      6     <div class="panel-body">
      7       <p>{{ text_shipping }}</p>
      8       <div class="form-horizontal">
      9         <div class="form-group required">
     10           <label class="col-sm-2 control-label" for="input-country">{{ entry_country }}</label>
     11           <div class="col-sm-10">
     12             <select name="country_id" id="input-country" class="form-control">
     13               <option value="">{{ text_select }}</option>
     14               {% for country in countries %}
     15               {% if country.country_id == country_id %}
     16               <option value="{{ country.country_id }}" selected="selected">{{ country.name }}</option>
     17               {% else %}
     18               <option value="{{ country.country_id }}">{{ country.name }}</option>
     19               {% endif %}
     20               {% endfor %}
     21             </select>
     22           </div>
     23         </div>
     24         <div class="form-group required">
     25           <label class="col-sm-2 control-label" for="input-zone">{{ entry_zone }}</label>
     26           <div class="col-sm-10">
     27             <select name="zone_id" id="input-zone" class="form-control">
     28             </select>
     29           </div>
     30         </div>
     31         <div class="form-group required">
     32           <label class="col-sm-2 control-label" for="input-postcode">{{ entry_postcode }}</label>
     33           <div class="col-sm-10">
     34             <input type="text" name="postcode" value="{{ postcode }}" placeholder="{{ entry_postcode }}" id="input-postcode" class="form-control" />
     35           </div>
     36         </div>
     37         <button type="button" id="button-quote" data-loading-text="{{ text_loading }}" class="btn btn-primary">{{ button_quote }}</button>
     38       </div>
     39       <script type="text/javascript"><!--
     40 $('#button-quote').on('click', function() {
     41 	$.ajax({
     42 		url: 'index.php?route=extension/total/shipping/quote',
     43 		type: 'post',
     44 		data: 'country_id=' + $('select[name=\'country_id\']').val() + '&zone_id=' + $('select[name=\'zone_id\']').val() + '&postcode=' + encodeURIComponent($('input[name=\'postcode\']').val()),
     45 		dataType: 'json',
     46 		beforeSend: function() {
     47 			$('#button-quote').button('loading');
     48 		},
     49 		complete: function() {
     50 			$('#button-quote').button('reset');
     51 		},
     52 		success: function(json) {
     53 			$('.alert-dismissible, .text-danger').remove();
     54 
     55 			if (json['error']) {
     56 				if (json['error']['warning']) {
     57 					$('.breadcrumb').after('<div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> ' + json['error']['warning'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
     58 
     59 					$('html, body').animate({ scrollTop: 0 }, 'slow');
     60 				}
     61 
     62 				if (json['error']['country']) {
     63 					$('select[name=\'country_id\']').after('<div class="text-danger">' + json['error']['country'] + '</div>');
     64 				}
     65 
     66 				if (json['error']['zone']) {
     67 					$('select[name=\'zone_id\']').after('<div class="text-danger">' + json['error']['zone'] + '</div>');
     68 				}
     69 
     70 				if (json['error']['postcode']) {
     71 					$('input[name=\'postcode\']').after('<div class="text-danger">' + json['error']['postcode'] + '</div>');
     72 				}
     73 			}
     74 
     75 			if (json['shipping_method']) {
     76 				$('#modal-shipping').remove();
     77 
     78 				html  = '<div id="modal-shipping" class="modal">';
     79 				html += '  <div class="modal-dialog">';
     80 				html += '    <div class="modal-content">';
     81 				html += '      <div class="modal-header">';
     82 				html += '        <h4 class="modal-title">{{ text_shipping_method }}</h4>';
     83 				html += '      </div>';
     84 				html += '      <div class="modal-body">';
     85 
     86 				for (i in json['shipping_method']) {
     87 					html += '<p><strong>' + json['shipping_method'][i]['title'] + '</strong></p>';
     88 
     89 					if (!json['shipping_method'][i]['error']) {
     90 						for (j in json['shipping_method'][i]['quote']) {
     91 							html += '<div class="radio">';
     92 							html += '  <label>';
     93 
     94 							if (json['shipping_method'][i]['quote'][j]['code'] == '{{ shipping_method }}') {
     95 								html += '<input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" checked="checked" />';
     96 							} else {
     97 								html += '<input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" />';
     98 							}
     99 
    100 							html += json['shipping_method'][i]['quote'][j]['title'] + ' - ' + json['shipping_method'][i]['quote'][j]['text'] + '</label></div>';
    101 						}
    102 					} else {
    103 						html += '<div class="alert alert-danger alert-dismissible">' + json['shipping_method'][i]['error'] + '</div>';
    104 					}
    105 				}
    106 
    107 				html += '      </div>';
    108 				html += '      <div class="modal-footer">';
    109 				html += '        <button type="button" class="btn btn-default" data-dismiss="modal">{{ button_cancel }}</button>';
    110 
    111 				{% if shipping_method %}
    112 				html += '        <input type="button" value="{{ button_shipping }}" id="button-shipping" data-loading-text="{{ text_loading }}" class="btn btn-primary" />';
    113 				{% else %}
    114 				html += '        <input type="button" value="{{ button_shipping }}" id="button-shipping" data-loading-text="{{ text_loading }}" class="btn btn-primary" disabled="disabled" />';
    115 				{% endif %}
    116 
    117 				html += '      </div>';
    118 				html += '    </div>';
    119 				html += '  </div>';
    120 				html += '</div> ';
    121 
    122 				$('body').append(html);
    123 
    124 				$('#modal-shipping').modal('show');
    125 
    126 				$('input[name=\'shipping_method\']').on('change', function() {
    127 					$('#button-shipping').prop('disabled', false);
    128 				});
    129 			}
    130 		},
    131 		error: function(xhr, ajaxOptions, thrownError) {
    132 			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
    133 		}
    134 	});
    135 });
    136 
    137 $(document).delegate('#button-shipping', 'click', function() {
    138 	$.ajax({
    139 		url: 'index.php?route=extension/total/shipping/shipping',
    140 		type: 'post',
    141 		data: 'shipping_method=' + encodeURIComponent($('input[name=\'shipping_method\']:checked').val()),
    142 		dataType: 'json',
    143 		beforeSend: function() {
    144 			$('#button-shipping').button('loading');
    145 		},
    146 		complete: function() {
    147 			$('#button-shipping').button('reset');
    148 		},
    149 		success: function(json) {
    150 			$('.alert-dismissible').remove();
    151 
    152 			if (json['error']) {
    153 				$('.breadcrumb').after('<div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
    154 
    155 				$('html, body').animate({ scrollTop: 0 }, 'slow');
    156 			}
    157 
    158 			if (json['redirect']) {
    159 				location = json['redirect'];
    160 			}
    161 		},
    162 		error: function(xhr, ajaxOptions, thrownError) {
    163 			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
    164 		}
    165 	});
    166 });
    167 //--></script>
    168 <script type="text/javascript"><!--
    169 $('select[name=\'country_id\']').on('change', function() {
    170 	$.ajax({
    171 		url: 'index.php?route=extension/total/shipping/country&country_id=' + this.value,
    172 		dataType: 'json',
    173 		beforeSend: function() {
    174 			$('select[name=\'country_id\']').prop('disabled', true);
    175 		},
    176 		complete: function() {
    177 			$('select[name=\'country_id\']').prop('disabled', false);
    178 		},
    179 		success: function(json) {
    180 			if (json['postcode_required'] == '1') {
    181 				$('input[name=\'postcode\']').parent().parent().addClass('required');
    182 			} else {
    183 				$('input[name=\'postcode\']').parent().parent().removeClass('required');
    184 			}
    185 
    186 			html = '<option value="">{{ text_select }}</option>';
    187 
    188 			if (json['zone'] && json['zone'] != '') {
    189 				for (i = 0; i < json['zone'].length; i++) {
    190 					html += '<option value="' + json['zone'][i]['zone_id'] + '"';
    191 
    192 					if (json['zone'][i]['zone_id'] == '{{ zone_id }}') {
    193 						html += ' selected="selected"';
    194 					}
    195 
    196 					html += '>' + json['zone'][i]['name'] + '</option>';
    197 				}
    198 			} else {
    199 				html += '<option value="0" selected="selected">{{ text_none }}</option>';
    200 			}
    201 
    202 			$('select[name=\'zone_id\']').html(html);
    203 		},
    204 		error: function(xhr, ajaxOptions, thrownError) {
    205 			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
    206 		}
    207 	});
    208 });
    209 
    210 $('select[name=\'country_id\']').trigger('change');
    211 //--></script>
    212     </div>
    213   </div>
    214 </div>