Changeset 2810974
- Timestamp:
- 11/03/2022 12:15:12 PM (3 years ago)
- Location:
- bring4you/trunk
- Files:
-
- 6 edited
-
README.txt (modified) (2 diffs)
-
admin/css/bring4you-admin.css (modified) (2 diffs)
-
admin/partials/bring4you-admin-display.php (modified) (4 diffs)
-
bring4you.php (modified) (6 diffs)
-
class/B4Y-shipping.php (modified) (2 diffs)
-
public/partials/bring4you-public-display.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bring4you/trunk/README.txt
r2791750 r2810974 2 2 Contributors: bring4you 3 3 Donate link: http://bring4you.com/ 4 Tags: transport, colis, volumineux, encombrants, meuble, deux-roue, moto, scooter, canape, pas cher, economique, assurance , encombrant, ecommerce4 Tags: transport, colis, volumineux, encombrants, meuble, deux-roue, moto, scooter, canape, pas cher, economique, assurance 5 5 Requires at least: 4.0.1 6 6 Requires PHP: 7.0 7 Tested up to: 5. 97 Tested up to: 5.8 8 8 Stable tag: 4.3 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html 11 11 12 Augmentez vos ventes d’objets lourds ou volumineux de 40% en proposant une livraison économique, efficace et écologique. 12 Module permettant d'ajouter le transporteur Bring4You à votre installation Woocommerce 13 13 14 14 == Description == 15 15 16 = Nouveau Bring4You - la livraison de colis encombrants pour tous. = 17 18 Bring4You, c’est… 19 20 = UN ACCÉLÉRATEUR = 21 22 = Augmentez vos ventes d’encombrants de 40% = 23 Boostez vos ventes de colis volumineux tout en gagnant du temps. Proposez des prix très compétitifs sur vos frais de port grâce à notre réseau et notre technologie d’optimisation des flux. Vous pouvez obtenir des tarifs 3 fois moins chers qu’avec les acteurs traditionnels. Ne loupez aucune vente en donnant un maximum de choix à vos clients. 24 25 = Solution ecommerce = 26 En quelques clics, vous permettez à vos clients de bénéficier d’une nouvelle solution de livraison moins chère et plus rapide tout en garantissant la livraison. 27 28 = Portée locale, régionale et nationale = 29 La multiplicité des transporteurs locaux complexifie la lisibilité de l’offre. Bring4You offre une solution unique et uniforme qui atteint 90 % de tout le territoire français. 30 31 = Tous les transporteurs sur une seule plateforme = 32 Avec plus de 10 000 conducteurs répartis dans toute la France, notre réseau flexible de véhicules, utilitaires ou camionnette peut répondre à une demande variable pour des articles de toutes tailles. 33 34 = Livraisons urgentes sous 24h = 35 Notre solution en ligne permet aux distributeurs et revendeurs de faire évoluer plus facilement une option de livraison supplémentaire pour répondre à tous les besoins des clients. 36 37 Vous avez des besoins particuliers ? Nous avons une solution alliant rapidité, flexibilité et compétitivité pour chacun de vos besoins : 38 *Livraison du premier et du dernier kilomètre ; 39 *Solution de tournée ; 40 *Achetez en ligne, livrez depuis le magasin ; 41 *Expedition urgente ; 42 *Gestion des stocks ; 43 *Retours et logistique inverse ; 44 *Groupage de vos envoi ; 45 46 = UN SEUL SITE = 47 Vous en avez assez de payer très cher vos livraisons de colis volumineux ou de ne pas trouver de solution ? Vous en avez assez des opérations manuelles pour gérer vos envois de colis ? Avec Bring4You c’est fini, gagnez du temps tous les jours grâce à notre solution d’automatisation et de suivi de vos colis. 48 49 50 Bref, vous pouvez expédier vos colis volumineux EN QUELQUES CLICS. 51 52 Le module permet de : 53 *Estimer les frais de port 54 *Ajouter les frais de port au panier 55 *Trouver un transporteur automatiquement 56 *Bénéficier d’un SAV de 3 mois 57 58 59 = UNE ASSURANCE = 60 Et si le transporteur égare ou casse mon envoi ? Avec notre assurance, pas de panique en cas de perte ou de vol, vous êtes remboursés de la valeur du colis. 61 62 = UN SEUL CONTACT = 63 Vous avez une question et n’avez pas le temps de rester en attente auprès des standards téléphoniques de chaque transporteur ? 64 Là encore Bring4You s’occupe de tout : un seul Service client en France et en Europe pour toutes vos questions sur l’expédition. 65 66 C’est parti ? 67 68 69 [S'abonner à l'API](https://modules.bring4you.com/produit/module-wordpress-woocommerce/) 70 71 Envoyez colis en quelques clics grâce à notre version Pro. 72 La version pro permet de : 73 *Estimer les frais de port 74 *Ajouter les frais de port au panier 75 *Trouver un transporteur automatiquement 76 *Bénéficier d’un SAV de 3 mois 77 78 [youtube https://www.youtube.com/watch?v=gXUjqUoqJrU] 16 Le module Bring4You permet de livrer vos colis encombrants à moindre coût 79 17 80 18 == Installation == … … 82 20 1. Envoyer `bring4you.php` vers le répertoire `/wp-content/plugins/` ou directement avec WordPress 83 21 2. Activer le module dans le menu 'Plugins' de WordPress 84 3. Générez une clé d’API en vous abonnant à Bring4You pour Wordpress [Ici](https://modules.bring4you.com/produit/module-wordpress-woocommerce/) 85 4. Configurer le module avec la clé d’API reçue 86 5. Placer le shortcode '[b4y_estimation]' dans votre page produit. 22 3. Configurer le module 23 4. Placer le shortcode '[b4y_estimation]' dans votre page produit. 87 24 88 25 N'hésitez pas à suivre notre guide d'installation : 89 [Guide vidéo](https://stonly.com/guide/fr/integration-wordpress-b0oIbHd4Xl/Steps/) 26 https://stonly.com/guide/fr/integration-wordpress-b0oIbHd4Xl/Steps/ 90 27 91 28 Notre vidéo de démonstration : 92 [Démonstration vidéo](https://www.youtube.com/watch?v=zMofmyOcwq0) 29 https://www.youtube.com/watch?v=zMofmyOcwq0 93 30 94 31 == Frequently Asked Questions == -
bring4you/trunk/admin/css/bring4you-admin.css
r2599188 r2810974 1 / **1 /wp/** 2 2 * All of the CSS for your admin-specific functionality should be 3 3 * included in this file. … … 102 102 } 103 103 104 #b4y_to_adresse,#b4y_select_address_select { 104 #b4y_to_adresse, #b4y_select_address_select, #b4y_to_phone, #b4y_to_name, 105 #b4y_from_adresse, #b4y_select_from_address_select, #b4y_from_phone, #b4y_from_name { 105 106 width: 100% !important; 106 107 max-width: 100% !important; 108 margin-bottom:5px; 107 109 } 110 111 #validate_to { 112 background:#E7A03C !important; 113 color: #fff !important; 114 border: #fff !important; 115 } 116 117 #validate_from.valid { 118 background:#00ff00 !important; 119 color: #000 !important; 120 border: #000 !important; 121 } 122 #validate_to.valid { 123 background:#00ff00 !important; 124 color: #000 !important; 125 border: #000 !important; 126 } 127 128 .important-hightlight { 129 background : #e7a03cc4; 130 padding: 5px; 131 } -
bring4you/trunk/admin/partials/bring4you-admin-display.php
r2766844 r2810974 113 113 $commission = 0; 114 114 $cats = ''; 115 $key = ''; 116 $name = ''; 117 $phone = ''; 115 118 116 119 if(get_option('b4y_plugin_setting_adresse') != '') … … 123 126 $aide = get_option('b4y_plugin_setting_aide'); 124 127 $commission = get_option('b4y_plugin_setting_comm'); 128 $key = get_option('b4y_plugin_setting_key'); 125 129 $cats = get_option('b4y_plugin_setting_cats'); 130 $name = get_option('b4y_plugin_setting_sender_name'); 131 $phone = get_option('b4y_plugin_setting_sender_phone'); 126 132 } 127 133 ?> … … 133 139 134 140 <div class="form-wrapper"> 141 <div class="form-group"> 142 <label class="control-label col-lg-3"><?php _e('Clé API Bring4You', 'b4y'); ?></label> 143 <div class="b4y-editzone"> 144 <input type="text" name="b4y_plugin_setting_key" id="b4y_plugin_setting_key" value="<?php echo $key ?>" class="" style="width:50%"> 145 <p class="help-block"><?php _e('Saisir la clé API fournie par Bring4You', 'b4y'); ?></p> 146 </div> 147 </div> 148 135 149 <div class="form-group"> 136 150 <label class="control-label col-lg-3"><?php _e('Mode Production', 'b4y'); ?></label> … … 164 178 </div> 165 179 </div> 166 180 181 <div class="form-group"> 182 <label class="control-label col-lg-3"><?php _e('Nom de l\'expéditeur', 'b4y'); ?></label> 183 <div class="b4y-editzone"> 184 <div class="input-group"> 185 <input type="text" name="b4y_plugin_setting_sender_name" id="b4y_plugin_setting_sender_name" value="<?php echo $name ?>" class="" style="width:50%"> 186 </div> 187 <p class="help-block"><?php _e('Ce nom sera envoyé lors de la création de tâche chez Bring4You', 'b4y'); ?></p> 188 </div> 189 </div> 190 191 <div class="form-group"> 192 <label class="control-label col-lg-3"><?php _e('Téléphone de l\'expéditeur', 'b4y'); ?></label> 193 <div class="b4y-editzone"> 194 <div class="input-group"> 195 <input type="text" name="b4y_plugin_setting_sender_phone" id="b4y_plugin_setting_sender_phone" value="<?php echo $phone ?>" class="" style="width:50%"> 196 </div> 197 <p class="help-block"><?php _e('Ce téléphone sera envoyé lors de la création de tâche chez Bring4You', 'b4y'); ?></p> 198 </div> 199 </div> 200 167 201 <div class="form-group"> 168 202 <label class="control-label col-lg-3"><?php _e('Texte de l\'estimation', 'b4y'); ?></label> -
bring4you/trunk/bring4you.php
r2766844 r2810974 38 38 * Rename this for your plugin and update it as you release new versions. 39 39 */ 40 define( 'BRING4YOU_VERSION', '1. 1.0' );40 define( 'BRING4YOU_VERSION', '1.0.7' ); 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 Orders 76 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 else 96 { 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 else 129 { 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 $name = ''; 138 139 if($current_order->shipping_first_name != '' && $current_order->shipping_last_name != '') 140 { 141 $name = $current_order->shipping_first_name.' '; 142 $name .= $current_order->shipping_last_name; 143 } 144 else 145 { 146 $name = $current_order->billing_first_name.' '; 147 $name .= $current_order->billing_last_name; 148 } 149 150 $phone = ''; 151 152 if($current_order->shipping_phone != '') 153 { 154 $phone = $current_order->shipping_phone; 155 } 156 else 157 { 158 $phone = $current_order->billing_phone; 159 } 160 161 $from_name = get_option('b4y_plugin_setting_sender_name'); 162 $from_phone = get_option('b4y_plugin_setting_sender_phone'); 163 $from_address = get_option('b4y_plugin_setting_adresse'); 164 $from_long = get_option('b4y_plugin_setting_adresse_longitude'); 165 $from_lat = get_option('b4y_plugin_setting_adresse_latitude'); 166 167 echo '<div id="popupChoose_'.$id.'" class="b4y-modal"> 168 <div class="b4y-modal-content"> 169 <span class="b4y-close">×</span> 170 <div> 171 <h3>'.__( 'Envoyer votre colis avec Bring4You').'</h3> 172 <p class="important-hightlight">⚠ '.__( '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> 173 <h4>Expéditeur</h4> 174 <input type="text" autocomplete="no" name="b4y_from_name" id="b4y_from_name" value="'.$from_name.'"> 175 <input type="text" autocomplete="no" name="b4y_from_phone" id="b4y_from_phone" value="'.$from_phone.'"> 176 <input type="text" autocomplete="no" name="b4y_from_adresse" id="b4y_from_adresse" value="'.$from_address.'"> 177 <input type="button" class="button button-primary valid" name="validate_from" id="validate_from" value="'.__( 'Valider adresse').'" /> 178 <input type="hidden" name="b4y_from_adresse_longitude" id="b4y_from_adresse_longitude" value="'.$from_long.'" > 179 <input type="hidden" name="b4y_from_adresse_latitude" id="b4y_from_adresse_latitude" value="'.$from_lat.'"> 180 <div id="select_from_box_wrapper"> 181 <div id="b4y_select_from_address"></div> 182 </div> 183 <h4>Destinataire</h4> 184 <input type="text" autocomplete="no" name="b4y_to_name" id="b4y_to_name" value="'.$name.'"> 185 <input type="text" autocomplete="no" name="b4y_to_phone" id="b4y_to_phone" value="'.$phone.'"> 186 <input type="text" autocomplete="no" name="b4y_to_adresse" id="b4y_to_adresse" value="'.$address.'"> 187 <input type="button" class="button button-primary" name="validate_to" id="validate_to" value="'.__( 'Valider adresse').'" /> 188 <input type="hidden" name="b4y_to_adresse_longitude" id="b4y_to_adresse_longitude" value="" > 189 <input type="hidden" name="b4y_to_adresse_latitude" id="b4y_to_adresse_latitude" value=""> 190 <div id="select_box_wrapper"> 191 <div id="b4y_select_address"></div> 192 </div> 193 <textarea name="b4y_description" id="b4y_description" placeholder="'.__( 'Spécification de votre envoi.').'"></textarea> 194 <br/> 195 <input type="hidden" name="b4y_estimation" id="b4y_estimation" value=""> 196 <div id="b4y_result_estimation"></div> 197 <br/> 198 <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> 199 </div> 200 </div> 201 </div>'; 202 echo '<div id="b4y_result"></div>'; 203 if(!$value) 204 { 205 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>'; 206 } 207 else 208 { 209 echo __( 'Tâche créée chez Bring4You', 'b4y' ); 210 } 211 } 212 213 add_action( 'wp_ajax_b4y_send_it', 'b4y_send_it' ); 214 add_action( 'wp_ajax_nopriv_b4y_send_it', 'b4y_send_it' ); 215 add_action( 'wp_ajax_b4y_estimationadmin', 'b4y_estimationadmin' ); 216 add_action( 'wp_ajax_nopriv_b4y_estimationadmin', 'b4y_estimationadmin' ); 217 218 function b4y_send_it() { 219 $post_id = intval( $_POST['post_id'] ); 220 221 $to = array(); 222 $to['address'] = $_POST['address']; 223 $to['latitude'] = $_POST['latitude']; 224 $to['longitude'] = $_POST['longitude']; 225 $to['name'] = $_POST['name']; 226 $to['phone'] = $_POST['phone']; 227 228 $from = array(); 229 $from['address'] = $_POST['from_address']; 230 $from['latitude'] = $_POST['from_latitude']; 231 $from['longitude'] = $_POST['from_longitude']; 232 $from['name'] = $_POST['from_name']; 233 $from['phone'] = $_POST['from_phone']; 234 235 236 $description = $_POST['description']; 237 238 $price = $_POST['price']; 239 240 $response = B4Y_task_creation($post_id,$to,$from,$price,$description); 241 242 $responseArray = json_decode($response,true); 243 244 if(isset($responseArray['statusCode']) && $responseArray['statusCode'] == 400) 245 { 246 $details = $responseArray['details'][0]; 247 248 $message = array(); 249 $message[] = 'error'; 250 $message[] = $details; 251 252 echo json_encode($message); 253 wp_die(); 254 } 255 else 256 { 257 update_post_meta($post_id, 'b4y_send', 'true' ); 258 259 $message = array(); 260 $message[] = 'ok'; 261 $message[] = $response; 262 263 echo json_encode($message); 264 265 wp_die(); 266 } 267 } 268 269 function b4y_estimationadmin() { 270 $post_id = intval( $_POST['post_id'] ); 271 272 $current_order = wc_get_order($post_id); 273 274 $to = array(); 275 $to['address'] = $_POST['address']; 276 277 $from = array(); 278 $from['address'] = $_POST['address_from']; 279 280 $totalvolume = 0; 281 $totalweight = 0; 282 283 $items = array(); 284 285 foreach ( $current_order->get_items() as $item_id => $item ) { 286 $product = $item->get_product(); 287 288 $weight = $product->get_weight(); 289 $width = $product->get_width(); 290 $height = $product->get_height(); 291 $length = $product->get_length(); 292 $quantity = $item->get_quantity(); 293 294 $volume = $quantity * ($width*$height*$length); 295 $totalvolume = $totalvolume + $volume; 296 297 $weight = $quantity * $weight; 298 $totalweight = $totalweight + $weight; 299 } 300 301 $arrival = urlencode(sanitize_text_field($to['address'])); 302 $departure = urlencode(sanitize_text_field($from['address'])); 303 304 $url = "https://bring4you.com/external-api/v1/priceEstimation?"; 305 306 $weight = round(wc_get_weight( $totalweight,'kg')); 307 308 $url = $url."weight=".$totalweight."&"; 309 310 $url = $url."volume=".$totalvolume."&"; 311 312 $url = $url."origin_city=".$departure."&"; 313 314 $url = $url."destination_city=".$arrival."&"; 315 316 317 $key = get_option('b4y_plugin_setting_key'); 318 319 if($key == 'def28227-d98e-4800-b777-2725a24bcece') 320 { 321 $dev = true; 322 } 323 324 $curl = curl_init(); 325 326 curl_setopt_array($curl, [ 327 CURLOPT_URL => $url, 328 CURLOPT_RETURNTRANSFER => true, 329 CURLOPT_ENCODING => "", 330 CURLOPT_MAXREDIRS => 10, 331 CURLOPT_TIMEOUT => 30, 332 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 333 CURLOPT_CUSTOMREQUEST => "GET", 334 CURLOPT_HTTPHEADER => [ 335 "Content-Type: application/json", 336 "X-Api-Key: ".$key 337 ], 338 ]); 339 340 $response = curl_exec($curl); 341 342 $err = curl_error($curl); 343 344 curl_close($curl); 345 346 //$response = wp_remote_get($url,array('sslverify' => FALSE)); 347 //$body = wp_remote_retrieve_body($response); 348 349 // convert response 350 $resultArray = json_decode($response,true); 351 352 $price = $resultArray['value']; 353 echo round($price); 354 wp_die(); 355 } 356 357 add_action( 'admin_footer', 'b4y_sent_it_script' ); 358 function b4y_sent_it_script() { 359 ?> 360 <script> 361 jQuery(document).ready(function ($) { 362 363 // Get the popup 364 var modal = jQuery(".b4y-modal"); 365 366 var finalsend = jQuery(".hideonfirst"); 367 368 // Get the <span> element that closes the modal 369 var span = jQuery(".b4y-close")[0]; 370 371 // When the user clicks on <span> (x), close the modal 372 span.onclick = function() { 373 modal.hide(); 374 } 375 376 // When the user clicks anywhere outside of the modal, close it 377 window.onclick = function(event) { 378 if (event.target == modal) { 379 modal.hide(); 380 } 381 } 382 383 jQuery('.b4y_sent_it').click(function () { 384 var post_id = jQuery(this).attr('data-post-id'); 385 386 finalsend.hide(); 387 jQuery("#popupChoose_"+post_id).show(); 388 }); 389 390 jQuery('.b4y_sent_it_now').click(function () { 391 var post_id = jQuery(this).attr('data-post-id'); 392 var address = jQuery(this).attr('data-address'); 393 var latitude = jQuery(this).attr('data-latitude'); 394 var longitude = jQuery(this).attr('data-longitude'); 395 var name = jQuery("#b4y_to_name").val(); 396 var phone = jQuery("#b4y_to_phone").val(); 397 398 var from_address = jQuery("#b4y_from_adresse").val(); 399 var from_longitude = jQuery("#b4y_from_adresse_longitude").val(); 400 var from_latitude = jQuery("#b4y_from_adresse_latitude").val(); 401 var from_name = jQuery("#b4y_from_name").val(); 402 var from_phone = jQuery("#b4y_from_phone").val(); 403 404 var description = jQuery("#b4y_description").val(); 405 var price = jQuery("#b4y_estimation").val(); 406 407 send_it(post_id, address, latitude, longitude,price,description,name,phone,from_address,from_longitude,from_latitude,from_name,from_phone); 408 }); 409 }); 410 411 function send_it(post_id, address, latitude, longitude,price,description,name,phone,from_address,from_longitude,from_latitude,from_name,from_phone) 412 { 413 var data = { 414 'action': 'b4y_send_it', 415 'post_id': post_id, 416 'address': address, 417 'latitude': latitude, 418 'longitude': longitude, 419 'description':description, 420 'price':price, 421 'name':name, 422 'phone':phone, 423 'from_address':from_address, 424 'from_longitude':from_longitude, 425 'from_latitude':from_latitude, 426 'from_name':from_name, 427 'from_phone':from_phone, 428 429 }; 430 431 jQuery.post(ajaxurl, data, function (response) { 432 console.log( "Result:", response ); 433 var result = JSON.parse(response); 434 var firstElement = result.shift(); 435 436 if(firstElement == "error") 437 { 438 var message = result.shift(); 439 alert('Erreur lors de l\'enregistrement sur Bring4You : ' + JSON.stringify(message)); 440 } 441 else { 442 jQuery("#b4y_result").html('Votre demande d\'envoi a été correctement envoyé'); 443 alert('Votre demande d\'envoi a été correctement envoyé'); 444 jQuery(".b4y-modal").hide(); 445 jQuery("#b4y_sent_it_" + post_id).hide(); 446 } 447 448 449 }); 450 } 451 452 jQuery('#validate_to').click(function () { 453 autocomplete_addess(); 454 }); 455 456 jQuery('#validate_from').click(function () { 457 autocomplete_addess_from(); 458 }); 459 460 jQuery('#b4y_to_adresse').keyup(function () { 461 autocomplete_addess(); 462 }); 463 464 jQuery('#b4y_from_adresse').keyup(function () { 465 autocomplete_addess_from(); 466 }); 467 468 function autocomplete_addess() 469 { 470 jQuery.ajax({ 471 url: "https://pelias.bring4you.com/v1/autocomplete", 472 method: "GET", 473 dataType: "json", 474 data: { 475 "text": jQuery('#b4y_to_adresse').val(), 476 }, 477 success: function( data, status, jqxhr ){ 478 //console.log( "Request received:", data ); 479 var selectHTML = '<select id="b4y_select_address_select" c size="10" style="width: 50%;max-width:50%;">'; 480 481 //console.log( "Collected:", data.features ); 482 483 for (var key in data.features) 484 { 485 var b4y_class = 'b4y_select_address_selected'; 486 if(jQuery('#b4y_to_adresse').val() == data.features[key].properties.label) 487 b4y_class += ' b4y_select_address_selected_on'; 488 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>'; 489 } 490 491 selectHTML +='</select>'; 492 493 jQuery('#b4y_select_address').html(selectHTML); 494 }, 495 error: function( jqxhr, status, error ){ 496 console.log( "Something went wrong!" ); 497 } 498 }); 499 } 500 501 function autocomplete_addess_from() 502 { 503 jQuery.ajax({ 504 url: "https://pelias.bring4you.com/v1/autocomplete", 505 method: "GET", 506 dataType: "json", 507 data: { 508 "text": jQuery('#b4y_from_adresse').val(), 509 }, 510 success: function( data, status, jqxhr ){ 511 //console.log( "Request received:", data ); 512 var selectHTML = '<select id="b4y_select_from_address_select" c size="10" style="width: 50%;max-width:50%;">'; 513 514 //console.log( "Collected:", data.features ); 515 516 for (var key in data.features) 517 { 518 var b4y_class = 'b4y_select_from_address_selected'; 519 if(jQuery('#b4y_from_adresse').val() == data.features[key].properties.label) 520 b4y_class += ' b4y_select_from_address_selected_on'; 521 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>'; 522 } 523 524 selectHTML +='</select>'; 525 526 jQuery('#b4y_select_from_address').html(selectHTML); 527 }, 528 error: function( jqxhr, status, error ){ 529 console.log( "Something went wrong!" ); 530 } 531 }); 532 } 533 534 jQuery('body').on('click','.b4y_select_from_address_selected', function () { 535 var label = jQuery(this).attr('data-label'); 536 var longitude = jQuery(this).attr('data-long'); 537 var latitude = jQuery(this).attr('data-lat'); 538 var finalsend = jQuery(".hideonfirst"); 539 var post_id = jQuery('.b4y_sent_it_now').attr('data-post-id'); 540 541 jQuery('#b4y_from_adresse').val(label); 542 jQuery('#b4y_from_adresse_latitude').val(latitude); 543 jQuery('#b4y_from_adresse_longitude').val(longitude); 544 545 jQuery('#b4y_select_from_address').html(''); 546 547 var data = { 548 'action': 'b4y_estimationadmin', 549 'post_id': post_id, 550 'address': jQuery('#b4y_to_adresse').val(), 551 'address_from': jQuery('#b4y_from_adresse').val() 552 }; 553 554 jQuery.post(ajaxurl, data, function (response) { 555 console.log( "Estimate B4Y:", response ); 556 jQuery('#b4y_estimation').val(response); 557 jQuery('#b4y_result_estimation').html("Estimation du tarif : " + response + " €"); 558 }); 559 }); 560 561 jQuery('body').on('click','.b4y_select_address_selected', function () { 562 var label = jQuery(this).attr('data-label'); 563 var longitude = jQuery(this).attr('data-long'); 564 var latitude = jQuery(this).attr('data-lat'); 565 var finalsend = jQuery(".hideonfirst"); 566 var post_id = jQuery('.b4y_sent_it_now').attr('data-post-id'); 567 568 jQuery('#b4y_to_adresse').val(label); 569 jQuery('#b4y_to_adresse_latitude').val(latitude); 570 jQuery('#b4y_to_adresse_longitude').val(longitude); 571 572 jQuery('#b4y_select_address').html(''); 573 574 jQuery("#b4y_sent_it_now_" + post_id).attr('data-address',label); 575 jQuery("#b4y_sent_it_now_" + post_id).attr('data-latitude',latitude); 576 jQuery("#b4y_sent_it_now_" + post_id).attr('data-longitude',longitude); 577 578 var data = { 579 'action': 'b4y_estimationadmin', 580 'post_id': post_id, 581 'address': jQuery('#b4y_to_adresse').val(), 582 'address_from': jQuery('#b4y_from_adresse').val() 583 }; 584 585 jQuery.post(ajaxurl, data, function (response) { 586 console.log( "Estimate B4Y:", response ); 587 jQuery('#b4y_estimation').val(response); 588 jQuery('#b4y_result_estimation').html("Estimation du tarif : " + response + " €"); 589 }); 590 591 jQuery('#validate_to').addClass('valid'); 592 593 finalsend.show(); 594 }); 595 </script> 596 597 <?php 598 } 599 600 // END - Add B4Y field to Orders 601 602 function B4Y_task_creation($post_id,$to,$from,$price,$description) { 603 $curl = curl_init(); 604 605 $current_order = wc_get_order($post_id); 606 607 $key = get_option('b4y_plugin_setting_key'); 608 609 $dev = false; 610 611 $items = array(); 612 613 foreach ( $current_order->get_items() as $item_id => $item ) { 614 $product = $item->get_product(); 615 616 $weight = $product->get_weight(); 617 $width = $product->get_width(); 618 $height = $product->get_height(); 619 $length = $product->get_length(); 620 $quantity = $item->get_quantity(); 621 $name = $product->get_name(); 622 623 $items[] = array( 624 'name' => $name, 625 'quantity' => (int)$quantity, 626 'weight' => (float)$weight, 627 'dimension' => array('width' => (float)$width, 'length' => (float)$length, 'height' => (float)$height) 628 ); 629 } 630 631 /*$from = array(); 632 $from['address'] = get_option('b4y_plugin_setting_adresse'); 633 $from['latitude'] = get_option('b4y_plugin_setting_adresse_latitude'); 634 $from['longitude'] = get_option('b4y_plugin_setting_adresse_longitude'); 635 $from['name'] = get_option('b4y_plugin_setting_sender_name'); 636 $from['phone'] = get_option('b4y_plugin_setting_sender_phone');*/ 637 638 $from = array('Address' => $from['address'],'lat' => $from['latitude'],'lng' => $from['longitude'],'name' => $from['name'],'phone' => $from['phone']); 639 $to = array('Address' => $to['address'],'lat' => $to['latitude'],'lng' => $to['longitude'],'name' => $to['name'],'phone' => $to['phone']); 640 641 $price = round($price/1.18); 642 643 $bonus = array( 644 'value' => $price, 645 'currency' => "EUR", 646 ); 647 648 $externalOrderId = $current_order->get_id(); 649 650 if($key == 'def28227-d98e-4800-b777-2725a24bcece') 651 { 652 $dev = true; 653 } 654 655 if($description != "") 656 $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'].'"},"removal":{"name":"'.$from['name'].'","phone":"'.$from['phone'].'"},"recipient":{"name":"'.$to['name'].'","phone":"'.$to['phone'].'"},"externalOrderId": "'.$externalOrderId.'"}'; 657 else 658 $json = '{"dev":'.['false', 'true'][$dev].',"items":'.json_encode($items).',"fromAddress":"'.$from['Address'].'","fromPlace":{"location":{"lat":'.$from['lat'].',"lng":'.$from['lng'].'}},"toAddress":"'.$to['Address'].'","toPlace":{"location":{"lat":'.$to['lat'].',"lng":'.$to['lng'].'}},"bonus":{"value":"'.$bonus['value'].'","currency":"'.$bonus['currency'].'"},"removal":{"name":"'.$from['name'].'","phone":"'.$from['phone'].'"},"recipient":{"name":"'.$to['name'].'","phone":"'.$to['phone'].'"},"externalOrderId": "'.$externalOrderId.'"}'; 659 660 curl_setopt_array($curl, [ 661 CURLOPT_URL => "https://bring4you.com/external-api/v1/tasks", 662 CURLOPT_RETURNTRANSFER => true, 663 CURLOPT_ENCODING => "", 664 CURLOPT_MAXREDIRS => 10, 665 CURLOPT_TIMEOUT => 30, 666 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 667 CURLOPT_CUSTOMREQUEST => "POST", 668 CURLOPT_POSTFIELDS => $json, 669 CURLOPT_HTTPHEADER => [ 670 "Content-Type: application/json", 671 "X-Api-Key: ".$key 672 ], 673 ]); 674 675 $response = curl_exec($curl); 676 677 $err = curl_error($curl); 678 679 curl_close($curl); 680 681 if ($err) { 682 return $json; 683 } else { 684 return $response; 685 } 686 } 72 687 73 688 function B4Y_shipping_rate_cost_calculation( $rates, $package ) { … … 85 700 86 701 function B4Y_estimation_result() { 87 $weight = sanitize_text_field($_POST['weight']);702 $weight = sanitize_text_field($_POST['weight']); 88 703 $width = sanitize_text_field($_POST['width']); 89 704 $height = sanitize_text_field($_POST['height']); … … 160 775 //file_put_contents(plugin_dir_path( __FILE__ ).'/log.txt', $url."\r\n", FILE_APPEND); 161 776 777 $key = get_option('b4y_plugin_setting_key'); 778 779 if($key == 'def28227-d98e-4800-b777-2725a24bcece') 780 { 781 $dev = true; 782 } 783 784 $curl = curl_init(); 785 786 curl_setopt_array($curl, [ 787 CURLOPT_URL => $url, 788 CURLOPT_RETURNTRANSFER => true, 789 CURLOPT_ENCODING => "", 790 CURLOPT_MAXREDIRS => 10, 791 CURLOPT_TIMEOUT => 30, 792 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 793 CURLOPT_CUSTOMREQUEST => "GET", 794 CURLOPT_HTTPHEADER => [ 795 "Content-Type: application/json", 796 "X-Api-Key: ".$key 797 ], 798 ]); 799 800 $response = curl_exec($curl); 801 802 $err = curl_error($curl); 803 804 curl_close($curl); 805 162 806 // make request 163 807 // make request 164 $response = wp_remote_get($url,array('sslverify' => FALSE));165 $body = wp_remote_retrieve_body($response);808 //$response = wp_remote_get($url,array('sslverify' => FALSE)); 809 //$body = wp_remote_retrieve_body($response); 166 810 167 811 // convert response 168 $resultArray = json_decode($ body,true);812 $resultArray = json_decode($response,true); 169 813 170 814 // If we manage error directly from wordpress … … 290 934 $price = ($price * (100 + $percent))/100; 291 935 292 echo $estimationText." : ".round($price).' '.$resultArray['currency']; 936 if(isset($resultArray['value']) && $price != 0) 937 echo $estimationText." : ".round($price).' '.$resultArray['currency']; 938 939 if($response == "Unauthorized") 940 echo "Il faut saisir une clé API valide dans l'administration"; 941 293 942 } 294 943 } … … 370 1019 register_setting( 'b4y_plugin_options', 'b4y_plugin_setting_cats'); 371 1020 register_setting( 'b4y_plugin_options', 'b4y_plugin_setting_comm'); 1021 register_setting( 'b4y_plugin_options', 'b4y_plugin_setting_key'); 1022 register_setting( 'b4y_plugin_options', 'b4y_plugin_setting_sender_name'); 1023 register_setting( 'b4y_plugin_options', 'b4y_plugin_setting_sender_phone'); 372 1024 } 373 1025 -
bring4you/trunk/class/B4Y-shipping.php
r2694699 r2810974 95 95 $quantity = $product['quantity']; 96 96 97 $totalvolume = $totalvolume + (($width * $height * $depth) * $quantity); 98 $totalweight = $totalweight + ($weight * $quantity); 97 if(is_numeric($width) && is_numeric($height) && is_numeric($depth) && is_numeric($quantity)) 98 $totalvolume = $totalvolume + (($width * $height * $depth) * $quantity); 99 100 if(is_numeric($weight) && is_numeric($quantity)) 101 $totalweight = $totalweight + ($weight * $quantity); 99 102 } 100 103 … … 153 156 } 154 157 158 $key = get_option('b4y_plugin_setting_key'); 159 160 if($key == 'def28227-d98e-4800-b777-2725a24bcece') 161 { 162 $dev = true; 163 } 164 165 $curl = curl_init(); 166 167 curl_setopt_array($curl, [ 168 CURLOPT_URL => $url, 169 CURLOPT_RETURNTRANSFER => true, 170 CURLOPT_ENCODING => "", 171 CURLOPT_MAXREDIRS => 10, 172 CURLOPT_TIMEOUT => 30, 173 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 174 CURLOPT_CUSTOMREQUEST => "GET", 175 CURLOPT_HTTPHEADER => [ 176 "Content-Type: application/json", 177 "X-Api-Key: ".$key 178 ], 179 ]); 180 181 $response = curl_exec($curl); 182 183 $err = curl_error($curl); 184 185 curl_close($curl); 186 155 187 // make request 156 188 // make request 157 $response = wp_remote_get($url,array('sslverify' => FALSE));158 $body = wp_remote_retrieve_body($response);189 //$response = wp_remote_get($url,array('sslverify' => FALSE)); 190 //$body = wp_remote_retrieve_body($response); 159 191 160 192 // convert response 161 $resultArray = json_decode($ body,true);193 $resultArray = json_decode($response,true); 162 194 163 195 // If we manage error directly from wordpress -
bring4you/trunk/public/partials/bring4you-public-display.php
r2599188 r2810974 27 27 $commission = get_option('b4y_plugin_setting_comm'); 28 28 29 $estimationok = false;29 $estimationok = true; 30 30 31 if( !empty($weight) && !empty($width) && !empty($height) && !empty($depth))32 $estimationok = true;31 if(empty($weight) || empty($width) || empty($height) || empty($depth)) 32 $estimationok = false; 33 33 34 34 if($prod == 1 && $estimationok) … … 60 60 elseif($prod == 1 && !$estimationok) 61 61 { 62 ?>62 ?> 63 63 64 <h2><?php _e('Estimation Bring4You non disponible','b4y'); ?></h2>64 <h2><?php _e('Estimation Bring4You non disponible','b4y'); ?></h2> 65 65 66 <?php 66 <?php 67 if(empty($weight)) 68 echo '<p>'._e('Le poids n\'est pas renseigné','b4y').'</p>'; 69 if(empty($width)) 70 echo '<p>'._e('La largeur n\'est pas renseignée','b4y').'</p>'; 71 if(empty($height)) 72 echo '<p>'._e('La hauteur n\'est pas renseignée','b4y').'</p>'; 73 if(empty($depth)) 74 echo '<p>'._e('La longueur n\'est pas renseignée','b4y').'</p>'; 67 75 } 68 76 ?>
Note: See TracChangeset
for help on using the changeset viewer.