Changeset 3399647
- Timestamp:
- 11/20/2025 11:12:48 AM (4 months ago)
- Location:
- cod24-shipping
- Files:
-
- 36 added
- 1 deleted
- 10 edited
-
tags/4.0.10/readme.txt (deleted)
-
tags/5.0 (added)
-
tags/5.0/assets (added)
-
tags/5.0/assets/css (added)
-
tags/5.0/assets/css/cod24-dokan-frontend.css (added)
-
tags/5.0/assets/css/cod24-dokan-vendor.css (added)
-
tags/5.0/assets/css/cod24-woo-admin.css (added)
-
tags/5.0/assets/css/sweetalert2.css (added)
-
tags/5.0/assets/index.php (added)
-
tags/5.0/assets/js (added)
-
tags/5.0/assets/js/city-select.js (added)
-
tags/5.0/assets/js/cod24-shcod-fee.js (added)
-
tags/5.0/assets/js/cod24-woo-admin.js (added)
-
tags/5.0/assets/js/sweetalert2.js (added)
-
tags/5.0/cod24-shipping.php (added)
-
tags/5.0/inc (added)
-
tags/5.0/inc/api (added)
-
tags/5.0/inc/api/class-cod24-api.php (added)
-
tags/5.0/inc/api/class-cod24-tipax-api.php (added)
-
tags/5.0/inc/class-cod24-dokan.php (added)
-
tags/5.0/inc/class-cod24-settings.php (added)
-
tags/5.0/inc/class-cod24-shcod.php (added)
-
tags/5.0/inc/class-cod24-woo.php (added)
-
tags/5.0/inc/index.php (added)
-
tags/5.0/inc/shipping (added)
-
tags/5.0/inc/shipping/class-cod24-pishtaz.php (added)
-
tags/5.0/inc/shipping/class-cod24-special.php (added)
-
tags/5.0/inc/shipping/class-cod24-tipax.php (added)
-
tags/5.0/index.php (added)
-
tags/5.0/readme.txt (added)
-
tags/5.0/templates (added)
-
tags/5.0/templates/vendor-order-metabox.php (added)
-
trunk/assets/css/cod24-dokan-frontend.css (added)
-
trunk/assets/css/cod24-dokan-vendor.css (added)
-
trunk/assets/js/cod24-woo-admin.js (modified) (4 diffs)
-
trunk/cod24-shipping.php (modified) (5 diffs)
-
trunk/inc/api/class-cod24-api.php (modified) (32 diffs)
-
trunk/inc/api/class-cod24-tipax-api.php (modified) (19 diffs)
-
trunk/inc/class-cod24-dokan.php (added)
-
trunk/inc/class-cod24-shcod.php (modified) (1 diff)
-
trunk/inc/class-cod24-woo.php (modified) (18 diffs)
-
trunk/inc/shipping/class-cod24-pishtaz.php (modified) (2 diffs)
-
trunk/inc/shipping/class-cod24-special.php (modified) (2 diffs)
-
trunk/inc/shipping/class-cod24-tipax.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/templates (added)
-
trunk/templates/vendor-order-metabox.php (added)
Legend:
- Unmodified
- Added
- Removed
-
cod24-shipping/trunk/assets/js/cod24-woo-admin.js
r3366748 r3399647 306 306 jQuery(".cod24_change_status").on('click', function(e){ 307 307 e.preventDefault(); 308 308 309 // Try to find the container - support both WooCommerce admin and Dokan vendor forms 309 310 var container = jQuery('#cod24_order_info'); 310 311 if (!container.length) { 311 console.error('Container with id="cod24_order_info" not found'); 312 container = jQuery('#vendor_cod24_form'); 313 } 314 315 if (!container.length) { 316 console.error('Container form not found (tried #order_barcode_form and #vendor_cod24_form)'); 312 317 return; 313 318 } 314 319 315 320 // Create FormData object 316 321 var data = new FormData(); 317 322 318 323 // Get all input, select, and textarea elements within the container 319 324 container.find('input, select, textarea').each(function() { 320 325 var element = jQuery(this); 321 326 var name = element.attr('name'); // Use the 'name' attribute as the key 322 327 323 328 // Skip elements without a 'name' attribute 324 329 if (!name) { … … 326 331 return; 327 332 } 328 333 329 334 // Handle checkboxes separately 330 335 if (element.attr('type') === 'checkbox') { … … 337 342 } 338 343 }); 339 344 340 345 // Append additional data (e.g., action) 341 346 data.append('action', 'cod24_change_status'); … … 488 493 }); 489 494 }); 490 495 496 // Handle is_calc_srv_by_weight checkbox change 497 jQuery(document).on('change', '#is_calc_srv_by_weight', function() { 498 var isChecked = jQuery(this).is(':checked'); 499 var cartonSizeSelect = jQuery('#carton_size'); 500 501 if (isChecked) { 502 // Disable carton size and set to 0 503 cartonSizeSelect.prop('disabled', true); 504 cartonSizeSelect.val('10'); 505 } else { 506 // Enable carton size 507 cartonSizeSelect.prop('disabled', false); 508 } 509 }); 510 511 // Initialize on page load 512 if (jQuery('#is_calc_srv_by_weight').is(':checked')) { 513 jQuery('#carton_size').prop('disabled', true); 514 } 491 515 }); -
cod24-shipping/trunk/cod24-shipping.php
r3366748 r3399647 3 3 Plugin Name: COD24 Shipping For Woocommerce 4 4 Description: This plugin is adding COD24 shipping methods to woocommerce. 5 Version: 4.0.105 Version: 5.0 6 6 Author: COD24 7 7 Author URI: https://cod24.ir … … 27 27 public function __construct() 28 28 { 29 define('COD24_PLUGIN_VERSION', ' 4.0.10');29 define('COD24_PLUGIN_VERSION', '5.0'); 30 30 define('COD24_PLUGIN_DIR', plugin_dir_path(__FILE__)); 31 31 define('COD24_PLUGIN_URL', plugin_dir_url(__FILE__)); … … 37 37 require_once('inc/shipping/class-cod24-special.php'); 38 38 require_once('inc/shipping/class-cod24-tipax.php'); 39 require_once('inc/class-cod24-shcod.php'); 39 require_once('inc/class-cod24-settings.php'); 40 require_once('inc/class-cod24-shcod.php'); 40 41 require_once('inc/class-cod24-woo.php'); 41 require_once('inc/class-cod24-settings.php'); 42 require_once('inc/class-cod24-dokan.php'); 43 44 // Include Dokan integration if Dokan is active 45 if (!class_exists('\WeDevs_Dokan')) { 46 47 } 42 48 43 49 // Schedule the cron job to run once (e.g., 2 minutes from now) … … 143 149 { 144 150 // Do nothing 151 flush_rewrite_rules(); 145 152 } 146 153 … … 150 157 public static function deactivate() 151 158 { 152 // Do nothing 159 // Do nothing 160 flush_rewrite_rules(); 153 161 } 154 162 } -
cod24-shipping/trunk/inc/api/class-cod24-api.php
r3346653 r3399647 30 30 } // END public function __construct() 31 31 32 /** 33 * Get credentials based on vendor_id 34 * 35 * @param int|null $vendor_id Optional vendor ID 36 * @return array Array with username, password, and secure settings 37 */ 38 private static function get_credentials( $vendor_id = null ) { 39 if( !empty( $vendor_id ) && $vendor_id > 0 ) { 40 // Use vendor credentials 41 return array( 42 'username' => get_user_meta( $vendor_id, '_vendor_cod24_username', true ), 43 'password' => get_user_meta( $vendor_id, '_vendor_cod24_password', true ), 44 'secure' => get_option('cod24_shipping_api_secure_connection_enabled') 45 ); 46 } else { 47 // Use admin credentials 48 return array( 49 'username' => get_option('cod24_shipping_username_panel'), 50 'password' => get_option('cod24__shipping_password_panel'), 51 'secure' => get_option('cod24_shipping_api_secure_connection_enabled') 52 ); 53 } 54 } 55 56 /** 57 * Get token based on vendor_id 58 * 59 * @param int|null $vendor_id Optional vendor ID 60 * @return string|false Token or false if not found 61 */ 62 private static function get_stored_token( $vendor_id = null ) { 63 if( !empty( $vendor_id ) && $vendor_id > 0 ) { 64 $token = get_user_meta( $vendor_id, '_vendor_cod24_shipping_token', true ); 65 } else { 66 $token = get_option('cod24_shipping_token'); 67 } 68 69 if( empty( $token ) ) 70 { 71 if( !empty( $vendor_id ) && $vendor_id > 0 ) { 72 self::get_token( $vendor_id ); 73 } else { 74 self::get_token(); 75 } 76 } 77 78 return $token; 79 } 80 81 /** 82 * Store token based on vendor_id 83 * 84 * @param string $token Token to store 85 * @param int|null $vendor_id Optional vendor ID 86 */ 87 private static function store_token( $token, $vendor_id = null ) { 88 if( !empty( $vendor_id ) && $vendor_id > 0 ) { 89 update_user_meta( $vendor_id, '_vendor_cod24_shipping_token', esc_attr( $token ) ); 90 } else { 91 update_option('cod24_shipping_token', esc_attr( $token ) ); 92 } 93 } 94 32 95 /** 33 96 * Admin bar wallet balance … … 100 163 } 101 164 } 165 166 /** 167 * vendor wallet balance 168 * 169 * @return void 170 */ 171 public static function vendor_wallet_amount() 172 { 173 $vendor_id = get_current_user_id(); 174 $cod24_token = self::get_stored_token( $vendor_id ); 175 176 if ( ! empty( $cod24_token ) ) 177 { 178 // Check if cached data exists 179 $cache_key = 'cod24_vendor_wallet_amount_' . $vendor_id; 180 $cached_vendor_wallet_amount = get_transient( $cache_key ); 181 182 if ( false === $cached_vendor_wallet_amount ) 183 { 184 // Cache is empty or expired, fetch data from API 185 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled') == 'yes' ) ? 'https://' : 'http://'; 186 $url = $api_protocol . 'api.cod24.ir/api/Wallet/getWalletAmount'; 187 $body = []; 188 $body = wp_json_encode( $body ); 189 190 // API arguments 191 $args = array( 192 'method' => 'POST', 193 'timeout' => 500, 194 'sslverify' => ( get_option('cod24_shipping_api_secure_connection_enabled') == 'yes' ) ? true : false, 195 'headers' => array( 196 'Authorization' => 'Bearer ' . $cod24_token, 197 'Content-Type' => 'application/json', 198 ), 199 'body' => $body, 200 ); 201 202 $request = wp_remote_post( $url, $args ); 203 204 if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) != 200 ) 205 { 206 $result['code'] = wp_remote_retrieve_response_code( $request ); 207 if ( $result['code'] == 401 ) 208 { 209 self::get_token( $vendor_id ); 210 } 211 } 212 else 213 { 214 $response = wp_remote_retrieve_body( $request ); 215 $result = json_decode( $response, true ); 216 $cached_vendor_wallet_amount = number_format( $result['walletAmount'], 0 ) . " " . get_woocommerce_currency_symbol(); 217 218 // Cache the result for 2 minutes 219 set_transient( $cache_key, $cached_vendor_wallet_amount, 2 * MINUTE_IN_SECONDS ); 220 } 221 } 222 223 printf( esc_attr__('Wallet Amount: %s', 'cod24-shipping' ), $cached_vendor_wallet_amount ); 224 } 225 } 102 226 103 227 /** 104 228 * Get COD24 token using username and password 105 * @param params106 * @return token107 */ 108 public static function get_token( )109 { 110 $cod24_username = get_option('cod24_shipping_username_panel');111 $c od24_password = get_option('cod24__shipping_password_panel');112 113 if( !empty( $c od24_username ) && !empty( $cod24_password) )229 * @param int|null $vendor_id Optional vendor ID 230 * @return void 231 */ 232 public static function get_token( $vendor_id = null ) 233 { 234 // get credentials by vendor 235 $credentials = self::get_credentials( $vendor_id ); 236 237 if( !empty( $credentials['username'] ) && !empty( $credentials['password'] ) ) 114 238 { 115 239 // send to api 116 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';240 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 117 241 $url = $api_protocol.'api.cod24.ir/api/Account/getToken'; 118 242 $body = array( 119 'userName' => esc_attr( $c od24_username),120 'password' => esc_attr( $c od24_password),243 'userName' => esc_attr( $credentials['username'] ), 244 'password' => esc_attr( $credentials['password'] ), 121 245 ); 122 246 … … 126 250 $args = array( 127 251 'method' => 'POST', 128 'sslverify' => false,252 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 129 253 'headers' => array( 130 254 'Content-Type' => 'application/json', … … 135 259 $request = wp_remote_post( $url, $args ); 136 260 137 if ( ! is_wp_error( $request ) ||wp_remote_retrieve_response_code( $request ) == 200 )261 if ( ! is_wp_error( $request ) && wp_remote_retrieve_response_code( $request ) == 200 ) 138 262 { 139 263 $response = wp_remote_retrieve_body( $request ); … … 141 265 if(!empty($result['token'])) 142 266 { 143 update_option('cod24_shipping_token', esc_attr( $result['token'] ) ); 267 // store token 268 self::store_token( $result['token'], $vendor_id ); 144 269 } 145 270 } … … 151 276 * 152 277 * @param data 278 * @param int|null $vendor_id Optional vendor ID 153 279 * @return final_result array | return code & total price of rate 154 280 */ 155 public static function get_rate( $data )281 public static function get_rate( $data, $vendor_id = null ) 156 282 { 157 283 $final_result = []; 158 $cod24_token = get_option('cod24_shipping_token'); 284 $cod24_token = self::get_stored_token( $vendor_id ); 285 $credentials = self::get_credentials( $vendor_id ); 159 286 160 287 if( !empty( $cod24_token ) ) … … 162 289 163 290 // send to api 164 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';291 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 165 292 $url = $api_protocol.'api.cod24.ir/api/Order/getPostPrice'; 166 293 $body = array( … … 179 306 'method' => 'POST', 180 307 'timeout' => 500, 181 'sslverify' => true,308 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 182 309 'headers' => array( 183 310 'Authorization' => 'Bearer '.$cod24_token, … … 229 356 $custom_total_weight = $cod24_info['total_weight']; // total weight for calculating of all products 230 357 $non_standard_package = $cod24_info['non_standard_package']; 231 $carton_size = $cod24_info['carton_size']; 358 $is_calc_srv_by_weight = isset( $cod24_info['is_calc_srv_by_weight'] ) ? $cod24_info['is_calc_srv_by_weight'] : 'no'; 359 360 // Set carton_size based on is_calc_srv_by_weight 361 if( $is_calc_srv_by_weight == 'yes' ) 362 { 363 $carton_size = 0; // If calculating by weight, set to 0 364 } 365 else 366 { 367 $carton_size = isset( $cod24_info['carton_size'] ) ? $cod24_info['carton_size'] : 0; 368 } 232 369 $content_parcel = ( isset( $cod24_info['content_parcel'] ) && !empty( $cod24_info['content_parcel'] ) ) ? $cod24_info['content_parcel'] : ''; 233 370 … … 376 513 'contentParcell' => $content_parcel, 377 514 'idCartonType' => (int) $carton_size, 515 'isCalcSrvByWeight' => ( $is_calc_srv_by_weight == 'yes' ) ? true : false, 378 516 ); 379 517 … … 385 523 * 386 524 * @param order_id int 525 * @param int|null $vendor_id Optional vendor ID 387 526 * @return final_result array | return code & total price of rate 388 527 */ 389 public static function add_order( $order_id )528 public static function add_order( $order_id, $vendor_id = null ) 390 529 { 391 530 $final_result = []; 392 $cod24_token = get_option('cod24_shipping_token'); 531 $cod24_token = self::get_stored_token( $vendor_id ); 532 $credentials = self::get_credentials( $vendor_id ); 393 533 394 534 if( !empty( $cod24_token ) ) 395 535 { 396 536 // send to api 397 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';537 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 398 538 $url = $api_protocol.'api.cod24.ir/api/Order/addOrder'; 399 539 $sanitized_data = self::prepare_data( $order_id ); … … 405 545 'method' => 'POST', 406 546 'timeout' => 500, 407 'sslverify' => true,547 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 408 548 'headers' => array( 409 549 'Authorization' => 'Bearer '.$cod24_token, … … 458 598 * 459 599 * @param order_ids array 600 * @param int|null $vendor_id Optional vendor ID 460 601 * @return final_result array | return code & total price of rate 461 602 */ 462 public static function add_order_batch( $order_ids )603 public static function add_order_batch( $order_ids, $vendor_id = null ) 463 604 { 464 605 $final_result_list = []; 465 606 $sanitized_data = []; 466 $cod24_token = get_option('cod24_shipping_token'); 607 $cod24_token = self::get_stored_token( $vendor_id ); 608 $credentials = self::get_credentials( $vendor_id ); 467 609 468 610 if( !empty( $cod24_token ) ) 469 611 { 470 612 // send to api 471 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';613 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 472 614 $url = $api_protocol.'api.cod24.ir/api/Order/addOrderBatch'; 473 615 if( !empty( $order_ids ) ) … … 485 627 'method' => 'POST', 486 628 'timeout' => 500, 487 'sslverify' => true,629 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 488 630 'headers' => array( 489 631 'Authorization' => 'Bearer '.$cod24_token, … … 554 696 * 555 697 * @param params 698 * @param int|null $vendor_id Optional vendor ID 556 699 * @return final_result array | return code & total price of rate 557 700 */ 558 public static function suspend_order( $params )701 public static function suspend_order( $params, $vendor_id = null ) 559 702 { 560 703 $final_result = []; 561 $cod24_token = get_option('cod24_shipping_token'); 704 $cod24_token = self::get_stored_token( $vendor_id ); 705 $credentials = self::get_credentials( $vendor_id ); 562 706 563 707 if( !empty( $cod24_token ) ) 564 708 { 565 709 // send to api 566 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';710 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 567 711 $url = $api_protocol.'api.cod24.ir/api/Order/suspendOrder'; 568 712 … … 573 717 'method' => 'POST', 574 718 'timeout' => 500, 575 'sslverify' => true,719 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 576 720 'headers' => array( 577 721 'Authorization' => 'Bearer '.$cod24_token, … … 608 752 * 609 753 * @param params 754 * @param int|null $vendor_id Optional vendor ID 610 755 * @return final_result array | return code & total price of rate 611 756 */ 612 public static function ready_to_send_order( $params )757 public static function ready_to_send_order( $params, $vendor_id = null ) 613 758 { 614 759 $final_result = []; 615 $cod24_token = get_option('cod24_shipping_token'); 760 $cod24_token = self::get_stored_token( $vendor_id ); 761 $credentials = self::get_credentials( $vendor_id ); 616 762 617 763 if( !empty( $cod24_token ) ) 618 764 { 619 765 // send to api 620 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';766 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 621 767 $url = $api_protocol.'api.cod24.ir/api/Order/readyToSend'; 622 768 … … 627 773 'method' => 'POST', 628 774 'timeout' => 500, 629 'sslverify' => true,775 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 630 776 'headers' => array( 631 777 'Authorization' => 'Bearer '.$cod24_token, … … 662 808 * 663 809 * @param params 810 * @param int|null $vendor_id Optional vendor ID 664 811 * @return final_result array | return code & total price of rate 665 812 */ 666 public static function cancel_order( $params )813 public static function cancel_order( $params, $vendor_id = null ) 667 814 { 668 815 $final_result = []; 669 $cod24_token = get_option('cod24_shipping_token'); 816 $cod24_token = self::get_stored_token( $vendor_id ); 817 $credentials = self::get_credentials( $vendor_id ); 670 818 671 819 if( !empty( $cod24_token ) ) 672 820 { 673 821 // send to api 674 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';822 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 675 823 $url = $api_protocol.'api.cod24.ir/api/Order/cancelOrder'; 676 824 … … 681 829 'method' => 'POST', 682 830 'timeout' => 500, 683 'sslverify' => true,831 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 684 832 'headers' => array( 685 833 'Authorization' => 'Bearer '.$cod24_token, … … 716 864 * 717 865 * @param serials 866 * @param int|null $vendor_id Optional vendor ID 718 867 * @return final_result factor url preview 719 868 */ 720 public static function factor_preview( $serials )869 public static function factor_preview( $serials, $vendor_id = null ) 721 870 { 722 871 $final_result = []; 723 $cod24_token = get_option('cod24_shipping_token'); 872 $cod24_token = self::get_stored_token( $vendor_id ); 873 $credentials = self::get_credentials( $vendor_id ); 724 874 725 875 if( !empty( $cod24_token ) ) 726 876 { 727 877 // send to api 728 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';878 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 729 879 $url = $api_protocol.'api.cod24.ir/api/Print/factorPreview'; 730 880 $body = wp_json_encode( $serials ); … … 734 884 'method' => 'POST', 735 885 'timeout' => 500, 736 'sslverify' => true,886 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 737 887 'headers' => array( 738 888 'Authorization' => 'Bearer '.$cod24_token, … … 763 913 'method' => 'POST', 764 914 'timeout' => 500, 765 'sslverify' => true,915 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 766 916 'headers' => array( 767 917 'Authorization' => esc_attr( $result['token'] ), … … 790 940 * 791 941 * @param serials 942 * @param int|null $vendor_id Optional vendor ID 792 943 * @return final_result barcode url preview 793 944 */ 794 public static function barcode_preview( $serials )945 public static function barcode_preview( $serials, $vendor_id = null ) 795 946 { 796 947 $final_result = []; 797 $cod24_token = get_option('cod24_shipping_token'); 948 $cod24_token = self::get_stored_token( $vendor_id ); 949 $credentials = self::get_credentials( $vendor_id ); 798 950 799 951 if( !empty( $cod24_token ) ) 800 952 { 801 953 // send to api 802 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';954 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 803 955 $url = $api_protocol.'api.cod24.ir/api/Print/barcodePreview'; 804 956 $body = wp_json_encode( $serials ); … … 808 960 'method' => 'POST', 809 961 'timeout' => 500, 810 'sslverify' => true,962 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 811 963 'headers' => array( 812 964 'Authorization' => 'Bearer '.$cod24_token, … … 837 989 'method' => 'POST', 838 990 'timeout' => 500, 839 'sslverify' => true,991 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 840 992 'headers' => array( 841 993 'Authorization' => esc_attr( $result['token'] ), … … 870 1022 $result = []; 871 1023 872 // send to api873 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled') =='yes' ) ? 'https://' : 'http://';874 $url = $api_protocol.' cod24-learn.s3.ir-thr-at1.arvanstorage.ir/States.json';1024 // get states from cdn 1025 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled') == 'yes' ) ? 'https://' : 'http://'; 1026 $url = $api_protocol.'apicod24.s3.ir-thr-at1.arvanstorage.ir/States.json'; 875 1027 $body = []; 876 1028 … … 905 1057 { 906 1058 $result = []; 907 $cod24_token = get_option('cod24_shipping_token');908 909 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled') =='yes' ) ? 'https://' : 'http://';1059 1060 // get cities form cdn 1061 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled') == 'yes' ) ? 'https://' : 'http://'; 910 1062 $url = $api_protocol.'apicod24.s3.ir-thr-at1.arvanstorage.ir/Cities.json'; 911 1063 $body = []; … … 930 1082 // Update the values of the 'cityNameFa' key for all elements in the array 931 1083 foreach ($result as &$item) { 932 $item['cityNameFa'] = self:: sanitize_first_last_space_character($item['cityNameFa']);1084 $item['cityNameFa'] = self::convert_arabic_to_persian_character( self::sanitize_first_last_space_character($item['cityNameFa']) ); 933 1085 } 934 1086 } … … 979 1131 'state_id' => $value['statePostCode'], 980 1132 'city_id' => $value['cityPostCode'], 981 'city_name' => self:: sanitize_first_last_space_character( $value['cityNameFa'])1133 'city_name' => self::convert_arabic_to_persian_character( self::sanitize_first_last_space_character( $value['cityNameFa'] ) ) 982 1134 ]; 983 1135 } … … 1045 1197 $user_city_name=str_replace($arabic, $farsi, $user_city_name); 1046 1198 1047 $sanitize_user_city_name = self:: sanitize_first_last_space_character( $user_city_name);1199 $sanitize_user_city_name = self::convert_arabic_to_persian_character( self::sanitize_first_last_space_character( $user_city_name ) ); 1048 1200 1049 1201 $data = self::get_all_cities(); … … 1079 1231 return $str; 1080 1232 } 1233 1234 public static function convert_arabic_to_persian_character($string) 1235 { 1236 $characters = [ 1237 'ك' => 'ک', 1238 'دِ' => 'د', 1239 'بِ' => 'ب', 1240 'زِ' => 'ز', 1241 'ذِ' => 'ذ', 1242 'شِ' => 'ش', 1243 'سِ' => 'س', 1244 'ى' => 'ی', 1245 'ي' => 'ی', 1246 '١' => '۱', 1247 '٢' => '۲', 1248 '٣' => '۳', 1249 '٤' => '۴', 1250 '٥' => '۵', 1251 '٦' => '۶', 1252 '٧' => '۷', 1253 '٨' => '۸', 1254 '٩' => '۹', 1255 '٠' => '۰', 1256 ]; 1257 return str_replace(array_keys($characters), array_values($characters),$string); 1258 } 1081 1259 1082 1260 public static function get_carton_sizes() -
cod24-shipping/trunk/inc/api/class-cod24-tipax-api.php
r3346653 r3399647 30 30 31 31 /** 32 * Get credentials based on vendor_id 33 * 34 * @param int|null $vendor_id Optional vendor ID 35 * @return array Array with username, password, and secure settings 36 */ 37 private static function get_credentials( $vendor_id = null ) { 38 if( !empty( $vendor_id ) && $vendor_id > 0 ) { 39 // Use vendor credentials 40 return array( 41 'username' => get_user_meta( $vendor_id, '_vendor_cod24_username', true ), 42 'password' => get_user_meta( $vendor_id, '_vendor_cod24_password', true ), 43 'secure' => get_user_meta( $vendor_id, '_vendor_cod24_secure_connection', true ) ?: 'yes' 44 ); 45 } else { 46 // Use admin credentials 47 return array( 48 'username' => get_option('cod24_shipping_username_panel'), 49 'password' => get_option('cod24__shipping_password_panel'), 50 'secure' => get_option('cod24_shipping_api_secure_connection_enabled') 51 ); 52 } 53 } 54 55 /** 56 * Get token based on vendor_id 57 * 58 * @param int|null $vendor_id Optional vendor ID 59 * @return string|false Token or false if not found 60 */ 61 private static function get_stored_token( $vendor_id = null ) { 62 if( !empty( $vendor_id ) && $vendor_id > 0 ) { 63 return get_user_meta( $vendor_id, '_vendor_cod24_shipping_token', true ); 64 } else { 65 return get_option('cod24_shipping_token'); 66 } 67 } 68 69 /** 32 70 * Get cod24 rate 33 71 * 34 72 * @param data 73 * @param int|null $vendor_id Optional vendor ID 35 74 * @return final_result array | return code & total price of rate 36 75 */ 37 public static function get_rate( $data )76 public static function get_rate( $data, $vendor_id = null ) 38 77 { 39 78 $final_result = []; 40 $cod24_token = get_option('cod24_shipping_token'); 79 $cod24_token = self::get_stored_token( $vendor_id ); 80 $credentials = self::get_credentials( $vendor_id ); 41 81 42 82 if( !empty( $cod24_token ) ) … … 44 84 45 85 // send to api 46 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';86 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 47 87 $url = $api_protocol.'api.cod24.ir/api/OrderTipax/getTipaxPrice'; 48 88 $body = array( … … 64 104 'method' => 'POST', 65 105 'timeout' => 500, 66 'sslverify' => true,106 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 67 107 'headers' => array( 68 108 'Authorization' => 'Bearer '.$cod24_token, … … 284 324 'height' => ( !empty( $custom_total_dimension['height'] ) && $custom_total_dimension['height'] > 0 ) ? floatval( $custom_total_dimension['height'] ) : 0, 285 325 'isUnusual' => ( !empty( $non_standard_package ) && $non_standard_package == 'yes' ) ? (bool) 1 : (bool) 0, 286 'serviceId' => 1,326 'serviceId' => 2, 287 327 'idPickupType' => $idPickupType, 288 328 'idDistributionType' => $idDistributionType … … 293 333 294 334 /** 295 * Add suspendorder on cod24 panel335 * Add order on cod24 panel 296 336 * 297 337 * @param order_id int 338 * @param int|null $vendor_id Optional vendor ID 298 339 * @return final_result array | return code & total price of rate 299 340 */ 300 public static function add_order( $order_id )341 public static function add_order( $order_id, $vendor_id = null ) 301 342 { 302 343 $final_result = []; 303 344 $sanitized_data = []; 304 $cod24_token = get_option('cod24_shipping_token'); 345 $cod24_token = self::get_stored_token( $vendor_id ); 346 $credentials = self::get_credentials( $vendor_id ); 305 347 306 348 if( !empty( $cod24_token ) ) 307 349 { 308 350 // send to api 309 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';351 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 310 352 $url = $api_protocol.'api.cod24.ir/api/OrderTipax/addOrderBatch'; 311 353 $sanitized_data[] = self::prepare_data( $order_id ); … … 317 359 'method' => 'POST', 318 360 'timeout' => 500, 319 'sslverify' => true,361 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 320 362 'headers' => array( 321 363 'Authorization' => 'Bearer '.$cod24_token, … … 332 374 $result = json_decode( $response, true ); 333 375 $final_result['code'] = wp_remote_retrieve_response_code( $request ); 334 $final_result['message'] = $result[ 0]['message'];376 $final_result['message'] = $result['message']; 335 377 if( !empty( $result[0]['errors'] ) ) 336 378 { … … 370 412 * 371 413 * @param order_ids array 414 * @param int|null $vendor_id Optional vendor ID 372 415 * @return final_result array | return code & total price of rate 373 416 */ 374 public static function add_order_batch( $order_ids )417 public static function add_order_batch( $order_ids, $vendor_id = null ) 375 418 { 376 419 $final_result_list = []; 377 420 $sanitized_data = []; 378 $cod24_token = get_option('cod24_shipping_token'); 421 $cod24_token = self::get_stored_token( $vendor_id ); 422 $credentials = self::get_credentials( $vendor_id ); 379 423 380 424 if( !empty( $cod24_token ) ) 381 425 { 382 426 // send to api 383 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';427 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 384 428 $url = $api_protocol.'api.cod24.ir/api/OrderTipax/addOrderBatch'; 385 429 if( !empty( $order_ids ) ) … … 396 440 'method' => 'POST', 397 441 'timeout' => 500, 398 'sslverify' => true,442 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 399 443 'headers' => array( 400 444 'Authorization' => 'Bearer '.$cod24_token, … … 464 508 * 465 509 * @param params 510 * @param int|null $vendor_id Optional vendor ID 466 511 * @return final_result array | return code & total price of rate 467 512 */ 468 public static function ready_to_send_order( $params )513 public static function ready_to_send_order( $params, $vendor_id = null ) 469 514 { 470 515 $final_result = []; 471 $cod24_token = get_option('cod24_shipping_token'); 516 $cod24_token = self::get_stored_token( $vendor_id ); 517 $credentials = self::get_credentials( $vendor_id ); 472 518 473 519 if( !empty( $cod24_token ) ) 474 520 { 475 521 // send to api 476 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';522 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 477 523 $url = $api_protocol.'api.cod24.ir/api/OrderTipax/readyToSendOrder'; 478 524 … … 483 529 'method' => 'POST', 484 530 'timeout' => 500, 485 'sslverify' => true,531 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 486 532 'headers' => array( 487 533 'Authorization' => 'Bearer '.$cod24_token, … … 518 564 * 519 565 * @param params 566 * @param int|null $vendor_id Optional vendor ID 520 567 * @return final_result array | return code & total price of rate 521 568 */ 522 public static function cancel_order( $params )569 public static function cancel_order( $params, $vendor_id = null ) 523 570 { 524 571 $final_result = []; 525 $cod24_token = get_option('cod24_shipping_token'); 572 $cod24_token = self::get_stored_token( $vendor_id ); 573 $credentials = self::get_credentials( $vendor_id ); 526 574 527 575 if( !empty( $cod24_token ) ) 528 576 { 529 577 // send to api 530 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled')=='yes' ) ? 'https://' : 'http://';578 $api_protocol = ( $credentials['secure'] == 'yes' ) ? 'https://' : 'http://'; 531 579 $url = $api_protocol.'api.cod24.ir/api/OrderTipax/cancelOrder'; 532 580 … … 537 585 'method' => 'POST', 538 586 'timeout' => 500, 539 'sslverify' => true,587 'sslverify' => ( $credentials['secure'] == 'yes' ) ? true : false, 540 588 'headers' => array( 541 589 'Authorization' => 'Bearer '.$cod24_token, … … 579 627 $result = []; 580 628 581 // send to api582 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled') =='yes' ) ? 'https://' : 'http://';629 // get tipax cities from cdn 630 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled') == 'yes' ) ? 'https://' : 'http://'; 583 631 $url = $api_protocol.'apicod24.s3.ir-thr-at1.arvanstorage.ir/TipaxCities.json'; 584 632 $body = []; … … 634 682 { 635 683 $result = []; 636 $cod24_token = get_option('cod24_shipping_token');637 638 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled') =='yes' ) ? 'https://' : 'http://';684 685 // get all cities from api 686 $api_protocol = ( get_option('cod24_shipping_api_secure_connection_enabled') == 'yes' ) ? 'https://' : 'http://'; 639 687 $url = $api_protocol.'apicod24.s3.ir-thr-at1.arvanstorage.ir/TipaxCities.json'; 640 688 $body = []; … … 659 707 // Update the values of the 'cityNameFa' key for all elements in the array 660 708 foreach ($result as &$item) { 661 $item['cityNameFa'] = self:: sanitize_first_last_space_character($item['cityNameFa']);709 $item['cityNameFa'] = self::convert_arabic_to_persian_character( self::sanitize_first_last_space_character($item['cityNameFa']) ); 662 710 } 663 711 } … … 708 756 'state_id' => $value['stateCode'], 709 757 'city_id' => $value['cityCode'], 710 'city_name' => self:: sanitize_first_last_space_character( $value['cityNameFa'])758 'city_name' => self::convert_arabic_to_persian_character( self::sanitize_first_last_space_character( $value['cityNameFa'] ) ) 711 759 ]; 712 760 } … … 727 775 public static function find_city( $user_city_name ) 728 776 { 729 $sanitize_user_city_name = self::sanitize_first_last_space_character( $user_city_name ); 777 // convert user city characters from arabic to persian 778 $arabic = array('ي', 'ك'); 779 $farsi = array('ی', 'ک'); 780 $user_city_name=str_replace($arabic, $farsi, $user_city_name); 781 782 $sanitize_user_city_name = self::convert_arabic_to_persian_character( self::sanitize_first_last_space_character( $user_city_name ) ); 730 783 $data = self::get_all_cities(); 731 784 … … 759 812 760 813 return $str; 814 } 815 816 public static function convert_arabic_to_persian_character($string) 817 { 818 $characters = [ 819 'ك' => 'ک', 820 'دِ' => 'د', 821 'بِ' => 'ب', 822 'زِ' => 'ز', 823 'ذِ' => 'ذ', 824 'شِ' => 'ش', 825 'سِ' => 'س', 826 'ى' => 'ی', 827 'ي' => 'ی', 828 '١' => '۱', 829 '٢' => '۲', 830 '٣' => '۳', 831 '٤' => '۴', 832 '٥' => '۵', 833 '٦' => '۶', 834 '٧' => '۷', 835 '٨' => '۸', 836 '٩' => '۹', 837 '٠' => '۰', 838 ]; 839 return str_replace(array_keys($characters), array_values($characters),$string); 761 840 } 762 841 -
cod24-shipping/trunk/inc/class-cod24-shcod.php
r3254068 r3399647 1 1 <?php 2 2 /** 3 * COD24 API4 * This class is connecting to COD24 API.3 * COD24 SHCOD 4 * This class is for shipping cost on delivery 5 5 * 6 6 * Package: COD24 Shipping -
cod24-shipping/trunk/inc/class-cod24-woo.php
r3366748 r3399647 319 319 $fields['city']['priority'] = 60; 320 320 $fields['address_1']['priority'] = 70; 321 //$fields['address_2']['priority'] = 80;321 322 322 return $fields; 323 323 } … … 486 486 </div> 487 487 <div class="cod24-meta-fields" style="margin-bottom:10px"> 488 <input type="checkbox" class="postbox is_calc_srv_by_weight" id="is_calc_srv_by_weight" style="margin-bottom:0px" name="is_calc_srv_by_weight" value="yes" <?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['is_calc_srv_by_weight'] ) && $order_cod24_info['is_calc_srv_by_weight'] == 'yes' ) checked( 'yes', $order_cod24_info['is_calc_srv_by_weight'] ); ?>/> 489 <label for="is_calc_srv_by_weight"><?php esc_attr_e('Calculate service cost by weight', 'cod24-shipping'); ?></label> 490 <div class="description"><?php esc_attr_e('If checked, carton size will be set to 0 and service cost will be calculated based on weight only.', 'cod24-shipping'); ?></div> 491 </div> 492 <div class="cod24-meta-fields" style="margin-bottom:10px"> 488 493 <div class="label" style="margin-bottom:10px"><label for="carton_size"><?php esc_attr_e('Carton Size', 'cod24-shipping'); ?></label></div> 489 <select name="carton_size" id="carton_size" class="postbox carton_size" style="margin-bottom:10px" >494 <select name="carton_size" id="carton_size" class="postbox carton_size" style="margin-bottom:10px" <?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['is_calc_srv_by_weight'] ) && $order_cod24_info['is_calc_srv_by_weight'] == 'yes' ) echo 'disabled'; ?>> 490 495 <option value="none"><?php esc_attr_e('Select the size...','cod24-shipping'); ?></option> 491 496 <?php foreach(COD24_API::get_carton_sizes() as $key => $carton_item) : ?> … … 660 665 $cod24_info['non_standard_package'] = 'no'; 661 666 662 // check carton size 663 $carton_sizes = COD24_API::get_carton_sizes(); 664 $user_carton_size = sanitize_text_field( $_POST['carton_size'] ); 665 if( in_array( $user_carton_size, array_keys( $carton_sizes ) ) ) 666 { 667 $cod24_info['carton_size'] = $user_carton_size; 668 } 669 670 // check content parcel 671 if( isset( $_POST['content_parcel'] ) && !empty( $_POST['content_parcel'] ) ) 672 { 673 $cod24_info['content_parcel'] = sanitize_textarea_field( $_POST['content_parcel'] ); 674 } 667 // check is_calc_srv_by_weight 668 if( isset( $_POST['is_calc_srv_by_weight'] ) && $_POST['is_calc_srv_by_weight'] == 'yes' ) 669 { 670 $cod24_info['is_calc_srv_by_weight'] = 'yes'; 671 $cod24_info['carton_size'] = 0; // Set carton size to 0 when calculating by weight 672 } 673 else 674 { 675 $cod24_info['is_calc_srv_by_weight'] = 'no'; 676 // check carton size 677 $carton_sizes = COD24_API::get_carton_sizes(); 678 $user_carton_size = sanitize_text_field( $_POST['carton_size'] ); 679 if( in_array( $user_carton_size, array_keys( $carton_sizes ) ) ) 680 { 681 $cod24_info['carton_size'] = $user_carton_size; 682 } 683 } 684 685 // check content parcel 686 if( isset( $_POST['content_parcel'] ) && !empty( $_POST['content_parcel'] ) ) 687 { 688 $cod24_info['content_parcel'] = sanitize_textarea_field( $_POST['content_parcel'] ); 689 } 675 690 } 676 691 elseif( $old_cod24_info['shipping_type'] == 'tipax' && isset( $_POST['tipax_custom_total_weight'] ) && !empty( $_POST['tipax_custom_total_weight'] ) ) … … 763 778 { 764 779 $order_id = intval( $_REQUEST['order_id'] ); 780 765 781 $cod24_new_status = sanitize_text_field( $_REQUEST['cod24_status'] ); // user enter custom total weight 766 782 767 783 // check and get order info 768 784 if( !empty( $order_id ) && absint( $order_id ) > 0 ) … … 790 806 $cod24_info['non_standard_package'] = 'no'; 791 807 792 // check carton size 793 $carton_sizes = COD24_API::get_carton_sizes(); 794 $user_carton_size = sanitize_text_field( $_POST['carton_size'] ); 795 if( in_array( $user_carton_size, array_keys( $carton_sizes ) ) ) 796 { 797 $cod24_info['carton_size'] = $user_carton_size; 798 } 808 // check is_calc_srv_by_weight 809 if( isset( $_POST['is_calc_srv_by_weight'] ) && $_POST['is_calc_srv_by_weight'] == 'yes' ) 810 { 811 $cod24_info['is_calc_srv_by_weight'] = 'yes'; 812 $cod24_info['carton_size'] = 0; // Set carton size to 0 when calculating by weight 813 } 814 else 815 { 816 $cod24_info['is_calc_srv_by_weight'] = 'no'; 817 // check carton size 818 $carton_sizes = COD24_API::get_carton_sizes(); 819 $user_carton_size = sanitize_text_field( $_POST['carton_size'] ); 820 if( in_array( $user_carton_size, array_keys( $carton_sizes ) ) ) 821 { 822 $cod24_info['carton_size'] = $user_carton_size; 823 } 824 } 799 825 800 826 // check content parcel … … 890 916 else 891 917 { 918 // Get vendor id 919 $vendor_id = self::get_vendor_id_for_shipping( $order_id ); 920 892 921 if( $cod24_info['shipping_type'] == 'tipax' ) 893 $result = COD24_Tipax_API::add_order( $order_id );922 $result = COD24_Tipax_API::add_order( $order_id, $vendor_id ); 894 923 else 895 $result = COD24_API::add_order( $order_id );924 $result = COD24_API::add_order( $order_id, $vendor_id ); 896 925 897 926 if( !empty( $result['serial'] ) ) … … 977 1006 if( $cod24_info['shipping_type'] == 'post' ) // suspend order only for post shipping 978 1007 { 979 $result = COD24_API::suspend_order( array( array( 'serial' => absint( $cod24_info['serial'] ), 'idOrderShop' => strval( $order_id ) ) ) ); 1008 // Get vendor id 1009 $vendor_id = self::get_vendor_id_for_shipping( $order_id ); 1010 1011 $result = COD24_API::suspend_order( array( array( 'serial' => absint( $cod24_info['serial'] ), 'idOrderShop' => strval( $order_id ) ) ), $vendor_id ); 980 1012 981 1013 if( !empty( $result[0]['barcode'] ) && $result[0]['isSuccess'] && $result[0]['code'] == 0 ) … … 1062 1094 else 1063 1095 { 1064 $result = COD24_API::ready_to_send_order( array( array( 'serial' => absint( $cod24_info['serial'] ), 'idOrderShop' => strval( $order_id ) ) ) ); 1096 // Get vendor id 1097 $vendor_id = self::get_vendor_id_for_shipping( $order_id ); 1098 1099 $result = COD24_API::ready_to_send_order( array( array( 'serial' => absint( $cod24_info['serial'] ), 'idOrderShop' => strval( $order_id ) ) ), $vendor_id ); 1065 1100 1066 1101 if( $result[0]['isSuccess'] && $result[0]['code'] == 0 ) … … 1112 1147 else 1113 1148 { 1114 $result = COD24_Tipax_API::ready_to_send_order( array( array( 'serial' => absint( $cod24_info['serial'] ), 'idOrderShop' => strval( $order_id ) ) ) ); 1149 // Get vendor id 1150 $vendor_id = self::get_vendor_id_for_shipping( $order_id ); 1151 1152 $result = COD24_Tipax_API::ready_to_send_order( array( array( 'serial' => absint( $cod24_info['serial'] ), 'idOrderShop' => strval( $order_id ) ) ), $vendor_id ); 1115 1153 1116 1154 if( $result[0]['isSuccess'] && $result[0]['code'] == 0 ) … … 1164 1202 else 1165 1203 { 1204 // Get vendor id 1205 $vendor_id = self::get_vendor_id_for_shipping( $order_id ); 1206 1166 1207 if( $cod24_info['shipping_type'] == 'tipax' ) 1167 $result = COD24_Tipax_API::cancel_order( array( array( 'serial' => $cod24_info['serial'], 'idOrderShop' => strval( $order_id ) ) ) );1208 $result = COD24_Tipax_API::cancel_order( array( array( 'serial' => $cod24_info['serial'], 'idOrderShop' => strval( $order_id ) ) ), $vendor_id ); 1168 1209 else 1169 $result = COD24_API::cancel_order( array( array( 'serial' => $cod24_info['serial'], 'idOrderShop' => strval( $order_id ) ) ) );1210 $result = COD24_API::cancel_order( array( array( 'serial' => $cod24_info['serial'], 'idOrderShop' => strval( $order_id ) ) ), $vendor_id ); 1170 1211 1171 1212 if( $result[0]['isSuccess'] && $result[0]['code'] == 0 ) … … 1215 1256 $result = array( 'status' => false, 'msg' => $error_message, 'url' => add_query_arg( array( 'post' => $order_id , 'action' => 'edit' ), admin_url( 'post.php' ) ) ); 1216 1257 else 1217 $result = array( 'status' => true , 'url' => add_query_arg( array( 'post' => $order_id , 'action' => 'edit' ), admin_url( 'post.php' ) ));1258 $result = array( 'status' => true ); 1218 1259 } 1219 1260 else … … 1254 1295 if( !empty( $cod24_info['serial'] ) ) 1255 1296 { 1297 $vendor_id = self::get_vendor_id_for_shipping( $order_id ); 1298 1256 1299 $data[] = [ 'serial' => (int) $cod24_info['serial'] ]; 1257 $factor_preview_result = COD24_API::factor_preview( $data );1300 $factor_preview_result = COD24_API::factor_preview( $data, $vendor_id ); 1258 1301 if( !empty( $factor_preview_result['url'] ) ) 1259 1302 { … … 1263 1306 else 1264 1307 { 1265 $message = sprintf( esc_attr__('There was an error in getting factor preview from COD24 panel. Error: %s ', 'cod24-shipping'), $ result['code']. " - ". $result['message'] );1308 $message = sprintf( esc_attr__('There was an error in getting factor preview from COD24 panel. Error: %s ', 'cod24-shipping'), $factor_preview_result['code']. " - ". $factor_preview_result['message'] ); 1266 1309 $result = array('status' => false , 'msg' => $message ); 1267 1310 } … … 1820 1863 1821 1864 if( !empty( $post_sanitized_data ) ) 1822 $post_result = COD24_API::add_order_batch( $post_sanitized_data ); 1865 { 1866 // Get first vendor id 1867 $vendor_id = self::get_vendor_id_for_shipping( $post_sanitized_data[0] ); 1868 1869 $post_result = COD24_API::add_order_batch( $post_sanitized_data, $vendor_id ); 1870 } 1823 1871 1824 1872 if( !empty( $tipax_sanitized_data ) ) 1825 $tipax_result = COD24_Tipax_API::add_order_batch( $tipax_sanitized_data ); 1873 { 1874 // Get first vendor id 1875 $vendor_id = self::get_vendor_id_for_shipping( $tipax_sanitized_data[0] ); 1876 1877 $tipax_result = COD24_Tipax_API::add_order_batch( $tipax_sanitized_data, $vendor_id ); 1878 } 1826 1879 1827 1880 $result = array_merge($post_result, $tipax_result); 1828 1829 error_log("RESULT DEBUG BATCH:" . print_r($result, true ) );1830 1881 1831 1882 if( !empty( $result ) ) … … 1921 1972 $post_result = []; 1922 1973 $tipax_result = []; 1974 1923 1975 if( !empty( $post_sanitized_data ) ) 1924 $post_result = COD24_API::suspend_order( $post_sanitized_data ); 1976 { 1977 // Get first vendor id 1978 $vendor_id = self::get_vendor_id_for_shipping( $post_sanitized_data[0] ); 1979 1980 $post_result = COD24_API::suspend_order( $post_sanitized_data, $vendor_id ); 1981 } 1925 1982 1926 1983 $result = array_merge($post_result, $tipax_result); … … 1989 2046 1990 2047 if( !empty( $post_sanitized_data ) ) 1991 $post_result = COD24_API::ready_to_send_order( $post_sanitized_data ); 2048 { 2049 // Get first vendor id 2050 $vendor_id = self::get_vendor_id_for_shipping( $post_sanitized_data[0] ); 2051 2052 $post_result = COD24_API::ready_to_send_order( $post_sanitized_data, $vendor_id ); 2053 } 1992 2054 1993 2055 if( !empty( $tipax_sanitized_data ) ) 1994 $tipax_result = COD24_Tipax_API::ready_to_send_order( $tipax_sanitized_data ); 2056 { 2057 // Get first vendor id 2058 $vendor_id = self::get_vendor_id_for_shipping( $tipax_sanitized_data[0] ); 2059 2060 $tipax_result = COD24_Tipax_API::ready_to_send_order( $tipax_sanitized_data, $vendor_id ); 2061 } 1995 2062 1996 2063 $result = array_merge($post_result, $tipax_result); … … 2058 2125 $post_result = []; 2059 2126 $tipax_result = []; 2127 2060 2128 if( !empty( $post_sanitized_data ) ) 2061 $post_result = COD24_API::cancel_order( $post_sanitized_data ); 2129 { 2130 // Get first vendor id 2131 $vendor_id = self::get_vendor_id_for_shipping( $post_sanitized_data[0] ); 2132 2133 $post_result = COD24_API::cancel_order( $post_sanitized_data, $vendor_id ); 2134 } 2062 2135 2063 2136 if( !empty( $tipax_sanitized_data ) ) 2064 $tipax_result = COD24_Tipax_API::cancel_order( $tipax_sanitized_data ); 2137 { 2138 // Get first vendor id 2139 $vendor_id = self::get_vendor_id_for_shipping( $tipax_sanitized_data[0] ); 2140 2141 $tipax_result = COD24_Tipax_API::cancel_order( $tipax_sanitized_data, $vendor_id ); 2142 } 2065 2143 2066 2144 $result = array_merge($post_result, $tipax_result); … … 2218 2296 wp_die(); 2219 2297 } 2298 2299 public static function is_dokan_shipping_enabled() 2300 { 2301 // Dokan core must be active 2302 if ( ! class_exists( 'WeDevs_Dokan' ) && ! function_exists( 'dokan' ) ) { 2303 return false; 2304 } 2305 2306 // Dokan Pro must be active (several possible checks) 2307 $pro_available = defined( 'DOKAN_PRO_INC' ) || function_exists( 'dokan_pro' ) || class_exists( 'WeDevs_Dokan_Pro' ); 2308 if ( ! $pro_available ) { 2309 return false; 2310 } 2311 2312 // Common WooCommerce / Dokan option name you mentioned: 2313 $opt = get_option( 'woocommerce_dokan_product_shipping_enabled', null ); 2314 if ( $opt != '1' ) { 2315 return false; 2316 } 2317 2318 return true; 2319 } 2320 2321 /** 2322 * Get vendor ID for appropriate shipping token usage 2323 * 2324 * @param int $order_id Order ID 2325 * @return int|null Returns vendor_id if valid vendor exists, null otherwise (uses admin token) 2326 */ 2327 public static function get_vendor_id_for_shipping($order_id) 2328 { 2329 // Default: use admin settings 2330 $vendor_id = null; 2331 2332 // Check if Dokan Shipping is enabled 2333 if (!self::is_dokan_shipping_enabled()) { 2334 return null; // Use admin token 2335 } 2336 2337 // Check if dokan function exists 2338 if (!function_exists('dokan_get_seller_id_by_order')) { 2339 return null; // Use admin token 2340 } 2341 2342 // Get vendor ID from order 2343 $vendor_ids = \dokan_get_seller_id_by_order($order_id); 2344 2345 // Get the first vendor 2346 $potential_vendor_id = (is_array($vendor_ids)) ? reset($vendor_ids) : (int) $vendor_ids; 2347 2348 // If vendor_id is not valid 2349 if (empty($potential_vendor_id) || $potential_vendor_id <= 0) { 2350 return null; 2351 } 2352 2353 // Check if this user is actually a vendor/seller 2354 if (function_exists('dokan_is_user_seller')) { 2355 if (dokan_is_user_seller($potential_vendor_id)) { 2356 return $potential_vendor_id; // Return valid vendor_id 2357 } 2358 } 2359 2360 // If not a valid vendor, use admin token 2361 return null; 2362 } 2220 2363 2221 2364 } // END class COD24_WOO -
cod24-shipping/trunk/inc/shipping/class-cod24-pishtaz.php
r3354882 r3399647 99 99 if(empty($user_delivery_address['state_id']) && empty($user_delivery_address['city_id'])) 100 100 $available = false; 101 102 // Check weight range 103 if ( $available && !empty($package['contents']) ) { 104 $min_weight = 30; // gram 105 $max_weight = 20000; // gram 106 $weight = 0; 107 108 foreach ($package['contents'] as $item_id => $values) { 109 $_product = $values['data']; 110 $weight = $weight + ( floatval( $_product->get_weight() ) * absint( $values['quantity'] ) ); 111 } 112 113 // Convert weight to grams 114 $weight = wc_get_weight($weight, 'g'); 115 116 // If weight is outside the valid range, make shipping unavailable 117 if ($weight < $min_weight || $weight > $max_weight) { 118 $available = false; 119 } 120 } 101 121 102 122 return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', $available, $package, $this ); … … 242 262 function C24_pishtaz_shipping($methods) 243 263 { 244 $methods['cod24_pishtaz'] = ' cod24_pishtaz_shipping';264 $methods['cod24_pishtaz'] = 'COD24_Pishtaz_Shipping'; 245 265 return $methods; 246 266 } -
cod24-shipping/trunk/inc/shipping/class-cod24-special.php
r3354882 r3399647 104 104 if(empty($user_delivery_address['state_id']) && empty($user_delivery_address['city_id'])) 105 105 $available = false; 106 107 // Check weight range 108 if ( $available && !empty($package['contents']) ) { 109 $min_weight = 30; // gram 110 $max_weight = 20000; // gram 111 $weight = 0; 112 113 foreach ($package['contents'] as $item_id => $values) { 114 $_product = $values['data']; 115 $weight = $weight + ( floatval( $_product->get_weight() ) * absint( $values['quantity'] ) ); 116 } 117 118 // Convert weight to grams 119 $weight = wc_get_weight($weight, 'g'); 120 121 // If weight is outside the valid range, make shipping unavailable 122 if ($weight < $min_weight || $weight > $max_weight) { 123 $available = false; 124 } 125 } 106 126 107 127 return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', $available, $package, $this ); … … 247 267 function C24_special_shipping($methods) 248 268 { 249 $methods['cod24_special'] = ' cod24_special_shipping';269 $methods['cod24_special'] = 'COD24_Special_Shipping'; 250 270 return $methods; 251 271 } -
cod24-shipping/trunk/inc/shipping/class-cod24-tipax.php
r3264094 r3399647 108 108 $available = false; 109 109 } 110 111 // Check weight range 112 if ( $available && !empty($package['contents']) ) { 113 $min_weight = 30; // gram 114 $max_weight = 20000; // gram 115 $weight = 0; 116 117 foreach ($package['contents'] as $item_id => $values) { 118 $_product = $values['data']; 119 $weight = $weight + ( floatval( $_product->get_weight() ) * absint( $values['quantity'] ) ); 120 } 121 122 // Convert weight to grams 123 $weight = wc_get_weight($weight, 'g'); 124 125 // If weight is outside the valid range, make shipping unavailable 126 if ($weight < $min_weight || $weight > $max_weight) { 127 $available = false; 128 } 129 } 110 130 111 131 return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', $available, $package, $this ); … … 159 179 function C24_tipax_shipping($methods) 160 180 { 161 $methods['cod24_tipax'] = ' cod24_tipax_shipping';181 $methods['cod24_tipax'] = 'COD24_Tipax_Shipping'; 162 182 return $methods; 163 183 } -
cod24-shipping/trunk/readme.txt
r3366748 r3399647 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 4.0.106 Stable tag: 5.0 7 7 License: GPL-2.0+ 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 22 22 - Ability to activate Tipax shipping 23 23 - Ability to activate Chapar & Alopeyk (coming soon) 24 - Dokan Support 24 25 25 26 == Installation == … … 43 44 44 45 == Changelog == 46 47 = 5.0 = 48 * Dokan (Multi-Vendor) Support 49 * Bugs fixes and improvements 45 50 46 51 = 4.0.10 =
Note: See TracChangeset
for help on using the changeset viewer.