Changeset 2766844
- Timestamp:
- 08/05/2022 11:53:05 AM (4 years ago)
- Location:
- bring4you/trunk
- Files:
-
- 3 edited
-
README.txt (modified) (2 diffs)
-
admin/partials/bring4you-admin-display.php (modified) (4 diffs)
-
bring4you.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bring4you/trunk/README.txt
r2690745 r2766844 52 52 = UN SEUL CONTACT = 53 53 Vous avez une question et n’avez pas le temps de rester en attente auprès des standards téléphoniques de chaque transporteur ? 54 Là encore Bring4You s’occupe de tout : un seul Service client en France et en Europe pour toutes vos questions sur l’expédition. 55 Une dernière chose : L’application Bring4You est 100% gratuite, aucun abonnement ou autres frais cachés ! 54 Là encore Bring4You s’occupe de tout : un seul Service client en France et en Europe pour toutes vos questions sur l’expédition ! 56 55 57 56 C’est parti ? … … 66 65 67 66 N'hésitez pas à suivre notre guide d'installation : 68 https://stonly.com/guide/fr/integration-wordpress-b0oIbHd4Xl/Steps/ 67 [Guide vidéo](https://stonly.com/guide/fr/integration-wordpress-b0oIbHd4Xl/Steps/) 69 68 70 69 Notre vidéo de démonstration : 71 https://www.youtube.com/watch?v=zMofmyOcwq0 70 [Démonstration vidéo](https://www.youtube.com/watch?v=zMofmyOcwq0) 71 72 [Passer à la version Pro](https://modules.bring4you.com/produit/module-wordpress-woocommerce/) 72 73 73 74 == Frequently Asked Questions == -
bring4you/trunk/admin/partials/bring4you-admin-display.php
r2688745 r2766844 113 113 $commission = 0; 114 114 $cats = ''; 115 $key = '';116 115 117 116 if(get_option('b4y_plugin_setting_adresse') != '') … … 124 123 $aide = get_option('b4y_plugin_setting_aide'); 125 124 $commission = get_option('b4y_plugin_setting_comm'); 126 $key = get_option('b4y_plugin_setting_key');127 125 $cats = get_option('b4y_plugin_setting_cats'); 128 126 } … … 194 192 </div> 195 193 </div> 196 197 <div class="form-group">198 <label class="control-label col-lg-3"><?php _e('Clé API pour la création des tâches', 'b4y'); ?></label>199 <div class="b4y-editzone">200 <input type="text" name="b4y_plugin_setting_key" id="b4y_plugin_setting_key" value="<?php echo $key ?>" class="" style="width:50%">201 <p class="help-block"><?php _e('Saisir la clé API fournie par Bring4You', 'b4y'); ?></p>202 </div>203 </div>204 194 205 195 <div class="form-group"> … … 210 200 211 201 $all_categories = B4Y_allcat(); 202 212 203 ?> 213 204 <select name="b4y_plugin_setting_cats[]" id="b4y_plugin_setting_cats" multiple size="10" style="width: 50%;max-width:50%;"> -
bring4you/trunk/bring4you.php
r2688746 r2766844 17 17 * Plugin URI: https://gitlab.com/bring4you/b4u-wordpress-plugin/-/archive/master/b4u-wordpress-plugin-master.zip 18 18 * Description: Module permettant d'ajouter le transporteur Bring4You à votre installation Woocommerce 19 * Version: 1.0. 619 * Version: 1.0.5 20 20 * Author: Bring4You 21 21 * Author URI: http://bring4you.com/ … … 38 38 * Rename this for your plugin and update it as you release new versions. 39 39 */ 40 define( 'BRING4YOU_VERSION', '1. 0.6' );40 define( 'BRING4YOU_VERSION', '1.1.0' ); 41 41 42 42 /** … … 70 70 add_action( 'wp_ajax_nopriv_b4yestimation', 'B4Y_estimation_result' ); 71 71 add_action( 'wp_ajax_b4yestimation', 'B4Y_estimation_result' ); 72 add_filter( 'woocommerce_shipping_methods', 'B4Y_register_b4y_method' );73 add_filter( 'woocommerce_package_rates', 'B4Y_shipping_rate_cost_calculation', 10, 2 );74 75 // Add B4Y field to Orders76 77 add_filter( 'manage_edit-shop_order_columns', 'set_b4y_edit_shop_order_columns' );78 function set_b4y_edit_shop_order_columns($columns) {79 $columns['b4y_send'] = __( 'Bring4You', 'b4y' );80 return $columns;81 }82 83 add_action( 'manage_shop_order_posts_custom_column' , 'b4y_shop_order_column', 10, 2 );84 function b4y_shop_order_column( $column, $post_id ) {85 switch ( $column ) {86 case 'b4y_send' :87 $id = $post_id;88 89 $value = get_post_meta( $id, 'b4y_send', true );90 91 if($value == false)92 {93 echo '<a href="'.admin_url().'post.php?post='.$id.'&action=edit#b4y_sent_it_'.$id.'" class="b4y_sent_it button"><img src="'.plugin_dir_url( __FILE__ ).'views/img/b4y.png" class="b4y-car" alt=""> '.__( 'Envoyer avec Bring4You', 'b4y' ).'</a>';94 }95 else96 {97 echo __( 'Tâche créée chez Bring4You', 'b4y' );98 }99 break;100 }101 }102 103 add_action( 'add_meta_boxes', 'add_shop_order_meta_box' );104 function add_shop_order_meta_box() {105 add_meta_box(106 'b4y_send',107 __( 'Bring4You', 'b4y' ),108 'shop_order_display_callback',109 'shop_order'110 );111 }112 113 function shop_order_display_callback( $post ) {114 $id = $post->ID;115 116 $current_order = wc_get_order($id);117 118 $value = get_post_meta( $id, 'b4y_send', true );119 120 if($current_order->shipping_city != '')121 {122 $address = $current_order->shipping_address_1.' ';123 $address .= $current_order->shipping_address_2.' ';124 $address .= $current_order->shipping_postcode.' ';125 $address .= $current_order->shipping_city.' ';126 $address .= $current_order->shipping_country.' ';127 }128 else129 {130 $address = $current_order->billing_address_1.' ';131 $address .= $current_order->billing_address_2.' ';132 $address .= $current_order->billing_postcode.' ';133 $address .= $current_order->billing_city.' ';134 $address .= $current_order->billing_country.' ';135 }136 137 echo '<div id="popupChoose_'.$id.'" class="b4y-modal">138 <div class="b4y-modal-content">139 <span class="b4y-close">×</span>140 <div>141 <h3>'.__( 'Envoyer votre colis avec Bring4You').'</h3>142 <p>'.__( 'Merci de valider l\'adresse de votre destinataire en sélectionnant l\'adresse correcte dans la liste, puis cliquez sur valider pour procéder à l\'envoi de la demande').'</p>143 <input type="text" autocomplete="no" name="b4y_to_adresse" id="b4y_to_adresse" value="'.$address.'">144 <input type="hidden" name="b4y_to_adresse_longitude" id="b4y_to_adresse_longitude" value="" >145 <input type="hidden" name="b4y_to_adresse_latitude" id="b4y_to_adresse_latitude" value="">146 <input type="hidden" name="b4y_estimation" id="b4y_estimation" value="">147 <div id="select_box_wrapper">148 <div id="b4y_select_address"></div>149 </div>150 <textarea name="b4y_description" id="b4y_description" placeholder="'.__( 'Spécification de votre envoi.').'"></textarea>151 <br/>152 <div id="b4y_result_estimation"></div>153 <br/>154 <a href="#" id="b4y_sent_it_now_'.$id.'" data-post-id="'.$id.'" data-address="" data-latitude="" data-longitude="" class="button hideonfirst b4y_sent_it_now">'.__( 'Envoyer', 'b4y' ).'</a>155 </div>156 </div>157 </div>';158 echo '<div id="b4y_result"></div>';159 if(!$value)160 {161 echo '<a href="#" id="b4y_sent_it_'.$id.'" data-post-id="'.$id.'" class="b4y_sent_it button"><img src="'.plugin_dir_url( __FILE__ ).'views/img/b4y.png" class="b4y-car" alt=""> '.__( 'Envoyer avec Bring4You', 'b4y' ).'</a>';162 }163 else164 {165 echo __( 'Tâche créée chez Bring4You', 'b4y' );166 }167 }168 169 add_action( 'wp_ajax_b4y_send_it', 'b4y_send_it' );170 add_action( 'wp_ajax_nopriv_b4y_send_it', 'b4y_send_it' );171 add_action( 'wp_ajax_b4y_estimationadmin', 'b4y_estimationadmin' );172 add_action( 'wp_ajax_nopriv_b4y_estimationadmin', 'b4y_estimationadmin' );173 174 function b4y_send_it() {175 $post_id = intval( $_POST['post_id'] );176 177 $to = array();178 $to['address'] = $_POST['address'];179 $to['latitude'] = $_POST['latitude'];180 $to['longitude'] = $_POST['longitude'];181 182 $description = $_POST['description'];183 184 $price = $_POST['price'];185 186 $response = B4Y_task_creation($post_id,$to,$price,$description);187 188 $responseArray = json_decode($response,true);189 190 if(isset($responseArray['statusCode']) && $responseArray['statusCode'] == 400)191 {192 $details = $responseArray['details'][0];193 194 $message = array();195 $message[] = 'error';196 $message[] = $details;197 198 echo json_encode($message);199 wp_die();200 }201 else202 {203 update_post_meta($post_id, 'b4y_send', 'true' );204 205 $message = array();206 $message[] = 'ok';207 $message[] = $response;208 209 echo json_encode($message);210 211 wp_die();212 }213 }214 215 function b4y_estimationadmin() {216 $post_id = intval( $_POST['post_id'] );217 218 $current_order = wc_get_order($post_id);219 220 $to = array();221 $to['address'] = $_POST['address'];222 223 $from = array();224 $from['address'] = get_option('b4y_plugin_setting_adresse');225 226 $totalvolume = 0;227 $totalweight = 0;228 229 $items = array();230 231 foreach ( $current_order->get_items() as $item_id => $item ) {232 $product = $item->get_product();233 234 $weight = $product->get_weight();235 $width = $product->get_width();236 $height = $product->get_height();237 $length = $product->get_length();238 $quantity = $item->get_quantity();239 240 $volume = $quantity * ($width*$height*$length);241 $totalvolume = $totalvolume + $volume;242 243 $weight = $quantity * $weight;244 $totalweight = $totalweight + $weight;245 }246 247 $arrival = urlencode(sanitize_text_field($to['address']));248 $departure = urlencode(sanitize_text_field($from['address']));249 250 $url = "https://bring4you.com/external-api/v1/priceEstimation?";251 252 $weight = round(wc_get_weight( $totalweight,'kg'));253 254 $url = $url."weight=".$totalweight."&";255 256 $url = $url."volume=".$totalvolume."&";257 258 $url = $url."origin_city=".$departure."&";259 260 $url = $url."destination_city=".$arrival."&";261 262 $response = wp_remote_get($url,array('sslverify' => FALSE));263 $body = wp_remote_retrieve_body($response);264 265 // convert response266 $resultArray = json_decode($body,true);267 268 $price = $resultArray['value'];269 echo round(substr($price, 0, -1));270 }271 272 add_action( 'admin_footer', 'b4y_sent_it_script' );273 function b4y_sent_it_script() {274 ?>275 <script>276 jQuery(document).ready(function ($) {277 278 // Get the popup279 var modal = jQuery(".b4y-modal");280 281 var finalsend = jQuery(".hideonfirst");282 283 // Get the <span> element that closes the modal284 var span = jQuery(".b4y-close")[0];285 286 // When the user clicks on <span> (x), close the modal287 span.onclick = function() {288 modal.hide();289 }290 291 // When the user clicks anywhere outside of the modal, close it292 window.onclick = function(event) {293 if (event.target == modal) {294 modal.hide();295 }296 }297 298 jQuery('.b4y_sent_it').click(function () {299 var post_id = jQuery(this).attr('data-post-id');300 301 finalsend.hide();302 jQuery("#popupChoose_"+post_id).show();303 });304 305 jQuery('.b4y_sent_it_now').click(function () {306 var post_id = jQuery(this).attr('data-post-id');307 var address = jQuery(this).attr('data-address');308 var latitude = jQuery(this).attr('data-latitude');309 var longitude = jQuery(this).attr('data-longitude');310 var description = jQuery("#b4y_description").val();311 var price = jQuery("#b4y_estimation").val();312 313 send_it(post_id, address, latitude, longitude,price,description);314 });315 });316 317 function send_it(post_id, address, latitude, longitude,price,description)318 {319 var data = {320 'action': 'b4y_send_it',321 'post_id': post_id,322 'address': address,323 'latitude': latitude,324 'longitude': longitude,325 'description':description,326 'price':price327 };328 329 jQuery.post(ajaxurl, data, function (response) {330 console.log( "Result:", response );331 var result = JSON.parse(response);332 var firstElement = result.shift();333 334 if(firstElement == "error")335 {336 var message = result.shift();337 alert('Erreur lors de l\'enregistrement sur Bring4You : ' + JSON.stringify(message));338 }339 else {340 jQuery("#b4y_result").html('Votre demande d\'envoi a été correctement envoyé');341 alert('Votre demande d\'envoi a été correctement envoyé');342 jQuery(".b4y-modal").hide();343 jQuery("#b4y_sent_it_" + post_id).hide();344 }345 346 347 });348 }349 350 jQuery('#b4y_to_adresse').keyup(function () {351 autocomplete_addess();352 });353 354 function autocomplete_addess()355 {356 jQuery.ajax({357 url: "https://pelias.bring4you.com/v1/autocomplete",358 method: "GET",359 dataType: "json",360 data: {361 "text": jQuery('#b4y_to_adresse').val(),362 },363 success: function( data, status, jqxhr ){364 //console.log( "Request received:", data );365 var selectHTML = '<select id="b4y_select_address_select" c size="10" style="width: 50%;max-width:50%;">';366 367 //console.log( "Collected:", data.features );368 369 for (var key in data.features)370 {371 var b4y_class = 'b4y_select_address_selected';372 if(jQuery('#b4y_to_adresse').val() == data.features[key].properties.label)373 b4y_class += ' b4y_select_address_selected_on';374 selectHTML +='<option value="'+data.features[key].properties.id+'" data-label="'+data.features[key].properties.label+'" data-long="'+data.features[key].geometry.coordinates[0]+'" data-lat="'+data.features[key].geometry.coordinates[1]+'" class="'+b4y_class+'">'+data.features[key].properties.label+'</option>';375 }376 377 selectHTML +='</select>';378 379 jQuery('#b4y_select_address').html(selectHTML);380 },381 error: function( jqxhr, status, error ){382 console.log( "Something went wrong!" );383 }384 });385 }386 387 jQuery('body').on('click','.b4y_select_address_selected', function () {388 var label = jQuery(this).attr('data-label');389 var longitude = jQuery(this).attr('data-long');390 var latitude = jQuery(this).attr('data-lat');391 var finalsend = jQuery(".hideonfirst");392 var post_id = jQuery('.b4y_sent_it_now').attr('data-post-id');393 394 jQuery('#b4y_to_adresse').val(label);395 jQuery('#b4y_to_adresse_latitude').val(latitude);396 jQuery('#b4y_to_adresse_longitude').val(longitude);397 398 jQuery('#b4y_select_address').html('');399 400 jQuery("#b4y_sent_it_now_" + post_id).attr('data-address',label);401 jQuery("#b4y_sent_it_now_" + post_id).attr('data-latitude',latitude);402 jQuery("#b4y_sent_it_now_" + post_id).attr('data-longitude',longitude);403 404 var data = {405 'action': 'b4y_estimationadmin',406 'post_id': post_id,407 'address': label408 };409 410 jQuery.post(ajaxurl, data, function (response) {411 console.log( "Estimate B4Y:", response );412 jQuery('#b4y_estimation').val(response);413 jQuery('#b4y_result_estimation').html("Estimation du tarif : " + response + " €");414 });415 416 finalsend.show();417 });418 </script>419 420 <?php421 }422 423 // END - Add B4Y field to Orders424 425 function B4Y_task_creation($post_id,$to,$price,$description) {426 $curl = curl_init();427 428 $current_order = wc_get_order($post_id);429 430 $key = get_option('b4y_plugin_setting_key');431 432 $dev = false;433 434 $items = array();435 436 foreach ( $current_order->get_items() as $item_id => $item ) {437 $product = $item->get_product();438 439 $weight = $product->get_weight();440 $width = $product->get_width();441 $height = $product->get_height();442 $length = $product->get_length();443 $quantity = $item->get_quantity();444 $name = $product->get_name();445 446 $items[] = array(447 'name' => $name,448 'quantity' => (int)$quantity,449 'weight' => (float)$weight,450 'dimension' => array('width' => (float)$width, 'length' => (float)$length, 'height' => (float)$height)451 );452 }453 454 $from = array();455 $from['address'] = get_option('b4y_plugin_setting_adresse');456 $from['latitude'] = get_option('b4y_plugin_setting_adresse_latitude');457 $from['longitude'] = get_option('b4y_plugin_setting_adresse_longitude');458 459 $from = array('Address' => $from['address'],'lat' => $from['latitude'],'lng' => $from['longitude']);460 $to = array('Address' => $to['address'],'lat' => $to['latitude'],'lng' => $to['longitude']);461 462 $bonus = array(463 'value' => $price,464 'currency' => "EUR",465 );466 467 $externalOrderId = $current_order->get_id();468 469 if($key == 'def28227-d98e-4800-b777-2725a24bcece')470 {471 $dev = true;472 }473 474 $json = '{"dev":'.['false', 'true'][$dev].',"items":'.json_encode($items).',"fromAddress":"'.$from['Address'].'","fromPlace":{"location":{"lat":'.$from['lat'].',"lng":'.$from['lng'].'}},"description":"'.$description.'","toAddress":"'.$to['Address'].'","toPlace":{"location":{"lat":'.$to['lat'].',"lng":'.$to['lng'].'}},"bonus":{"value":"'.$bonus['value'].'","currency":"'.$bonus['currency'].'"},"externalOrderId": "'.$externalOrderId.'"}';475 476 curl_setopt_array($curl, [477 CURLOPT_URL => "https://bring4you.com/external-api/v1/tasks",478 CURLOPT_RETURNTRANSFER => true,479 CURLOPT_ENCODING => "",480 CURLOPT_MAXREDIRS => 10,481 CURLOPT_TIMEOUT => 30,482 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,483 CURLOPT_CUSTOMREQUEST => "POST",484 CURLOPT_POSTFIELDS => $json,485 CURLOPT_HTTPHEADER => [486 "Content-Type: application/json",487 "X-Api-Key: ".$key488 ],489 ]);490 491 $response = curl_exec($curl);492 493 $err = curl_error($curl);494 495 curl_close($curl);496 497 if ($err) {498 return $json;499 } else {500 return $response;501 }502 }503 72 504 73 function B4Y_shipping_rate_cost_calculation( $rates, $package ) { … … 801 370 register_setting( 'b4y_plugin_options', 'b4y_plugin_setting_cats'); 802 371 register_setting( 'b4y_plugin_options', 'b4y_plugin_setting_comm'); 803 register_setting( 'b4y_plugin_options', 'b4y_plugin_setting_key');804 372 } 805 373
Note: See TracChangeset
for help on using the changeset viewer.