Changeset 2987026
- Timestamp:
- 10/31/2023 08:47:21 PM (2 years ago)
- Location:
- shipbubble
- Files:
-
- 45 added
- 7 edited
-
tags/1.7.2 (added)
-
tags/1.7.2/admin (added)
-
tags/1.7.2/admin/css (added)
-
tags/1.7.2/admin/css/styles-wc.css (added)
-
tags/1.7.2/admin/index.php (added)
-
tags/1.7.2/admin/js (added)
-
tags/1.7.2/admin/js/ajax-create-shipment.js (added)
-
tags/1.7.2/admin/js/ajax-validate-address.js (added)
-
tags/1.7.2/admin/js/ajax-validate-auth.js (added)
-
tags/1.7.2/admin/woocommerce (added)
-
tags/1.7.2/admin/woocommerce/async-create-shipment.php (added)
-
tags/1.7.2/admin/woocommerce/async-validate-address.php (added)
-
tags/1.7.2/admin/woocommerce/enqueue-styles.php (added)
-
tags/1.7.2/admin/woocommerce/orders.php (added)
-
tags/1.7.2/admin/woocommerce/shipping-settings.php (added)
-
tags/1.7.2/admin/wordpress (added)
-
tags/1.7.2/admin/wordpress/async-validate-auth.php (added)
-
tags/1.7.2/admin/wordpress/index.php (added)
-
tags/1.7.2/admin/wordpress/settings-callback.php (added)
-
tags/1.7.2/admin/wordpress/settings-field-validation.php (added)
-
tags/1.7.2/admin/wordpress/settings-menu.php (added)
-
tags/1.7.2/admin/wordpress/settings-page.php (added)
-
tags/1.7.2/admin/wordpress/settings-register.php (added)
-
tags/1.7.2/includes (added)
-
tags/1.7.2/includes/constants.php (added)
-
tags/1.7.2/includes/core-methods.php (added)
-
tags/1.7.2/includes/endpoints.php (added)
-
tags/1.7.2/includes/index.php (added)
-
tags/1.7.2/index.php (added)
-
tags/1.7.2/languages (added)
-
tags/1.7.2/languages/index.php (added)
-
tags/1.7.2/license.txt (added)
-
tags/1.7.2/public (added)
-
tags/1.7.2/public/async-checkout-couriers.php (added)
-
tags/1.7.2/public/css (added)
-
tags/1.7.2/public/css/styles-wc.css (added)
-
tags/1.7.2/public/js (added)
-
tags/1.7.2/public/js/couriers-on-checkout.js (added)
-
tags/1.7.2/public/js/sweetalert2.min.js (added)
-
tags/1.7.2/public/woocommerce (added)
-
tags/1.7.2/public/woocommerce/checkout.php (added)
-
tags/1.7.2/public/woocommerce/enqueue-styles.php (added)
-
tags/1.7.2/readme.txt (added)
-
tags/1.7.2/shipbubble.php (added)
-
tags/1.7.2/uninstall.php (added)
-
trunk/admin/js/ajax-create-shipment.js (modified) (1 diff)
-
trunk/admin/woocommerce/async-create-shipment.php (modified) (3 diffs)
-
trunk/admin/woocommerce/orders.php (modified) (5 diffs)
-
trunk/includes/core-methods.php (modified) (4 diffs)
-
trunk/public/js/couriers-on-checkout.js (modified) (3 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/shipbubble.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shipbubble/trunk/admin/js/ajax-create-shipment.js
r2975160 r2987026 20 20 21 21 if (details.val() != '') { 22 let payload; 23 if (typeof JSON.parse(details.val()) == 'object') { 24 payload = JSON.parse(details.val()); 25 } else { 26 payload = JSON.parse(JSON.parse(details.val())); 27 } 22 28 23 const payload = JSON.parse(details.val());24 29 payload['order_id'] = wc_order_id.val(); 25 30 -
shipbubble/trunk/admin/woocommerce/async-create-shipment.php
r2975160 r2987026 37 37 if (!current_user_can('manage_options')) return; 38 38 39 // $shipmentPayload = $_POST['data'];40 39 $payload = array_map('sanitize_text_field', $_POST['data']['shipment']); 41 40 … … 44 43 $orderId = sanitize_text_field($shipmentPayload['order_id']); 45 44 46 $shipmentDetailsArray = get_post_meta($orderId, 'shipbubble_shipment_details'); 47 if (count($shipmentDetailsArray)) { 48 $shipment = json_decode($shipmentDetailsArray[0], true); 49 $shipment['admin_initiate_shipment_time'] = date('Y-m-d H:i:s'); 50 update_post_meta($orderId, 'shipbubble_shipment_details', sanitize_text_field(json_encode($shipment))); 51 } 45 // set time meta to initiate the request 46 $shipmentPayload['admin_initiate_shipment_time'] = date('Y-m-d H:i:s'); 47 update_post_meta($orderId, 'shipbubble_shipment_details', sanitize_text_field(json_encode($shipmentPayload))); 52 48 49 // initiate request 53 50 $response = shipbubble_create_shipment($shipmentPayload); 54 51 … … 57 54 update_post_meta($orderId, 'shipbubble_order_id', $response->data->order_id); 58 55 59 $shipmentDetailsArray = get_post_meta($orderId, 'shipbubble_shipment_details'); 60 if (count($shipmentDetailsArray)) { 61 $shipment = json_decode($shipmentDetailsArray[0], true); 62 $shipment['admin_create_shipment_time'] = date('Y-m-d H:i:s'); 63 update_post_meta($orderId, 'shipbubble_shipment_details', sanitize_text_field(json_encode($shipment))); 64 } 56 // set time meta 57 $shipmentPayload['admin_create_shipment_time'] = date('Y-m-d H:i:s'); 58 update_post_meta($orderId, 'shipbubble_shipment_details', sanitize_text_field(json_encode($shipmentPayload))); 65 59 66 60 // set shipping status -
shipbubble/trunk/admin/woocommerce/orders.php
r2976344 r2987026 4 4 function shibubble_order_data_after_billing_address($order) 5 5 { 6 6 7 if (in_array($order->get_status(), SHIPBUBBLE_WC_BAD_ORDER_STATUS_ARR)) { 7 8 return; … … 23 24 $orderAddress = sb_create_address($shippingData['address_1'], $shippingData['city'], $shippingData['state'], $shippingData['country']); 24 25 25 // echo '<pre> ' . var_export(reset($order->get_items( 'shipping' ))->get_method_id(), true) . '</pre>';26 // echo '<pre> ' . var_export($shippingData, true) . '</pre>';27 // echo '<pre> ' . var_export($order->data['shipping'], true) . '</pre>';28 // echo '<pre>' . var_export(wc_get_product( $order->get_items()[9]['product_id'] ), true) . '</pre>';29 // echo '<pre> ' . var_export(json_decode($shipment)->service_code, true) . '</pre>';30 // die;31 32 26 // Get Delivery Address 33 27 $shipbubbleDeliveryAddress = get_post_meta($order->get_id(), 'shipbubble_delivery_address', true); … … 36 30 $shipbubbleOrderId = get_post_meta($order->get_id(), 'shipbubble_order_id', true); 37 31 38 $shipment = $shipmentDetailsArray[0]; // [0 => 'request token ...'] 39 32 // $shipment = $shipmentDetailsArray[0]; // [0 => 'request token ...'] 33 34 // var_dump($shipmentDetailsArray[0]); 35 // die; 36 37 $convertedArray = shipbubble_convert_special_strings_to_array($shipmentDetailsArray[0]); // [0 => 'request token ...'] 38 $shipment = json_decode(json_encode($convertedArray)); 39 $serviceCode = ''; // prod 40 40 // $serviceCode = array( 'speedaf-express' ); // test 41 41 42 if (empty($shipment)) { 43 $serviceCode = array(); // prod 44 } else { 45 $serviceCode = array(json_decode($shipment)->service_code); // prod 42 if (!empty($shipment)) { 43 $serviceCode = $shipment->service_code; // prod 46 44 } 47 45 … … 52 50 $hrsInterval = $interval->h + ($interval->days * 24); 53 51 54 // check token has lasted longer than 48hrs before regenerating new request token 55 if (strlen($shipbubbleOrderId) < 1 && $hrsInterval > SHIPBUBBLE_REQUEST_TOKEN_EXPIRY && !is_null($shipment)) { 56 $rates = shipbubble_regenerate_rate_token($order, $serviceCode); 57 if (count($rates)) { 58 $shipment = json_encode($rates); 52 //if (strlen($shipbubbleOrderId) < 1 && !sb_compare_addresses($shipbubbleDeliveryAddress, $orderAddress) && $hrsInterval < SHIPBUBBLE_REQUEST_TOKEN_EXPIRY && !is_null($shipment)) { 53 54 // set flag to regenerate token 55 $regenerateToken = false; 56 57 // Check token has expired and shipbubble id doesn't exist to enable flag 58 if (strlen($shipbubbleOrderId) < 1 && $hrsInterval > SHIPBUBBLE_REQUEST_TOKEN_EXPIRY) { 59 $regenerateToken = true; 60 } 61 62 // Check address has changed under 48hrs to enable flag 63 if (!sb_compare_addresses($shipbubbleDeliveryAddress, $orderAddress)) { 64 $regenerateToken = true; 65 } 66 67 if ($regenerateToken && !is_null($shipment)) { 68 // regenerate token 69 $regeneratedMeta = shipbubble_regenerate_rate_token($order, $shipment); 70 71 // update db 72 if (count($regeneratedMeta) && isset($regeneratedMeta['request_token'])) { 73 $shipment = json_encode($regeneratedMeta); 59 74 update_post_meta($order->get_id(), 'shipbubble_shipment_details', $shipment); 60 75 update_post_meta($order->get_id(), 'shipbubble_delivery_address', $orderAddress); 61 } 62 } 63 64 // Check address has changed under 48hrs before before regenerating new request token 65 if (strlen($shipbubbleOrderId) < 1 && !sb_compare_addresses($shipbubbleDeliveryAddress, $orderAddress) && $hrsInterval < SHIPBUBBLE_REQUEST_TOKEN_EXPIRY && !is_null($shipment)) { 66 // regenerate 67 $rates = shipbubble_regenerate_rate_token($order, $serviceCode); 68 if (count($rates)) { 69 $shipment = json_encode($rates); 70 update_post_meta($order->get_id(), 'shipbubble_shipment_details', $shipment); 71 update_post_meta($order->get_id(), 'shipbubble_delivery_address', $orderAddress); 76 } else { 77 if (isset($regeneratedMeta['errors'])) { 78 $message = $regeneratedMeta["errors"] . ' when regenerating shipbubble token'; 79 $output = '<div id="message" class="notice notice-warning is-dismissible"> 80 <p>' . $message . '</p> 81 82 <button type="button" class="notice-dismiss"> 83 <span class="screen-reader-text">Dismiss this notice.</span> 84 </button> 85 </div>'; 86 87 echo $output; 88 } 72 89 } 73 90 } … … 77 94 <input type="hidden" id="wc_order_id" name="wc_order_id" value='<?php echo esc_html($order->get_id()); ?>' /> 78 95 79 <input type="hidden" id="shipment_details" name="shipment_details" value='<?php echo esc_html( $shipment); ?>' />96 <input type="hidden" id="shipment_details" name="shipment_details" value='<?php echo esc_html(json_encode($shipment)); ?>' /> 80 97 81 98 <button id="create-shipment" style="background-color: #FF5170; color: #FFF; padding: 4px 16px; border: 1px solid #FF5170; border-radius: 3px; cursor: pointer;"> -
shipbubble/trunk/includes/core-methods.php
r2975160 r2987026 184 184 } 185 185 186 function shipbubble_regenerate_rate_token($order, $s erviceCodes)186 function shipbubble_regenerate_rate_token($order, $shipment) 187 187 { 188 188 $countryObject = WC()->countries; … … 200 200 201 201 // Generate Address Code 202 202 203 $addressResponse = shipbubble_validate_address( 203 204 $shipping['name'], … … 240 241 241 242 // Fetch Shipping rate for service code 242 $response = shipbubble_process_shipping_rates($addressCode, $items, $serviceCodes);243 244 if (count($response) > 0) {243 $response = shipbubble_process_shipping_rates($addressCode, $items, [$shipment->service_code]); 244 245 if (count($response) && isset($response['couriers']) && count($response['couriers'])) { 245 246 $rates['request_token'] = $response['request_token']; 246 $rates['service_code'] = $response['couriers'][0]->service_code; 247 $rates['courier_id'] = $response['couriers'][0]->courier_id; 248 $rates['courier_name'] = $response['couriers'][0]->courier_name; 249 $rates['shipment_cost'] = $response['couriers'][0]->total; 250 } 251 } 252 253 // echo '<pre>' . var_export($rates, true) . '</pre>'; 254 // die; 255 247 248 // filter request 249 $filtered_courier = array_filter($response['couriers'], function ($courier) use ($shipment) { 250 return $shipment->service_code == $courier->service_code && $shipment->courier_id == $courier->courier_id; 251 }); 252 253 if (count($filtered_courier)) { 254 $rates['service_code'] = $filtered_courier[0]->service_code; 255 $rates['courier_id'] = $filtered_courier[0]->courier_id; 256 $rates['courier_name'] = $filtered_courier[0]->courier_name; 257 $rates['shipment_cost'] = (string) $filtered_courier[0]->total; 258 } else { 259 $rates['service_code'] = $response['couriers'][0]->service_code; 260 $rates['courier_id'] = $response['couriers'][0]->courier_id; 261 $rates['courier_name'] = $response['couriers'][0]->courier_name; 262 $rates['shipment_cost'] = (string) $response['couriers'][0]->total; 263 } 264 265 // first data 266 $rates['request_datetime'] = $shipment->request_datetime; 267 $rates['order_request_time'] = $shipment->order_request_time; 268 269 // new data 270 $rates['regenerated_token_time'] = date('Y-m-d H:i:s'); 271 } else { 272 if (isset($response['error'])) { 273 $rates['errors'] = $response['error']; 274 } 275 } 276 } else { 277 if (isset($addressResponse->status) && $addressResponse->status == 'failed') { 278 $rates['errors'] = isset($addressResponse->message) ? $addressResponse->message : ''; 279 } 280 } 256 281 return $rates; 257 282 } … … 316 341 return trim(strtolower($address1)) == trim(strtolower($address2)); 317 342 } 343 344 function shipbubble_convert_special_strings_to_array($subject) 345 { 346 $string = str_replace('\n', '', $subject); 347 $string = str_replace('{', '', $string); 348 $string = str_replace('}', '', $string); 349 $string = rtrim($string, ','); 350 $string = str_replace('"', '', $string); 351 352 $converted = []; 353 foreach (explode(',', $string) as $item) { 354 $parts = explode(':', $item); 355 $count = count($parts); 356 if ($count > 2) { 357 $join = ''; 358 for ($i = 1; $i < $count; $i++) { 359 if ($count - $i == 1) { 360 $join .= $parts[$i]; 361 } else { 362 $join .= $parts[$i] . ':'; 363 } 364 } 365 $converted[trim($parts[0])] = $join; 366 } else { 367 $converted[trim($parts[0])] = $parts[1]; 368 } 369 } 370 371 return $converted; 372 } -
shipbubble/trunk/public/js/couriers-on-checkout.js
r2975160 r2987026 24 24 // use shipping variables 25 25 if (useShippingAddress.is(':checked')) { 26 26 27 firstName = $('input#shipping_first_name').val(); 27 28 lastName = $('input#shipping_last_name').val(); … … 51 52 52 53 } else { 54 53 55 // use billing variables 54 56 firstName = $('input#billing_first_name').val(); … … 181 183 182 184 // log time of data fetch 183 var request_fetch_date = new Date().toJSON(); 184 $('input[name="shipbubble_rate_datetime"]').val(request_fetch_date); 185 var json_fetch_date = new Date().toJSON(); 186 var string_fetch_date = JSON.stringify(json_fetch_date); 187 $('input[name="shipbubble_rate_datetime"]').val(string_fetch_date); 185 188 186 189 loaders.hide(); -
shipbubble/trunk/readme.txt
r2976344 r2987026 84 84 * Fixed checkout bug for other shipping methods (if available). 85 85 86 = 1.7.2 = 87 * Admin process shipment bug fix. 88 86 89 == Upgrade Notice == 87 = 1.7. 1=88 Fixed checkout bug for other shipping methods (if available). 90 = 1.7.2 = 91 Admin process shipment bug fix -
shipbubble/trunk/shipbubble.php
r2976344 r2987026 8 8 * Tags: logistics, deliveries, shipping rates, multiple couriers, post purchase experience 9 9 * Requires at least: 4.0 10 * Tested up to: 6. 211 * Version: 1.7. 110 * Tested up to: 6.3 11 * Version: 1.7.2 12 12 * Requires PHP: 5.6 13 13 * Text Domain: shipbubble … … 189 189 } 190 190 191 // error_log(print_r('here', true)); 192 // error_log(print_r(sea($_POST['shipbubble_shipment_details']), true)); 191 // error_log(print_r($_POST['shipbubble_shipment_details']), true)); 193 192 // die; 194 193 … … 265 264 update_post_meta($order_id, 'shipbubble_delivery_address', $address); 266 265 } 266 } 267 } 268 269 add_action('woocommerce_checkout_order_processed', 'handle_processed', 10, 1); 270 function handle_processed($order_id) 271 { 272 $order = new WC_Order($order_id); 273 $shipping_items = $order->get_items('shipping'); 274 $shipping_total = $order->get_shipping_total(); 275 276 if ($order->has_shipping_method(SHIPBUBBLE_ID) && (empty($shipping_items) || "0" == $shipping_total)) { 277 $order->delete(); 278 wp_send_json_error(); 267 279 } 268 280 }
Note: See TracChangeset
for help on using the changeset viewer.