Plugin Directory

Changeset 2515504


Ignore:
Timestamp:
04/15/2021 09:41:51 AM (5 years ago)
Author:
redboxsa
Message:

Update version 1.4

Location:
redbox-pickup
Files:
3 edited
6 copied

Legend:

Unmodified
Added
Removed
  • redbox-pickup/tags/1.4/front/front.php

    r2491692 r2515504  
    122122            }
    123123
    124             function redbox_create_shipment( $order_id ) {
    125                 if ( ! $order_id )
    126                     return;
    127 
    128                 if( ! get_post_meta( $order_id, '_thankyou_action_done', true ) ) {
    129                     $order = wc_get_order( $order_id );
    130                     $orderKey = $order->get_order_key();
    131                     $orderNumber = $order->get_order_number();
    132 
    133                     $customerData = $this->redbox_get_data_customer($order);
    134                     $priceData = $this->redbox_get_other_info($order);
    135 
    136                     $dataShipment = [
    137                         "store_url" => get_home_url(),
    138                         "reference" => $order_id,
    139                         "point_id" => $order->get_meta( '_redbox_point_id' ),
    140                         "customer_name" => $customerData['name'],
    141                         "customer_phone" => $customerData['phone'],
    142                         "customer_email" => $customerData['email'],
    143                         "customer_address" => $customerData['adddress'],
    144                         "cod_amount" => "",
    145                         "cod_currency" => "",
    146                         "shipping_price" => $priceData['shipping_total'],
    147                         "shipping_currency" => $order->get_currency(),
    148                         "items" => $this->redbox_get_product($order),
    149                         "from_platform" => "woo_commerce"
    150                     ];
    151                     if ($order->get_payment_method() == "cod") {
    152                         $dataShipment['cod_amount'] = $priceData['order_total'];
    153                         $dataShipment['cod_currency'] = $priceData['curency'];
    154                     } else {
    155                         $dataShipment['cod_amount'] = 0;
    156                         $dataShipment['cod_currency'] = $priceData['curency'];
    157                     }
    158                     if ($this->redbox_validate_body_create_shipment($dataShipment)) {
    159                         $urlQuery = REDBOX_URL_CREATE_SHIPMENT;
    160                         $options = array(
    161                             'headers' => array(
    162                                 'Authorization' => 'Bearer ' . $this->redboxKey
    163                             ),
    164                             'body' => $dataShipment
    165                         );
    166                         $response = wp_remote_post($urlQuery, $options);
    167                         $body = json_decode( wp_remote_retrieve_body( $response ), true );
    168                         if ($body['success']) {
    169                             $note = 'RedBox tracking number: ' . $body['tracking_number'];
    170                             $order->add_order_note( $note );
    171                             $order->update_meta_data( 'redbox_shipment_url_shipping_label', $body['url_shipping_label'] );
    172                         } else {
    173                             $note = 'RedBox error: ' . $body['msg'];
    174                             $order->add_order_note( $note );
    175                         }
     124            function redbox_create_shipment( $order_id, $posted_data, $order ) {
     125                if (!$order) return;
     126                $orderKey = $order->get_order_key();
     127                $orderNumber = $order->get_order_number();
     128
     129                $customerData = $this->redbox_get_data_customer($order);
     130                $priceData = $this->redbox_get_other_info($order);
     131
     132                $dataShipment = [
     133                    "store_url" => get_home_url(),
     134                    "reference" => $order_id,
     135                    "point_id" => $order->get_meta( '_redbox_point_id' ),
     136                    "customer_name" => $customerData['name'],
     137                    "customer_phone" => $customerData['phone'],
     138                    "customer_email" => $customerData['email'],
     139                    "customer_address" => $customerData['adddress'],
     140                    "cod_amount" => "",
     141                    "cod_currency" => "",
     142                    "shipping_price" => $priceData['shipping_total'],
     143                    "shipping_currency" => $order->get_currency(),
     144                    "items" => $this->redbox_get_product($order),
     145                    "from_platform" => "woo_commerce"
     146                ];
     147                if ($order->get_payment_method() == "cod") {
     148                    $dataShipment['cod_amount'] = $priceData['order_total'];
     149                    $dataShipment['cod_currency'] = $priceData['curency'];
     150                } else {
     151                    $dataShipment['cod_amount'] = 0;
     152                    $dataShipment['cod_currency'] = $priceData['curency'];
     153                }
     154                if ($this->redbox_validate_body_create_shipment($dataShipment)) {
     155                    $urlQuery = REDBOX_URL_CREATE_SHIPMENT;
     156                    $options = array(
     157                        'headers' => array(
     158                            'Authorization' => 'Bearer ' . $this->redboxKey
     159                        ),
     160                        'body' => $dataShipment
     161                    );
     162                    $response = wp_remote_post($urlQuery, $options);
     163                    $body = json_decode( wp_remote_retrieve_body( $response ), true );
     164                    if ($body['success']) {
     165                        $note = 'RedBox tracking number: ' . $body['tracking_number'];
     166                        $order->add_order_note( $note );
     167                        $order->update_meta_data( 'redbox_shipment_url_shipping_label', $body['url_shipping_label'] );
     168                    } else {
     169                        $note = 'RedBox error: ' . $body['msg'];
     170                        $order->add_order_note( $note );
    176171                    }
    177                    
    178                     $order->update_meta_data( '_thankyou_action_done', true );
    179                     $order->save();
    180                 }
     172                }
     173               
     174                $order->save();
    181175            }
    182176
     
    195189
    196190            function redbox_update_shipment( $post_id ) {
    197                 if ('shop_order' == $_POST[ 'post_type' ]) {
     191                if (isset($_POST[ 'post_type' ]) && 'shop_order' == $_POST[ 'post_type' ]) {
    198192                    $order = wc_get_order( $post_id );
    199193                    $orderKey = $order->get_order_key();
     
    267261            }
    268262               
    269             function redbox_show_redbox_point_in_admin_order_detail( $order ) {   
     263            function redbox_show_redbox_point_in_admin_order_detail(  $order ) {   
    270264               $order_id = $order->get_id();
    271265               if (get_post_meta( $order_id, '_redbox_point', true )) {
     
    301295                add_action('wp_ajax_getlispoint', array( $this, 'redbox_get_list_point' ));
    302296                add_action('wp_ajax_nopriv_getlispoint', array( $this, 'redbox_get_list_point' ));
    303                 add_action('woocommerce_thankyou', array( $this, 'redbox_create_shipment' ));
     297                add_action('woocommerce_checkout_order_processed', array( $this, 'redbox_create_shipment' ), 10, 3);
    304298                add_action( 'woocommerce_after_checkout_billing_form', array($this, 'redbox_add_point_field') );
    305299
    306300
    307301                add_action( 'woocommerce_checkout_update_order_meta', array($this, 'redbox_save_redbox_point_when_create_order') );
    308                 // add_action( 'woocommerce_admin_order_data_after_shipping_address', array($this, 'redbox_show_redbox_point_in_admin_order_detail'));
    309                 add_action( 'woocommerce_thankyou', array($this, 'redbox_show_redbox_point_when_create_order_success') );
     302                add_action( 'woocommerce_admin_order_data_after_shipping_address', array($this, 'redbox_show_redbox_point_in_admin_order_detail'));
     303                add_action( 'woocommerce_checkout_order_processed', array($this, 'redbox_show_redbox_point_when_create_order_success') );
    310304                add_action( 'woocommerce_view_order', array($this, 'redbox_show_redbox_point_when_create_order_success') );
    311305                add_action('woocommerce_checkout_process', array($this, 'redbox_validate_with_redbox_pickup'));
  • redbox-pickup/tags/1.4/readme.txt

    r2493015 r2515504  
    55Requires at least: 3.3
    66Tested up to: 5.5.1
    7 Stable tag: 1.3
     7Stable tag: 1.4
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3737= 1.3 =
    3838Bound map when search address or click my location
     39= 1.4 =
     40Enhance hook to complete order
    3941
    4042
     
    4446= 1.3 =
    4547Bound map when search address or click my location
     48= 1.4 =
     49Enhance hook to complete order
    4650
    4751
  • redbox-pickup/tags/1.4/redbox.php

    r2493015 r2515504  
    44        * Description: This plugin allows customers pickup package at RedBox Locker.
    55        * Plugin URI: https://woocommerce.com/
    6         * Version: 1.3
     6        * Version: 1.4
    77        * Author: RedBox
    88        * Author URI: https://redboxsa.com
  • redbox-pickup/trunk/front/front.php

    r2491692 r2515504  
    122122            }
    123123
    124             function redbox_create_shipment( $order_id ) {
    125                 if ( ! $order_id )
    126                     return;
    127 
    128                 if( ! get_post_meta( $order_id, '_thankyou_action_done', true ) ) {
    129                     $order = wc_get_order( $order_id );
    130                     $orderKey = $order->get_order_key();
    131                     $orderNumber = $order->get_order_number();
    132 
    133                     $customerData = $this->redbox_get_data_customer($order);
    134                     $priceData = $this->redbox_get_other_info($order);
    135 
    136                     $dataShipment = [
    137                         "store_url" => get_home_url(),
    138                         "reference" => $order_id,
    139                         "point_id" => $order->get_meta( '_redbox_point_id' ),
    140                         "customer_name" => $customerData['name'],
    141                         "customer_phone" => $customerData['phone'],
    142                         "customer_email" => $customerData['email'],
    143                         "customer_address" => $customerData['adddress'],
    144                         "cod_amount" => "",
    145                         "cod_currency" => "",
    146                         "shipping_price" => $priceData['shipping_total'],
    147                         "shipping_currency" => $order->get_currency(),
    148                         "items" => $this->redbox_get_product($order),
    149                         "from_platform" => "woo_commerce"
    150                     ];
    151                     if ($order->get_payment_method() == "cod") {
    152                         $dataShipment['cod_amount'] = $priceData['order_total'];
    153                         $dataShipment['cod_currency'] = $priceData['curency'];
    154                     } else {
    155                         $dataShipment['cod_amount'] = 0;
    156                         $dataShipment['cod_currency'] = $priceData['curency'];
    157                     }
    158                     if ($this->redbox_validate_body_create_shipment($dataShipment)) {
    159                         $urlQuery = REDBOX_URL_CREATE_SHIPMENT;
    160                         $options = array(
    161                             'headers' => array(
    162                                 'Authorization' => 'Bearer ' . $this->redboxKey
    163                             ),
    164                             'body' => $dataShipment
    165                         );
    166                         $response = wp_remote_post($urlQuery, $options);
    167                         $body = json_decode( wp_remote_retrieve_body( $response ), true );
    168                         if ($body['success']) {
    169                             $note = 'RedBox tracking number: ' . $body['tracking_number'];
    170                             $order->add_order_note( $note );
    171                             $order->update_meta_data( 'redbox_shipment_url_shipping_label', $body['url_shipping_label'] );
    172                         } else {
    173                             $note = 'RedBox error: ' . $body['msg'];
    174                             $order->add_order_note( $note );
    175                         }
     124            function redbox_create_shipment( $order_id, $posted_data, $order ) {
     125                if (!$order) return;
     126                $orderKey = $order->get_order_key();
     127                $orderNumber = $order->get_order_number();
     128
     129                $customerData = $this->redbox_get_data_customer($order);
     130                $priceData = $this->redbox_get_other_info($order);
     131
     132                $dataShipment = [
     133                    "store_url" => get_home_url(),
     134                    "reference" => $order_id,
     135                    "point_id" => $order->get_meta( '_redbox_point_id' ),
     136                    "customer_name" => $customerData['name'],
     137                    "customer_phone" => $customerData['phone'],
     138                    "customer_email" => $customerData['email'],
     139                    "customer_address" => $customerData['adddress'],
     140                    "cod_amount" => "",
     141                    "cod_currency" => "",
     142                    "shipping_price" => $priceData['shipping_total'],
     143                    "shipping_currency" => $order->get_currency(),
     144                    "items" => $this->redbox_get_product($order),
     145                    "from_platform" => "woo_commerce"
     146                ];
     147                if ($order->get_payment_method() == "cod") {
     148                    $dataShipment['cod_amount'] = $priceData['order_total'];
     149                    $dataShipment['cod_currency'] = $priceData['curency'];
     150                } else {
     151                    $dataShipment['cod_amount'] = 0;
     152                    $dataShipment['cod_currency'] = $priceData['curency'];
     153                }
     154                if ($this->redbox_validate_body_create_shipment($dataShipment)) {
     155                    $urlQuery = REDBOX_URL_CREATE_SHIPMENT;
     156                    $options = array(
     157                        'headers' => array(
     158                            'Authorization' => 'Bearer ' . $this->redboxKey
     159                        ),
     160                        'body' => $dataShipment
     161                    );
     162                    $response = wp_remote_post($urlQuery, $options);
     163                    $body = json_decode( wp_remote_retrieve_body( $response ), true );
     164                    if ($body['success']) {
     165                        $note = 'RedBox tracking number: ' . $body['tracking_number'];
     166                        $order->add_order_note( $note );
     167                        $order->update_meta_data( 'redbox_shipment_url_shipping_label', $body['url_shipping_label'] );
     168                    } else {
     169                        $note = 'RedBox error: ' . $body['msg'];
     170                        $order->add_order_note( $note );
    176171                    }
    177                    
    178                     $order->update_meta_data( '_thankyou_action_done', true );
    179                     $order->save();
    180                 }
     172                }
     173               
     174                $order->save();
    181175            }
    182176
     
    195189
    196190            function redbox_update_shipment( $post_id ) {
    197                 if ('shop_order' == $_POST[ 'post_type' ]) {
     191                if (isset($_POST[ 'post_type' ]) && 'shop_order' == $_POST[ 'post_type' ]) {
    198192                    $order = wc_get_order( $post_id );
    199193                    $orderKey = $order->get_order_key();
     
    267261            }
    268262               
    269             function redbox_show_redbox_point_in_admin_order_detail( $order ) {   
     263            function redbox_show_redbox_point_in_admin_order_detail(  $order ) {   
    270264               $order_id = $order->get_id();
    271265               if (get_post_meta( $order_id, '_redbox_point', true )) {
     
    301295                add_action('wp_ajax_getlispoint', array( $this, 'redbox_get_list_point' ));
    302296                add_action('wp_ajax_nopriv_getlispoint', array( $this, 'redbox_get_list_point' ));
    303                 add_action('woocommerce_thankyou', array( $this, 'redbox_create_shipment' ));
     297                add_action('woocommerce_checkout_order_processed', array( $this, 'redbox_create_shipment' ), 10, 3);
    304298                add_action( 'woocommerce_after_checkout_billing_form', array($this, 'redbox_add_point_field') );
    305299
    306300
    307301                add_action( 'woocommerce_checkout_update_order_meta', array($this, 'redbox_save_redbox_point_when_create_order') );
    308                 // add_action( 'woocommerce_admin_order_data_after_shipping_address', array($this, 'redbox_show_redbox_point_in_admin_order_detail'));
    309                 add_action( 'woocommerce_thankyou', array($this, 'redbox_show_redbox_point_when_create_order_success') );
     302                add_action( 'woocommerce_admin_order_data_after_shipping_address', array($this, 'redbox_show_redbox_point_in_admin_order_detail'));
     303                add_action( 'woocommerce_checkout_order_processed', array($this, 'redbox_show_redbox_point_when_create_order_success') );
    310304                add_action( 'woocommerce_view_order', array($this, 'redbox_show_redbox_point_when_create_order_success') );
    311305                add_action('woocommerce_checkout_process', array($this, 'redbox_validate_with_redbox_pickup'));
  • redbox-pickup/trunk/readme.txt

    r2493015 r2515504  
    55Requires at least: 3.3
    66Tested up to: 5.5.1
    7 Stable tag: 1.3
     7Stable tag: 1.4
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3737= 1.3 =
    3838Bound map when search address or click my location
     39= 1.4 =
     40Enhance hook to complete order
    3941
    4042
     
    4446= 1.3 =
    4547Bound map when search address or click my location
     48= 1.4 =
     49Enhance hook to complete order
    4650
    4751
  • redbox-pickup/trunk/redbox.php

    r2493015 r2515504  
    44        * Description: This plugin allows customers pickup package at RedBox Locker.
    55        * Plugin URI: https://woocommerce.com/
    6         * Version: 1.3
     6        * Version: 1.4
    77        * Author: RedBox
    88        * Author URI: https://redboxsa.com
Note: See TracChangeset for help on using the changeset viewer.