Changeset 3237612
- Timestamp:
- 02/10/2025 06:40:11 AM (13 months ago)
- Location:
- shipany
- Files:
-
- 8 edited
- 1 copied
-
tags/1.1.68 (copied) (copied from shipany/trunk)
-
tags/1.1.68/includes/Utils/ShipanyHelper.php (modified) (11 diffs)
-
tags/1.1.68/includes/abstract-shipany-wc-order.php (modified) (8 diffs)
-
tags/1.1.68/includes/class-shipany-wc-method-ecs-asia.php (modified) (3 diffs)
-
tags/1.1.68/shipany-woocommerce.php (modified) (6 diffs)
-
trunk/includes/Utils/ShipanyHelper.php (modified) (11 diffs)
-
trunk/includes/abstract-shipany-wc-order.php (modified) (8 diffs)
-
trunk/includes/class-shipany-wc-method-ecs-asia.php (modified) (3 diffs)
-
trunk/shipany-woocommerce.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shipany/tags/1.1.68/includes/Utils/ShipanyHelper.php
r3227976 r3237612 143 143 } 144 144 145 /** 146 * Build the payload for the order creation 147 * @param mixed $wc_order_id 148 * @param array $shipany_data { 149 * @type string $mode - query or create, default is query 150 * @type string $cour_uid 151 * @type string $cour_svc_pl 152 * @type string $storage_type 153 * @type bool $paid_by_rcvr 154 * @type bool $auto 155 * 156 * } 157 * @return array 158 * $shipany_data = 159 * 160 * 161 * 162 */ 163 public static function build_shipany_order_payload($wc_order_id, $shipany_data = array()) { 145 public static function build_shipany_order_payload_by_data($address, $packages, $shipany_data = array()) { 164 146 $shipany_data = array_merge( 165 147 array( … … 175 157 'location_uid' => '', // static::get_settings('shipany_default_location'), 176 158 'incoterms' => static::get_settings('shipany_incoterms'), 159 'description' => " ", 160 'ccy' => get_woocommerce_currency(), 177 161 ), 178 162 $shipany_data … … 181 165 $shipany_data['mode'] = 'query'; 182 166 } 183 $wc_order = wc_get_order($wc_order_id);184 167 185 168 $merchant_info = static::get_merchant_info(); … … 268 251 $items = array(); 269 252 $items_value_total = 0; 270 foreach ($wc_order->get_items() as $item) { 253 $items_weight_total = 0; 254 foreach ($packages as $item) { 271 255 $product = wc_get_product($item['product_id']); 272 $item_value = $item['line_total'] / $item['qty']; 256 $qty = $item['qty'] ?? $item['quantity'] ?? 0; 257 $item_value = $item['line_total'] / $qty; 273 258 if (empty($product) || $product->is_virtual()) { 274 259 continue; … … 309 294 } 310 295 $sa_item_weight = floatval(static::convert_wc_weight_to_kg($item_weight)); 311 $items_value_total += floatval($item_value) * floatval($item['qty']); 296 $items_value_total += floatval($item_value) * floatval($qty); 297 $items_weight_total += $sa_item_weight * floatval($qty); 312 298 $item_array = array( 313 299 "sku" => "" . $sku, … … 318 304 "unt_price" => array( 319 305 "val" => empty($item_value) ? 0.01 : floatval($item_value), 320 "ccy" => $ wc_order->get_currency()306 "ccy" => $shipany_data['ccy'], 321 307 ), 322 "qty" => floatval($ item['qty']),308 "qty" => floatval($qty), 323 309 "wt" => array( 324 310 "val" => $sa_item_weight > 0 ? $sa_item_weight : 0, … … 343 329 } 344 330 // If not USA or Australia, then change state from ISO code to name 345 if ($ shipping_address['country'] != 'US' && $shipping_address['country'] != 'AU') {331 if ($address['country'] != 'US' && $address['country'] != 'AU') { 346 332 // Get all states for a country 347 $states = WC()->countries->get_states($ shipping_address['country']);333 $states = WC()->countries->get_states($address['country']); 348 334 349 335 // If the state is empty, it was entered as free text 350 if (!empty($states) && !empty($ shipping_address['state'])) {336 if (!empty($states) && !empty($address['state'])) { 351 337 // Change the state to be the name and not the code 352 $ shipping_address['state'] = $states[$shipping_address['state']];338 $address['state'] = $states[$address['state']]; 353 339 354 340 // Remove anything in parentheses (e.g. TH) 355 $ind = strpos($ shipping_address['state'], " (");341 $ind = strpos($address['state'], " ("); 356 342 if (false !== $ind) { 357 $ shipping_address['state'] = substr($shipping_address['state'], 0, $ind);343 $address['state'] = substr($address['state'], 0, $ind); 358 344 } 359 345 } … … 403 389 "mch_ttl_val" => array( 404 390 "val" => $items_value_total, 405 "ccy" => $ wc_order->get_currency()391 "ccy" => $shipany_data['ccy'] 406 392 ), 407 393 'cour_ttl_cost' => array( 408 394 'val' => 1, 409 'ccy' => $ wc_order->get_currency()395 'ccy' => $shipany_data['ccy'] 410 396 ), 411 397 "sndr_ctc" => $sndr_ctc, … … 413 399 "ctc" => array( 414 400 "tit" => "", 415 "f_name" => $ shipping_address['first_name'],416 "l_name" => $ shipping_address['last_name'],401 "f_name" => $address['first_name'], 402 "l_name" => $address['last_name'], 417 403 "phs" => array( 418 404 array( 419 405 "typ" => "Mobile", 420 'cnty_code' => str_replace('+', '', WC()->countries->get_country_calling_code($ wc_order->get_shipping_country())),421 'num' => $ shipping_address["phone"]406 'cnty_code' => str_replace('+', '', WC()->countries->get_country_calling_code($address['country'])), 407 'num' => $address["phone"] 422 408 ) 423 409 ), 424 'email' => $ shipping_address['email'],410 'email' => $address['email'], 425 411 "note" => "", 426 "co_name" => isset($ shipping_address['company']) ? $shipping_address['company'] : ''412 "co_name" => isset($address['company']) ? $address['company'] : '' 427 413 ), 428 414 "addr" => array( 429 415 "typ" => "Residential", 430 "ln" => $ shipping_address["address_1"],431 "ln2" => isset($ shipping_address["address_2"]) ? $shipping_address["address_2"] : '',416 "ln" => $address["address_1"], 417 "ln2" => isset($address["address_2"]) ? $address["address_2"] : '', 432 418 "ln3" => "", 433 "distr" => $wrong_rcvr_addr_format ? (isset($ shipping_address["district"]) ? $shipping_address["district"] : '') : $shipping_address["city"],419 "distr" => $wrong_rcvr_addr_format ? (isset($address["district"]) ? $address["district"] : '') : $address["city"], 434 420 "cnty" => $alpha_three_country_code, 435 421 'state' => $wrong_rcvr_addr_format ? '' : (static::get_settings('shipany_region') == 2 ? '' : $shipping_address["state"]), … … 444 430 if ($shipany_data["description"] != " ") { 445 431 $payload['mch_notes'] = array($shipany_data["description"]); 432 } 433 434 return \SHIPANY\Utils\Args_Parser::unset_empty_values($payload); 435 } 436 437 /** 438 * Build the payload for the order creation 439 * @param mixed $wc_order_id 440 * @param array $shipany_data { 441 * @type string $mode - query or create, default is query 442 * @type string $cour_uid 443 * @type string $cour_svc_pl 444 * @type string $storage_type 445 * @type bool $paid_by_rcvr 446 * @type bool $auto 447 * 448 * } 449 * @return array 450 * $shipany_data = 451 * 452 * 453 * 454 */ 455 public static function build_shipany_order_payload_by_wc_order_id($wc_order_id, $shipany_data = array()) { 456 $shipany_data = array_merge( 457 array( 458 'mode' => 'query', 459 'cour_uid' => '', 460 'cour_svc_pl' => '', 461 'storage_type' => static::get_settings('set_default_storage_type'), 462 'paid_by_rcvr' => static::get_settings('shipany_paid_by_rec') == 'yes', 463 'auto' => false, 464 'add-ons' => array(), // for lalamove, keep the structure of the add-ons 465 'description' => " " 466 ), 467 $shipany_data 468 ); 469 if (!in_array($shipany_data['mode'], ['query', 'create'])) { 470 $shipany_data['mode'] = 'query'; 471 } 472 $wc_order = wc_get_order($wc_order_id); 473 $shipany_data['ccy'] = $wc_order->get_currency(); 474 $shipping_address = array_merge( 475 (array) $wc_order->get_address('billing'), 476 \SHIPANY\Utils\Args_Parser::unset_empty_values((array) $wc_order->get_address('shipping')) 477 ); 478 $payload = static::build_shipany_order_payload_by_data($shipping_address, $wc_order->get_items(), $shipany_data); 479 $payload['ext_order_ref'] = $wc_order->get_order_number() . (static::get_settings("shipany_customize_order_id") ? static::get_settings("shipany_customize_order_id") : ''); 480 $payload["wt"] = array( 481 "val" => floatval(static::calculate_order_weight($wc_order)) ?: 1, 482 "unt" => "kg" 483 ); 484 if (strval($wc_order->get_order_number()) != strval($wc_order_id)) { 485 $payload['ext_order_id'] = strval($wc_order_id); 446 486 } 447 487 … … 759 799 760 800 return apply_filters('shipping_shipany_order_weight', $total_weight, $order_id); 801 } 802 803 protected static function calculate_order_weight_by_items($items) { 804 761 805 } 762 806 -
shipany/tags/1.1.68/includes/abstract-shipany-wc-order.php
r3227216 r3237612 170 170 } 171 171 172 $data = ShipanyHelper::build_shipany_order_payload ($_POST['order_id'], array(172 $data = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($_POST['order_id'], array( 173 173 'mode' => 'query', 174 174 'cour_uid' => $_POST["courier_uid"], … … 209 209 $self_drop_off = $_POST['selfDropOff'] === 'yes'; 210 210 $this->save_meta_box( $_POST[ 'order_id' ] ); 211 $data = ShipanyHelper::build_shipany_order_payload ($_POST['order_id'], array(211 $data = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($_POST['order_id'], array( 212 212 'mode' => 'query', 213 213 'cour_uid' => $target_cour_uid, … … 312 312 $storage_type = $this->shipping_shipnay_settings["set_default_storage_type"]; 313 313 } 314 $args = ShipanyHelper::build_shipany_order_payload ($order_id, array(314 $args = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($order_id, array( 315 315 'mode' => 'create', 316 316 'cour_uid' => $target_cour_uid, … … 911 911 // ups, lalamove 912 912 $this->save_meta_box( $order_id ); 913 $data = ShipanyHelper::build_shipany_order_payload ($order_id, array(913 $data = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($order_id, array( 914 914 'mode' => 'query', 915 915 'cour_uid' => $selected_courier, … … 1376 1376 } 1377 1377 } 1378 $args = ShipanyHelper::build_shipany_order_payload ($order_id, array(1378 $args = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($order_id, array( 1379 1379 'mode' => 'create', 1380 1380 'cour_uid' => $target_cour_uid, … … 1479 1479 $storage_type = $this->shipping_shipnay_settings["set_default_storage_type"]; 1480 1480 } 1481 $args = ShipanyHelper::build_shipany_order_payload ($order_id, array(1481 $args = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($order_id, array( 1482 1482 'mode' => 'create', 1483 1483 'cour_uid' => $target_cour_uid, … … 1556 1556 $storage_type = $this->shipping_shipnay_settings["set_default_storage_type"]; 1557 1557 } 1558 $args = ShipanyHelper::build_shipany_order_payload ($wc_order_id, array(1558 $args = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($wc_order_id, array( 1559 1559 'mode' => 'create', 1560 1560 'cour_uid' => $target_cour_uid, … … 1730 1730 array_push($data["add-ons"]["additional_services"], array("code" => $services_element)); 1731 1731 } 1732 $data = ShipanyHelper::build_shipany_order_payload ($_POST['order_id'], array(1732 $data = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($_POST['order_id'], array( 1733 1733 'mode' => 'query', 1734 1734 'cour_uid' => $_POST["courier_uid"], -
shipany/tags/1.1.68/includes/class-shipany-wc-method-ecs-asia.php
r3225923 r3237612 539 539 'desc_tip' => true 540 540 ); 541 $carrier_service = array( 542 'title' => __( 'Carrier Service', 'pr-shipping-shipany' ), 543 'type' => 'checkbox', 544 'label' => __( ' ', 'pr-shipping-shipany' ), 545 'default' => 'no', 546 'description' => __( 'Please tick here if you want carrier_service. Enable Locker/Store List (new) is recommended', 'pr-shipping-shipany' ), 547 'desc_tip' => true 548 ); 549 $locker_list_selector = array( 550 'title' => __( 'Enable Locker/Store List (new)', 'pr-shipping-shipany' ), 551 'type' => 'checkbox', 552 'label' => __( ' ', 'pr-shipping-shipany' ), 553 'default' => 'no', 554 'description' => __( 'Please remove the "local pickup" method in Shipping Zone!!', 'pr-shipping-shipany' ), 555 'desc_tip' => true 556 ); 541 557 542 558 $ddp_or_ddu = array( … … 556 572 "shipany_default_courier_additional_service" => $default_courier_additional_service, 557 573 // "shipany_default_location" => $default_location, 574 "shipany_carrier_service" => $carrier_service, 575 "shipany_locker_list_selector" => $locker_list_selector, 558 576 "shipany_paid_by_rec" => $paid_by_rec, 559 577 "shipany_self_drop_off" => $self_drop_off, … … 749 767 return $saved; 750 768 } 769 770 public function calculate_shipping( $packages = array() ) { 771 if(ShipanyHelper::get_settings('shipany_carrier_service') === 'yes'){ 772 $target_cour_uid = ShipanyHelper::get_settings( 'shipany_default_courier' ); 773 $storage_type = "Normal"; 774 if (ShipanyHelper::get_settings("set_default_storage_type")){ 775 $storage_type = ShipanyHelper::get_settings("set_default_storage_type"); 776 } 777 $args = ShipanyHelper::build_shipany_order_payload_by_data($packages['destination'], $packages['contents'], array( 778 'mode' => 'query', 779 'cour_uid' => $target_cour_uid, 780 'storage_type' => $storage_type, 781 'auto' => true, 782 )); 783 $obj_rate_query = ShipanyHelper::query_rate($args, array()); 784 // ob_clean(); 785 // var_dump($obj_rate_query); 786 // die(); 787 foreach($obj_rate_query as $rate){ 788 $this->add_rate(array( 789 'id' => $this->id . ':' . $rate->cour_uid . ':' . $rate->cour_svc_pl, 790 'label' => __($rate->cour_svc_pl, 'pr-shipping-shipany') . ' (Powered by ShipAny)', 791 'cost' => $rate->cour_ttl_cost->val, 792 'calc_tax' => 'per_item' 793 )); 794 } 795 } 796 } 751 797 } 752 798 -
shipany/tags/1.1.68/shipany-woocommerce.php
r3227976 r3237612 174 174 WC()->customer->set_billing_country($country); 175 175 WC()->customer->set_billing_state($state); 176 WC()->customer->set_props(array('shipping_address_type' => wc_clean($_POST["shipping_address_type"]))); 177 WC()->customer->set_props(array('billing_address_type' => wc_clean($_POST["billing_address_type"]))); 176 178 } 177 179 else { … … 501 503 lockField(true); 502 504 } else { 503 jQuery('#ship-to-different-address-checkbox').prop('disabled', false); 504 // jQuery remove input hidden name="ship_to_different_address", must check it is type=hidden 505 jQuery('input[name="ship_to_different_address"][type="hidden"]').remove() 506 lockField(false); 505 lockField(jQuery('#shipping_address_type').val() === 'locker' || jQuery('#billing_address_type').val() === 'locker'); 507 506 } 508 507 }) 509 508 if (window.location.href.includes('checkout') || window.location.href.includes('cart')) { 510 509 let aTag = document.getElementById('onChangeLocation'); 510 jQuery('#ship-to-different-address-checkbox').on('change', function(){ 511 if(jQuery(this).is(':checked')){ 512 jQuery('#billing_address_type_field').hide(); 513 jQuery('#shipping_address_type').val(jQuery('#billing_address_type').val()); 514 jQuery('#billing_address_type').val('address'); 515 }else{ 516 jQuery('#billing_address_type_field').show(); 517 } 518 }); 519 520 jQuery('#billing_address_type, #shipping_address_type').on('change', function(){ 521 if(jQuery(this).val() === 'locker'){ 522 trigger_list() 523 lockField(true); 524 } else { 525 lockField(false); 526 } 527 }); 511 528 // add change component 512 529 createChangeLocationElement = function () { … … 531 548 } 532 549 aTag = document.getElementById('onChangeLocation'); 533 if(aTag != null){ 534 aTag.onclick = () => { 535 jQuery('[id^="shipping_method_0_local_pickup"][type="radio"]')[0].click(); 536 trigger_list(); 537 }; 538 } 550 if(aTag) aTag.onclick = trigger_list; 539 551 } 540 552 jQuery(document.body).on('updated_cart_totals', function () { … … 571 583 } 572 584 } else { 573 lockField( false);585 lockField(jQuery('#shipping_address_type').val() === 'locker' || jQuery('#billing_address_type').val() === 'locker'); 574 586 } 575 587 } … … 641 653 642 654 if (strpos($chosen_shipping, 'local_pickup') === 0 || strpos($method->get_id(), 'local_pickup') === 0) { 655 include_once("pages/click-collect-widget.php"); 656 } else if(ShipanyHelper::get_settings('shipany_locker_list_selector') === 'yes'){ 643 657 include_once("pages/click-collect-widget.php"); 644 658 } … … 1360 1374 $SHIPANY_WC = SHIPANY(); 1361 1375 } 1376 add_filter( 'woocommerce_checkout_fields' , 'shipany_custom_address_field' ); 1377 // add_action( 'woocommerce_checkout_update_user_meta', 'shipany_woocommerce_checkout_update_user_meta', 10, 2 ); 1378 1379 function shipany_woocommerce_checkout_update_user_meta( $customer_id, $posted ) { 1380 if (isset($posted['billing_address_type'])) { 1381 $billing_address_type = sanitize_text_field( $posted['billing_address_type'] ); 1382 update_user_meta( $customer_id, 'billing_address_type', $billing_address_type); 1383 } 1384 if (isset($posted['shipping_address_type'])) { 1385 $shipping_address_type = sanitize_text_field( $posted['shipping_address_type'] ); 1386 update_user_meta( $customer_id, 'shipping_address_type', $shipping_address_type); 1387 } 1388 } 1389 1390 function shipany_custom_address_field( $address_fields ) { 1391 if(ShipanyHelper::get_settings('shipany_locker_list_selector') === 'yes'){ 1392 $location_array = array( 1393 'address' => __('Address', 'pr-shipping-shipany'), 1394 'locker' => __('Locker', 'pr-shipping-shipany'), 1395 ); 1396 1397 $address_fields['billing']['billing_address_type']['label'] = 'Address Type'; 1398 $address_fields['billing']['billing_address_type']['type'] = 'select'; 1399 $address_fields['billing']['billing_address_type']['options'] = $location_array; 1400 $address_fields['billing']['billing_address_type']['required'] = true; 1401 $address_fields['billing']['billing_address_type']['priority'] = 35; 1402 $address_fields['billing']['billing_address_type']['class'] = array( 'form-row-wide', 'address-field' ); 1403 1404 $address_fields['shipping']['shipping_address_type']['label'] = 'Address Type'; 1405 $address_fields['shipping']['shipping_address_type']['type'] = 'select'; 1406 $address_fields['shipping']['shipping_address_type']['options'] = $location_array; 1407 $address_fields['shipping']['shipping_address_type']['required'] = true; 1408 $address_fields['shipping']['shipping_address_type']['priority'] = 35; 1409 $address_fields['shipping']['shipping_address_type']['class'] = array( 'form-row-wide', 'address-field' ); 1410 } 1411 return $address_fields; 1412 } -
shipany/trunk/includes/Utils/ShipanyHelper.php
r3227976 r3237612 143 143 } 144 144 145 /** 146 * Build the payload for the order creation 147 * @param mixed $wc_order_id 148 * @param array $shipany_data { 149 * @type string $mode - query or create, default is query 150 * @type string $cour_uid 151 * @type string $cour_svc_pl 152 * @type string $storage_type 153 * @type bool $paid_by_rcvr 154 * @type bool $auto 155 * 156 * } 157 * @return array 158 * $shipany_data = 159 * 160 * 161 * 162 */ 163 public static function build_shipany_order_payload($wc_order_id, $shipany_data = array()) { 145 public static function build_shipany_order_payload_by_data($address, $packages, $shipany_data = array()) { 164 146 $shipany_data = array_merge( 165 147 array( … … 175 157 'location_uid' => '', // static::get_settings('shipany_default_location'), 176 158 'incoterms' => static::get_settings('shipany_incoterms'), 159 'description' => " ", 160 'ccy' => get_woocommerce_currency(), 177 161 ), 178 162 $shipany_data … … 181 165 $shipany_data['mode'] = 'query'; 182 166 } 183 $wc_order = wc_get_order($wc_order_id);184 167 185 168 $merchant_info = static::get_merchant_info(); … … 268 251 $items = array(); 269 252 $items_value_total = 0; 270 foreach ($wc_order->get_items() as $item) { 253 $items_weight_total = 0; 254 foreach ($packages as $item) { 271 255 $product = wc_get_product($item['product_id']); 272 $item_value = $item['line_total'] / $item['qty']; 256 $qty = $item['qty'] ?? $item['quantity'] ?? 0; 257 $item_value = $item['line_total'] / $qty; 273 258 if (empty($product) || $product->is_virtual()) { 274 259 continue; … … 309 294 } 310 295 $sa_item_weight = floatval(static::convert_wc_weight_to_kg($item_weight)); 311 $items_value_total += floatval($item_value) * floatval($item['qty']); 296 $items_value_total += floatval($item_value) * floatval($qty); 297 $items_weight_total += $sa_item_weight * floatval($qty); 312 298 $item_array = array( 313 299 "sku" => "" . $sku, … … 318 304 "unt_price" => array( 319 305 "val" => empty($item_value) ? 0.01 : floatval($item_value), 320 "ccy" => $ wc_order->get_currency()306 "ccy" => $shipany_data['ccy'], 321 307 ), 322 "qty" => floatval($ item['qty']),308 "qty" => floatval($qty), 323 309 "wt" => array( 324 310 "val" => $sa_item_weight > 0 ? $sa_item_weight : 0, … … 343 329 } 344 330 // If not USA or Australia, then change state from ISO code to name 345 if ($ shipping_address['country'] != 'US' && $shipping_address['country'] != 'AU') {331 if ($address['country'] != 'US' && $address['country'] != 'AU') { 346 332 // Get all states for a country 347 $states = WC()->countries->get_states($ shipping_address['country']);333 $states = WC()->countries->get_states($address['country']); 348 334 349 335 // If the state is empty, it was entered as free text 350 if (!empty($states) && !empty($ shipping_address['state'])) {336 if (!empty($states) && !empty($address['state'])) { 351 337 // Change the state to be the name and not the code 352 $ shipping_address['state'] = $states[$shipping_address['state']];338 $address['state'] = $states[$address['state']]; 353 339 354 340 // Remove anything in parentheses (e.g. TH) 355 $ind = strpos($ shipping_address['state'], " (");341 $ind = strpos($address['state'], " ("); 356 342 if (false !== $ind) { 357 $ shipping_address['state'] = substr($shipping_address['state'], 0, $ind);343 $address['state'] = substr($address['state'], 0, $ind); 358 344 } 359 345 } … … 403 389 "mch_ttl_val" => array( 404 390 "val" => $items_value_total, 405 "ccy" => $ wc_order->get_currency()391 "ccy" => $shipany_data['ccy'] 406 392 ), 407 393 'cour_ttl_cost' => array( 408 394 'val' => 1, 409 'ccy' => $ wc_order->get_currency()395 'ccy' => $shipany_data['ccy'] 410 396 ), 411 397 "sndr_ctc" => $sndr_ctc, … … 413 399 "ctc" => array( 414 400 "tit" => "", 415 "f_name" => $ shipping_address['first_name'],416 "l_name" => $ shipping_address['last_name'],401 "f_name" => $address['first_name'], 402 "l_name" => $address['last_name'], 417 403 "phs" => array( 418 404 array( 419 405 "typ" => "Mobile", 420 'cnty_code' => str_replace('+', '', WC()->countries->get_country_calling_code($ wc_order->get_shipping_country())),421 'num' => $ shipping_address["phone"]406 'cnty_code' => str_replace('+', '', WC()->countries->get_country_calling_code($address['country'])), 407 'num' => $address["phone"] 422 408 ) 423 409 ), 424 'email' => $ shipping_address['email'],410 'email' => $address['email'], 425 411 "note" => "", 426 "co_name" => isset($ shipping_address['company']) ? $shipping_address['company'] : ''412 "co_name" => isset($address['company']) ? $address['company'] : '' 427 413 ), 428 414 "addr" => array( 429 415 "typ" => "Residential", 430 "ln" => $ shipping_address["address_1"],431 "ln2" => isset($ shipping_address["address_2"]) ? $shipping_address["address_2"] : '',416 "ln" => $address["address_1"], 417 "ln2" => isset($address["address_2"]) ? $address["address_2"] : '', 432 418 "ln3" => "", 433 "distr" => $wrong_rcvr_addr_format ? (isset($ shipping_address["district"]) ? $shipping_address["district"] : '') : $shipping_address["city"],419 "distr" => $wrong_rcvr_addr_format ? (isset($address["district"]) ? $address["district"] : '') : $address["city"], 434 420 "cnty" => $alpha_three_country_code, 435 421 'state' => $wrong_rcvr_addr_format ? '' : (static::get_settings('shipany_region') == 2 ? '' : $shipping_address["state"]), … … 444 430 if ($shipany_data["description"] != " ") { 445 431 $payload['mch_notes'] = array($shipany_data["description"]); 432 } 433 434 return \SHIPANY\Utils\Args_Parser::unset_empty_values($payload); 435 } 436 437 /** 438 * Build the payload for the order creation 439 * @param mixed $wc_order_id 440 * @param array $shipany_data { 441 * @type string $mode - query or create, default is query 442 * @type string $cour_uid 443 * @type string $cour_svc_pl 444 * @type string $storage_type 445 * @type bool $paid_by_rcvr 446 * @type bool $auto 447 * 448 * } 449 * @return array 450 * $shipany_data = 451 * 452 * 453 * 454 */ 455 public static function build_shipany_order_payload_by_wc_order_id($wc_order_id, $shipany_data = array()) { 456 $shipany_data = array_merge( 457 array( 458 'mode' => 'query', 459 'cour_uid' => '', 460 'cour_svc_pl' => '', 461 'storage_type' => static::get_settings('set_default_storage_type'), 462 'paid_by_rcvr' => static::get_settings('shipany_paid_by_rec') == 'yes', 463 'auto' => false, 464 'add-ons' => array(), // for lalamove, keep the structure of the add-ons 465 'description' => " " 466 ), 467 $shipany_data 468 ); 469 if (!in_array($shipany_data['mode'], ['query', 'create'])) { 470 $shipany_data['mode'] = 'query'; 471 } 472 $wc_order = wc_get_order($wc_order_id); 473 $shipany_data['ccy'] = $wc_order->get_currency(); 474 $shipping_address = array_merge( 475 (array) $wc_order->get_address('billing'), 476 \SHIPANY\Utils\Args_Parser::unset_empty_values((array) $wc_order->get_address('shipping')) 477 ); 478 $payload = static::build_shipany_order_payload_by_data($shipping_address, $wc_order->get_items(), $shipany_data); 479 $payload['ext_order_ref'] = $wc_order->get_order_number() . (static::get_settings("shipany_customize_order_id") ? static::get_settings("shipany_customize_order_id") : ''); 480 $payload["wt"] = array( 481 "val" => floatval(static::calculate_order_weight($wc_order)) ?: 1, 482 "unt" => "kg" 483 ); 484 if (strval($wc_order->get_order_number()) != strval($wc_order_id)) { 485 $payload['ext_order_id'] = strval($wc_order_id); 446 486 } 447 487 … … 759 799 760 800 return apply_filters('shipping_shipany_order_weight', $total_weight, $order_id); 801 } 802 803 protected static function calculate_order_weight_by_items($items) { 804 761 805 } 762 806 -
shipany/trunk/includes/abstract-shipany-wc-order.php
r3227216 r3237612 170 170 } 171 171 172 $data = ShipanyHelper::build_shipany_order_payload ($_POST['order_id'], array(172 $data = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($_POST['order_id'], array( 173 173 'mode' => 'query', 174 174 'cour_uid' => $_POST["courier_uid"], … … 209 209 $self_drop_off = $_POST['selfDropOff'] === 'yes'; 210 210 $this->save_meta_box( $_POST[ 'order_id' ] ); 211 $data = ShipanyHelper::build_shipany_order_payload ($_POST['order_id'], array(211 $data = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($_POST['order_id'], array( 212 212 'mode' => 'query', 213 213 'cour_uid' => $target_cour_uid, … … 312 312 $storage_type = $this->shipping_shipnay_settings["set_default_storage_type"]; 313 313 } 314 $args = ShipanyHelper::build_shipany_order_payload ($order_id, array(314 $args = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($order_id, array( 315 315 'mode' => 'create', 316 316 'cour_uid' => $target_cour_uid, … … 911 911 // ups, lalamove 912 912 $this->save_meta_box( $order_id ); 913 $data = ShipanyHelper::build_shipany_order_payload ($order_id, array(913 $data = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($order_id, array( 914 914 'mode' => 'query', 915 915 'cour_uid' => $selected_courier, … … 1376 1376 } 1377 1377 } 1378 $args = ShipanyHelper::build_shipany_order_payload ($order_id, array(1378 $args = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($order_id, array( 1379 1379 'mode' => 'create', 1380 1380 'cour_uid' => $target_cour_uid, … … 1479 1479 $storage_type = $this->shipping_shipnay_settings["set_default_storage_type"]; 1480 1480 } 1481 $args = ShipanyHelper::build_shipany_order_payload ($order_id, array(1481 $args = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($order_id, array( 1482 1482 'mode' => 'create', 1483 1483 'cour_uid' => $target_cour_uid, … … 1556 1556 $storage_type = $this->shipping_shipnay_settings["set_default_storage_type"]; 1557 1557 } 1558 $args = ShipanyHelper::build_shipany_order_payload ($wc_order_id, array(1558 $args = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($wc_order_id, array( 1559 1559 'mode' => 'create', 1560 1560 'cour_uid' => $target_cour_uid, … … 1730 1730 array_push($data["add-ons"]["additional_services"], array("code" => $services_element)); 1731 1731 } 1732 $data = ShipanyHelper::build_shipany_order_payload ($_POST['order_id'], array(1732 $data = ShipanyHelper::build_shipany_order_payload_by_wc_order_id($_POST['order_id'], array( 1733 1733 'mode' => 'query', 1734 1734 'cour_uid' => $_POST["courier_uid"], -
shipany/trunk/includes/class-shipany-wc-method-ecs-asia.php
r3225923 r3237612 539 539 'desc_tip' => true 540 540 ); 541 $carrier_service = array( 542 'title' => __( 'Carrier Service', 'pr-shipping-shipany' ), 543 'type' => 'checkbox', 544 'label' => __( ' ', 'pr-shipping-shipany' ), 545 'default' => 'no', 546 'description' => __( 'Please tick here if you want carrier_service. Enable Locker/Store List (new) is recommended', 'pr-shipping-shipany' ), 547 'desc_tip' => true 548 ); 549 $locker_list_selector = array( 550 'title' => __( 'Enable Locker/Store List (new)', 'pr-shipping-shipany' ), 551 'type' => 'checkbox', 552 'label' => __( ' ', 'pr-shipping-shipany' ), 553 'default' => 'no', 554 'description' => __( 'Please remove the "local pickup" method in Shipping Zone!!', 'pr-shipping-shipany' ), 555 'desc_tip' => true 556 ); 541 557 542 558 $ddp_or_ddu = array( … … 556 572 "shipany_default_courier_additional_service" => $default_courier_additional_service, 557 573 // "shipany_default_location" => $default_location, 574 "shipany_carrier_service" => $carrier_service, 575 "shipany_locker_list_selector" => $locker_list_selector, 558 576 "shipany_paid_by_rec" => $paid_by_rec, 559 577 "shipany_self_drop_off" => $self_drop_off, … … 749 767 return $saved; 750 768 } 769 770 public function calculate_shipping( $packages = array() ) { 771 if(ShipanyHelper::get_settings('shipany_carrier_service') === 'yes'){ 772 $target_cour_uid = ShipanyHelper::get_settings( 'shipany_default_courier' ); 773 $storage_type = "Normal"; 774 if (ShipanyHelper::get_settings("set_default_storage_type")){ 775 $storage_type = ShipanyHelper::get_settings("set_default_storage_type"); 776 } 777 $args = ShipanyHelper::build_shipany_order_payload_by_data($packages['destination'], $packages['contents'], array( 778 'mode' => 'query', 779 'cour_uid' => $target_cour_uid, 780 'storage_type' => $storage_type, 781 'auto' => true, 782 )); 783 $obj_rate_query = ShipanyHelper::query_rate($args, array()); 784 // ob_clean(); 785 // var_dump($obj_rate_query); 786 // die(); 787 foreach($obj_rate_query as $rate){ 788 $this->add_rate(array( 789 'id' => $this->id . ':' . $rate->cour_uid . ':' . $rate->cour_svc_pl, 790 'label' => __($rate->cour_svc_pl, 'pr-shipping-shipany') . ' (Powered by ShipAny)', 791 'cost' => $rate->cour_ttl_cost->val, 792 'calc_tax' => 'per_item' 793 )); 794 } 795 } 796 } 751 797 } 752 798 -
shipany/trunk/shipany-woocommerce.php
r3227976 r3237612 174 174 WC()->customer->set_billing_country($country); 175 175 WC()->customer->set_billing_state($state); 176 WC()->customer->set_props(array('shipping_address_type' => wc_clean($_POST["shipping_address_type"]))); 177 WC()->customer->set_props(array('billing_address_type' => wc_clean($_POST["billing_address_type"]))); 176 178 } 177 179 else { … … 501 503 lockField(true); 502 504 } else { 503 jQuery('#ship-to-different-address-checkbox').prop('disabled', false); 504 // jQuery remove input hidden name="ship_to_different_address", must check it is type=hidden 505 jQuery('input[name="ship_to_different_address"][type="hidden"]').remove() 506 lockField(false); 505 lockField(jQuery('#shipping_address_type').val() === 'locker' || jQuery('#billing_address_type').val() === 'locker'); 507 506 } 508 507 }) 509 508 if (window.location.href.includes('checkout') || window.location.href.includes('cart')) { 510 509 let aTag = document.getElementById('onChangeLocation'); 510 jQuery('#ship-to-different-address-checkbox').on('change', function(){ 511 if(jQuery(this).is(':checked')){ 512 jQuery('#billing_address_type_field').hide(); 513 jQuery('#shipping_address_type').val(jQuery('#billing_address_type').val()); 514 jQuery('#billing_address_type').val('address'); 515 }else{ 516 jQuery('#billing_address_type_field').show(); 517 } 518 }); 519 520 jQuery('#billing_address_type, #shipping_address_type').on('change', function(){ 521 if(jQuery(this).val() === 'locker'){ 522 trigger_list() 523 lockField(true); 524 } else { 525 lockField(false); 526 } 527 }); 511 528 // add change component 512 529 createChangeLocationElement = function () { … … 531 548 } 532 549 aTag = document.getElementById('onChangeLocation'); 533 if(aTag != null){ 534 aTag.onclick = () => { 535 jQuery('[id^="shipping_method_0_local_pickup"][type="radio"]')[0].click(); 536 trigger_list(); 537 }; 538 } 550 if(aTag) aTag.onclick = trigger_list; 539 551 } 540 552 jQuery(document.body).on('updated_cart_totals', function () { … … 571 583 } 572 584 } else { 573 lockField( false);585 lockField(jQuery('#shipping_address_type').val() === 'locker' || jQuery('#billing_address_type').val() === 'locker'); 574 586 } 575 587 } … … 641 653 642 654 if (strpos($chosen_shipping, 'local_pickup') === 0 || strpos($method->get_id(), 'local_pickup') === 0) { 655 include_once("pages/click-collect-widget.php"); 656 } else if(ShipanyHelper::get_settings('shipany_locker_list_selector') === 'yes'){ 643 657 include_once("pages/click-collect-widget.php"); 644 658 } … … 1360 1374 $SHIPANY_WC = SHIPANY(); 1361 1375 } 1376 add_filter( 'woocommerce_checkout_fields' , 'shipany_custom_address_field' ); 1377 // add_action( 'woocommerce_checkout_update_user_meta', 'shipany_woocommerce_checkout_update_user_meta', 10, 2 ); 1378 1379 function shipany_woocommerce_checkout_update_user_meta( $customer_id, $posted ) { 1380 if (isset($posted['billing_address_type'])) { 1381 $billing_address_type = sanitize_text_field( $posted['billing_address_type'] ); 1382 update_user_meta( $customer_id, 'billing_address_type', $billing_address_type); 1383 } 1384 if (isset($posted['shipping_address_type'])) { 1385 $shipping_address_type = sanitize_text_field( $posted['shipping_address_type'] ); 1386 update_user_meta( $customer_id, 'shipping_address_type', $shipping_address_type); 1387 } 1388 } 1389 1390 function shipany_custom_address_field( $address_fields ) { 1391 if(ShipanyHelper::get_settings('shipany_locker_list_selector') === 'yes'){ 1392 $location_array = array( 1393 'address' => __('Address', 'pr-shipping-shipany'), 1394 'locker' => __('Locker', 'pr-shipping-shipany'), 1395 ); 1396 1397 $address_fields['billing']['billing_address_type']['label'] = 'Address Type'; 1398 $address_fields['billing']['billing_address_type']['type'] = 'select'; 1399 $address_fields['billing']['billing_address_type']['options'] = $location_array; 1400 $address_fields['billing']['billing_address_type']['required'] = true; 1401 $address_fields['billing']['billing_address_type']['priority'] = 35; 1402 $address_fields['billing']['billing_address_type']['class'] = array( 'form-row-wide', 'address-field' ); 1403 1404 $address_fields['shipping']['shipping_address_type']['label'] = 'Address Type'; 1405 $address_fields['shipping']['shipping_address_type']['type'] = 'select'; 1406 $address_fields['shipping']['shipping_address_type']['options'] = $location_array; 1407 $address_fields['shipping']['shipping_address_type']['required'] = true; 1408 $address_fields['shipping']['shipping_address_type']['priority'] = 35; 1409 $address_fields['shipping']['shipping_address_type']['class'] = array( 'form-row-wide', 'address-field' ); 1410 } 1411 return $address_fields; 1412 }
Note: See TracChangeset
for help on using the changeset viewer.