Plugin Directory

Changeset 2988435


Ignore:
Timestamp:
11/03/2023 10:40:35 AM (2 years ago)
Author:
shipdepot
Message:

Update version 1.1.3

Location:
ship-depot/trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • ship-depot/trunk/Ship_Depot_init.php

    r2981538 r2988435  
    55 * Plugin URI:        https://shipdepot.vn/
    66 * Description:       Ship Depot support shipping couriers in Vietnam like GHN, GHTK, AhaMove.
    7  * Version:           1.1.2
     7 * Version:           1.1.3
    88 * Author:            ShipDepot.vn
    99 * Text Domain:       ship-depot-translate
  • ship-depot/trunk/includes/Order/class-order-shipping.php

    r2963463 r2988435  
    1919     * @param int $items_total_price Total price of all items in order.
    2020     * @param int $item_regular_price_total Total regular price of all items in order.
     21     * @param int $order_total Price after calculate of order.
    2122     * @param string $for_courier Json of List courier calculate.
    2223     * @return Ship_Depot_Courier_Response[]|bool
    2324     */
    24     public static function calculate_shipping_fee($is_cod, $is_insurance, $insurance_amount, $list_packages, $list_items, $receiver, $sender_storage, $sender_info, $items_total_price, $item_regular_price_total, $for_courier = '')
     25    public static function calculate_shipping_fee($is_cod, $is_insurance, $insurance_amount, $list_packages, $list_items, $receiver, $sender_storage, $sender_info, $items_total_price, $item_regular_price_total, $order_total, $for_courier = '')
    2526    {
    2627        Ship_Depot_Logger::wrlog('[Ship_Depot_Order_Shipping][calculate_shipping] receiver: ' . print_r($receiver, true));
     
    4041        $cod = new Ship_Depot_Cod();
    4142        $cod->IsActive = $is_cod;
    42         $cod->Value = $is_cod ? $items_total_price : 0;
     43        $cod->Value = $is_cod ? $order_total : 0;
    4344
    4445        $str_fee_modify = get_option('sd_setting_fee');
  • ship-depot/trunk/includes/class-ship-depot-general.php

    r2963463 r2988435  
    5151        require_once SHIP_DEPOT_DIR_PATH . 'helper/class-function-protect-data.php';
    5252        require_once SHIP_DEPOT_DIR_PATH . 'helper/class-function-get-data.php';
     53        require_once SHIP_DEPOT_DIR_PATH . 'helper/class-shipping-helper.php';
    5354        require_once SHIP_DEPOT_DIR_PATH . 'includes/Settings/class-ship-depot-data.php';
    5455        require_once SHIP_DEPOT_DIR_PATH . 'rest-api/class-shipdepot-webhook.php';
  • ship-depot/trunk/page/admin/orders/sd-order-detail.php

    r2981538 r2988435  
    287287                "item_regular_price_total" => $item_regular_price_total,
    288288                "ship_from_station" => $ship_from_station,
     289                "total_discount_amount" => $order->get_discount_total()
    289290            );
    290291
     
    447448        jQuery(document).ready(function($) {
    448449            let isAddNew = jQuery('#is_add_new').val() == "true" ? true : false;
    449             let cod_amount = parseFloat(<?php echo esc_js(wc_get_order($order_id)->get_subtotal()) ?>);
     450            let cod_amount = parseFloat(<?php echo esc_js($order->get_subtotal() - floatval($order->get_discount_total())) ?>);
    450451            if ($('#selectedShipping').length > 0) {
    451452                console.log('selected shipping existed');
     
    740741{
    741742    //return [];
    742     return ['sd_not_create_ship', 'sd_list_package_size', 'sd_sender_storage', 'sd_sender_info', 'sd_ship_info', 'sd_receiver', 'sd_insurance', 'sd_cod', 'sd_selected_shipping', 'sd_selected_courier', 'sd_shipping_notes', 'sd_customer_pay_shipping', 'sd_is_edit_order', 'sd_list_items', 'sd_cod_failed_info'];
     743    return ['sd_not_create_ship', 'sd_list_package_size', 'sd_sender_storage', 'sd_sender_info', 'sd_ship_info', 'sd_receiver', 'sd_insurance', 'sd_cod', 'sd_selected_shipping', 'sd_selected_courier', 'sd_shipping_notes', 'sd_customer_pay_shipping', 'sd_is_edit_order', 'sd_list_items', 'sd_cod_failed_info', 'sd_ship_from_station'];
    743744}
    744745
     
    885886        $str_cod = get_post_meta($post->ID, 'sd_cod', true);
    886887        if (!Ship_Depot_Helper::check_null_or_empty($str_cod)) {
    887             $cod = new Ship_Depot_Insurance(Ship_Depot_Helper::CleanJsonFromHTMLAndDecode($str_cod));
     888            $cod = new Ship_Depot_Cod(Ship_Depot_Helper::CleanJsonFromHTMLAndDecode($str_cod));
    888889        }
    889890        //
  • ship-depot/trunk/page/frontend/sd-checkout-page.php

    r2963463 r2988435  
    2626    Ship_Depot_Logger::wrlog('[sd_woocommerce_review_order_before_order_total] _POST: ' . print_r($_POST, true));
    2727    Ship_Depot_Logger::wrlog('[sd_woocommerce_review_order_before_order_total] _GET: ' . print_r($_GET, true));
     28    Ship_Depot_Logger::wrlog('[sd_woocommerce_review_order_before_order_total] cart get_total: ' . print_r(WC()->cart->get_total('number'), true));
    2829    $str_courier_setting = get_option('sd_setting_courier');
    2930    if (!Ship_Depot_Helper::check_null_or_empty($str_courier_setting)) {
     
    148149        Ship_Depot_Logger::wrlog('[sd_woocommerce_review_order_before_order_total] is_cod: ' . print_r($is_cod, true));
    149150        //
    150         $list_shipping = Ship_Depot_Order_Shipping::calculate_shipping_fee($is_cod, false, 0, $list_packages_sizes, $list_items, $receiver, isset($selected_storage) ? $selected_storage->WarehouseID : '', isset($sender_info) ? $sender_info : '', WC()->cart->get_subtotal(), $item_regular_price_total, $courier_setting);
     151        $list_shipping = Ship_Depot_Order_Shipping::calculate_shipping_fee($is_cod, false, 0, $list_packages_sizes, $list_items, $receiver, isset($selected_storage) ? $selected_storage->WarehouseID : '', isset($sender_info) ? $sender_info : '', WC()->cart->get_subtotal(), $item_regular_price_total, WC()->cart->get_total('number'), $courier_setting);
    151152    }
    152153    $str_selected_shipping = WC()->session->get('selected_shipping');
     
    489490    }
    490491    //shipping notes
    491     $shipping_notes = Ship_Depot_Helper::check_null_or_empty(sanitize_textarea_field($_POST['shipdepot_shipping_notes']) ? '' : sanitize_textarea_field($_POST['shipdepot_shipping_notes']));
     492    $shipping_notes = Ship_Depot_Helper::check_null_or_empty(sanitize_textarea_field($_POST['shipdepot_shipping_notes'])) ? '' : sanitize_textarea_field($_POST['shipdepot_shipping_notes']);
    492493    Ship_Depot_Logger::wrlog('[sd_action_checkout_order_processed] shipping_notes: ' . print_r($shipping_notes, true));
    493494    update_post_meta($order_id, 'sd_shipping_notes', $shipping_notes);
  • ship-depot/trunk/readme.txt

    r2981538 r2988435  
    33Tags: shipping, couriers, ghn, ghtk, aha
    44Requires at least: 6.1.1
    5 Tested up to: 6.3.1
     5Tested up to: 6.3.2
    66Requires PHP: 7.4.3
    7 Stable tag: 1.1.2
     7Stable tag: 1.1.3
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    6565
    6666== Changelog ==
     67= 1.1.3 =
     68* Sửa 1 số lỗi nhỏ
    6769
    6870= 1.1.2 =
  • ship-depot/trunk/rest-api/class-shipdepot-webhook.php

    r2922618 r2988435  
    5151                'methods' => 'POST',
    5252                'callback' => [$this, 'sd_update_shipping_status'],
     53                'permission_callback' => '__return_true'
     54            ]);
     55
     56            register_rest_route('shipdepot/webhook/v1', '/UpdateCancelShipping', [
     57                'methods' => 'POST',
     58                'callback' => [$this, 'sd_update_cancel_shipping'],
    5359                'permission_callback' => '__return_true'
    5460            ]);
     
    228234                    && $shop_api_key == $data->APIKey
    229235                ) {
    230                     $ship_info = $data->ShipInfo;
    231                     $ship_info_decrypted = Ship_Depot_ProtectData::DecryptData($ship_info);
     236                    $ship_info_encrypted = $data->ShipInfo;
     237                    $ship_info_decrypted = Ship_Depot_ProtectData::DecryptData($ship_info_encrypted);
    232238                    $ship_param = json_decode($ship_info_decrypted);
    233239                    Ship_Depot_Logger::wrlog('[Ship_Depot_Webhook][sd_update_shipping_status] ship_param from post data: ' . print_r($ship_param, true));
     
    258264                            $str_update_order_statuses = get_option('sd_update_order_statuses');
    259265                            if (str_contains($status_lower, strtolower(SD_CANCEL_STATUS))) {
    260                                 update_post_meta($ship_param->WOOOrderID, 'sd_ship_info', '');
    261266                                $order_note = __('Vận đơn ' . $ship_info->TrackingNumber . ' đã bị hủy. Lý do: ', 'ship-depot-translate');
    262267                                if (!Ship_Depot_Helper::check_null_or_empty($ship_param->CancelDescription)) {
    263268                                    $order_note = $order_note . ' ' . $ship_param->CancelDescription;
    264269                                }
    265                                 $order->add_order_note($order_note);
     270                                Ship_Depot_Shipping_Helper::cancel_shipping($order, $ship_info->TrackingNumber, $order_note);
    266271                            }
    267272                            //
     
    270275                                foreach ($list_update_order_statuses as $status_obj) {
    271276                                    $status = new Ship_Depot_Shipping_Status($status_obj);
    272                                     if(str_contains($status_lower, strtolower($status->ID))){
     277                                    if (str_contains($status_lower, strtolower($status->ID))) {
    273278                                        Ship_Depot_Logger::wrlog('[Ship_Depot_Webhook][sd_update_shipping_status][update status auto] updated status in option: ' . print_r($status, true));
    274                                         if($status->IsUsed && !Ship_Depot_Helper::check_null_or_empty($status->WooOrderStatusID)){
     279                                        if ($status->IsUsed && !Ship_Depot_Helper::check_null_or_empty($status->WooOrderStatusID)) {
    275280                                            Ship_Depot_Logger::wrlog('[Ship_Depot_Webhook][sd_update_shipping_status][update status auto] order status changed to ' . $status->WooOrderStatusID);
    276281                                            $order->update_status(str_replace('wc-', '', $status->WooOrderStatusID), 'Update auto by Ship Depot.');
     
    285290            return 'OK';
    286291        }
     292
     293        function sd_update_cancel_shipping($request)
     294        {
     295            $params = wp_parse_args($request->get_params(), '');
     296            Ship_Depot_Logger::wrlog('[Ship_Depot_Webhook][sd_update_cancel_shipping] params: ' . print_r($params, true));
     297            if (!Ship_Depot_Helper::check_null_or_empty($params)) {
     298                $data =  (object) $params;
     299                $shop_api_key = get_option('sd_api_key');
     300                Ship_Depot_Logger::wrlog('[Ship_Depot_Webhook][sd_update_cancel_shipping] shop_api_key: ' . print_r($shop_api_key, true));
     301                if (
     302                    !Ship_Depot_Helper::check_null_or_empty($shop_api_key)
     303                    && !Ship_Depot_Helper::check_null_or_empty($data->APIKey)
     304                    && $shop_api_key == $data->APIKey
     305                ) {
     306                    $ship_info_encrypted = $data->ShipInfo;
     307                    $ship_info_decrypted = Ship_Depot_ProtectData::DecryptData($ship_info_encrypted);
     308                    $ship_param = json_decode($ship_info_decrypted);
     309                    Ship_Depot_Logger::wrlog('[Ship_Depot_Webhook][sd_update_cancel_shipping] ship_param from post data: ' . print_r($ship_param, true));
     310                    $str_ship_info = get_post_meta($ship_param->WOOOrderID, 'sd_ship_info', true);
     311                    Ship_Depot_Logger::wrlog('[Ship_Depot_Webhook][sd_update_cancel_shipping] current ship_info: ' . print_r($str_ship_info, true));
     312                    if (!Ship_Depot_Helper::check_null_or_empty($str_ship_info)) {
     313                        $ship_info = json_decode($str_ship_info);
     314                        Ship_Depot_Logger::wrlog('[Ship_Depot_Webhook][sd_update_cancel_shipping] ship_info->TrackingNumber: ' . print_r($ship_info->TrackingNumber, true));
     315                        Ship_Depot_Logger::wrlog('[Ship_Depot_Webhook][sd_update_cancel_shipping] ship_info->TrackingNumber: ' . print_r($ship_param->TrackingNumber, true));
     316                        if ($ship_info->TrackingNumber == $ship_param->TrackingNumber) {
     317                            $order = new WC_Order($ship_param->WOOOrderID);
     318                            //Update empty ship info
     319                            $order_note = __('Vận đơn ' . $ship_info->TrackingNumber . ' đã bị hủy. Lý do: ', 'ship-depot-translate');
     320                            if (!Ship_Depot_Helper::check_null_or_empty($ship_param->CancelDescription)) {
     321                                $order_note = $order_note . ' ' . $ship_param->CancelDescription;
     322                            }
     323                            Ship_Depot_Shipping_Helper::cancel_shipping($order, $ship_info->TrackingNumber, $order_note);
     324                            //
     325                        }
     326                    }
     327                }
     328            }
     329            return 'OK';
     330        }
    287331    }
    288332    new Ship_Depot_Webhook();
Note: See TracChangeset for help on using the changeset viewer.