Plugin Directory

Changeset 3021703


Ignore:
Timestamp:
01/15/2024 04:20:37 AM (2 years ago)
Author:
redboxsa
Message:

version 1.34

Location:
redbox-pickup
Files:
17 added
3 edited

Legend:

Unmodified
Added
Removed
  • redbox-pickup/trunk/front/front.php

    r2994949 r3021703  
    4040                        'name' => $item->get_name(),
    4141                        'quantity' => $item->get_quantity(),
    42                         'total' => $item->get_total(),
     42                        'totalPrice' => $item->get_total(),
    4343                        'currency' => $order->get_currency()
    4444                    ];
     45                    $note = 'items ' . json_encode($item->get_data());
     46                    $order->add_order_note( $note );
    4547                }
    4648                return $products;
     
    175177                    "cod_currency" => "",
    176178                    "shipping_price" => $priceData['shipping_total'],
    177                     "shipping_currency" => $order->get_currency(),
     179                    "shipping_price_currency" => $order->get_currency(),
    178180                    "items" => $this->redbox_get_product($order),
    179181                    "from_platform" => "woo_commerce"
     
    185187                    $dataShipment['cod_currency'] = $priceData['curency'];
    186188                } else {
    187                     if ($order->is_paid()) {
    188                         $dataShipment['cod_amount'] = 0;
    189                         $dataShipment['cod_currency'] = $priceData['curency'];
    190                     } else {
    191                         $dataShipment['cod_amount'] = 10;
    192                         $dataShipment['cod_currency'] = "USD";
    193                     }
     189                    $dataShipment['cod_amount'] = 0;
     190                    $dataShipment['cod_currency'] = $priceData['curency'];
    194191                }
    195192                if ($this->redbox_validate_body_create_shipment($dataShipment)) {
     
    218215
    219216            private function redbox_validate_body_update_shipment($dataShipment = []){
    220                 if (isset($dataShipment["point_id"]) && !empty($dataShipment["point_id"]) &&
    221                     isset($dataShipment["customer_phone"]) && !empty($dataShipment["customer_phone"])
    222                 ) {
     217                if (isset($dataShipment["customer_phone"]) && !empty($dataShipment["customer_phone"])) {
    223218                    return true;
    224219                } else {
     
    227222            }
    228223
    229             function redbox_update_shipment( $post_id ) {
    230                 if (isset($_POST[ 'post_type' ]) && 'shop_order' == $_POST[ 'post_type' ]) {
    231                     $order = wc_get_order( $post_id );
    232                     $orderKey = $order->get_order_key();
    233                     $orderNumber = $order->get_order_number();
    234 
    235                     $customerData = $this->redbox_get_data_customer($order);
    236                     $priceData = $this->redbox_get_other_info($order);
    237 
    238                     $dataShipment = [
    239                         "reference" => $post_id,
    240                         "point_id" => get_post_meta( $order_id, '_redbox_point_id', true ),
    241                         "customer_name" => $customerData['name'],
    242                         "customer_phone" => $customerData['phone'],
    243                         "customer_email" => $customerData['email'],
    244                         "customer_address" => $customerData['adddress'],
    245                         "cod_amount" => "",
    246                         "cod_currency" => "",
    247                         "shipping_price" => $priceData['shipping_total'],
    248                         "shipping_currency" => $order->get_currency(),
    249                         "items" => $this->redbox_get_product($order),
    250                         "status" => $order->get_status()
    251                     ];
    252                     if ($order->get_payment_method() == "cod") {
    253                         $dataShipment['cod_amount'] = $priceData['order_total'];
    254                         $dataShipment['cod_currency'] = $priceData['curency'];
    255                     } else {
    256                         $dataShipment['cod_amount'] = 0;
    257                         $dataShipment['cod_currency'] = $priceData['curency'];
    258                     }
    259                     if ($this->redbox_validate_body_update_shipment($dataShipment)) {
    260                         $urlQuery = REDBOX_URL_UPDATE_SHIPMENT;
    261                         $options = array(
    262                             'headers' => array(
    263                                 'Authorization' => 'Bearer ' . $this->redboxKey
    264                             ),
    265                             'body' => $dataShipment,
    266                             'timeout' => 60
    267                         );
    268                         $response = wp_remote_post($urlQuery, $options);
    269                     }
    270                 }
     224            function redbox_update_shipment( $order_id, $order ) {
     225                if ( is_admin() ) {
     226                    $orderKey = $order->get_order_key();
     227                    $orderNumber = $order->get_order_number();
     228
     229                    $customerData = $this->redbox_get_data_customer($order);
     230                    $priceData = $this->redbox_get_other_info($order);
     231                    $current_user = wp_get_current_user();
     232
     233                    $dataShipment = [
     234                        "reference" => $order_id,
     235                        "point_id" => get_post_meta( $order_id, '_redbox_point_id', true ),
     236                        "customer_name" => $customerData['name'],
     237                        "customer_phone" => $customerData['phone'],
     238                        "customer_email" => $customerData['email'],
     239                        "customer_address" => $customerData['adddress'],
     240                        "cod_amount" => "",
     241                        "cod_currency" => "",
     242                        "shipping_price" => $priceData['shipping_total'],
     243                        "shipping_price_currency" => $order->get_currency(),
     244                        "items" => $this->redbox_get_product($order),
     245                        "status" => $order->get_status(),
     246                        "action_by" => $current_user ? $current_user->user_login : "business_admin"
     247                    ];
     248                    if ($order->get_payment_method() == "cod") {
     249                        $dataShipment['cod_amount'] = $priceData['order_total'];
     250                        $dataShipment['cod_currency'] = $priceData['curency'];
     251                    } else {
     252                        $dataShipment['cod_amount'] = 0;
     253                        $dataShipment['cod_currency'] = $priceData['curency'];
     254                    }
     255                    if ($this->redbox_validate_body_update_shipment($dataShipment)) {
     256                        $urlQuery = REDBOX_URL_UPDATE_SHIPMENT;
     257                        $options = array(
     258                            'headers' => array(
     259                                'Authorization' => 'Bearer ' . $this->redboxKey
     260                            ),
     261                            'body' => $dataShipment,
     262                            'timeout' => 60
     263                        );
     264                        $response = wp_remote_post($urlQuery, $options);
     265                    }
     266                }
    271267            }
    272268 
     
    358354                add_action( 'woocommerce_view_order', array($this, 'redbox_show_redbox_point_when_create_order_success') );
    359355                add_action('woocommerce_checkout_process', array($this, 'redbox_validate_with_redbox_pickup'));
    360                 add_action( 'save_post', array($this, 'redbox_update_shipment'));
     356                add_action( 'woocommerce_update_order', array($this, 'redbox_update_shipment'), 10, 2);
    361357                add_action( 'woocommerce_admin_order_data_after_shipping_address', array($this, 'redbox_add_button_print_label'));
    362358                add_filter( 'woocommerce_package_rates', array($this, 'bbloomer_woocommerce_tiered_shipping'), 10, 2 );
  • redbox-pickup/trunk/readme.txt

    r2994949 r3021703  
    55Requires at least: 3.3
    66Tested up to: 5.5.1
    7 Stable tag: 1.33
     7Stable tag: 1.34
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7474= 1.33 =
    7575Fix shipping method
     76= 1.34 =
     77Fix update information, api create-v2
    7678
    7779
  • redbox-pickup/trunk/redbox.php

    r2994949 r3021703  
    44        * Description: This plugin allows customers pickup package at RedBox Locker.
    55        * Plugin URI: https://woocommerce.com/
    6         * Version: 1.33
     6        * Version: 1.34
    77        * Author: RedBox
    88        * Author URI: https://redboxsa.com
     
    4040    }
    4141    if (!defined('REDBOX_URL_CREATE_SHIPMENT')) {
    42         define('REDBOX_URL_CREATE_SHIPMENT', REDBOX_BASE_URL . "/create-shipment-for-store");
     42        define('REDBOX_URL_CREATE_SHIPMENT', REDBOX_BASE_URL . "/create-shipment-v2");
    4343    }
    4444    if (!defined('REDBOX_URL_UPDATE_SHIPMENT')) {
Note: See TracChangeset for help on using the changeset viewer.