Plugin Directory

Changeset 2346001


Ignore:
Timestamp:
07/24/2020 10:35:23 AM (6 years ago)
Author:
returnedx
Message:

huge update - adding orderpush

Location:
orderbee/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orderbee/trunk/README.txt

    r2345995 r2346001  
    44Requires at least: 4.0.1
    55Tested up to: 5.4.2
    6 Stable tag: 1.1.0
     6Stable tag: 1.1.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • orderbee/trunk/orderbee.php

    r2345996 r2346001  
    1717 * Plugin URI:        https://www.orderbee.be
    1818 * Description:       This plugin makes a fast and safe connection between your Woocommerce and OrderBee.
    19  * Version:           1.1.0
     19 * Version:           1.1.1
    2020 * Author:            OrderBee
    2121 * Author URI:        https://www.orderbee.be
     
    3535 * Rename this for your plugin and update it as you release new versions.
    3636 */
    37 define('ORDERBEE_VERSION', '1.1.0');
     37define('ORDERBEE_VERSION', '1.1.1');
    3838
    3939/**
     
    6464require plugin_dir_path(__FILE__) . 'includes/class-orderbee.php';
    6565require plugin_dir_path(__FILE__) . 'includes/class-orderbee-settings.php';
    66 include plugin_dir_path(__FILE__) . 'includes/class-orderbee-pushorders.php';
    6766
    6867/**
     
    150149
    151150}
     151
     152if (!function_exists('obfrwc_push_to_server')) {
     153
     154    function obfrwc_push_to_server($order_id) {
     155        global $wpdb;
     156        $order = new WC_Order($order_id);         
     157        $input = array();
     158        $input['ordernumber'] = $order->get_order_number();   
     159        $input['email'] = $order->get_billing_email();   
     160        $input['name'] = $order->get_formatted_billing_full_name();
     161        $input['company_name'] = $order->get_billing_company();   
     162        $input['contact_number'] = str_replace(' ', '', $order->get_billing_phone());
     163        $input['address_1'] = $order->get_billing_address_1();     
     164        $input['address_2'] = $order->get_billing_address_2();   
     165        $input['city'] = $order->get_billing_city();     
     166        $input['postal_code'] = $order->get_billing_postcode();   
     167        $input['country'] = $order->get_billing_country();   
     168        $input['del_name'] = $order->get_formatted_shipping_full_name();
     169        $input['del_company_name'] = $order->get_shipping_company();   
     170        $input['del_address_1'] = $order->get_shipping_address_1();     
     171        $input['del_address_2'] = $order->get_shipping_address_2();   
     172        $input['del_city'] = $order->get_shipping_city();     
     173        $input['del_postal_code'] = $order->get_shipping_postcode();   
     174        $input['del_country'] = $order->get_shipping_country();   
     175        $input['instructions'] = $order->get_customer_note();     
     176        $input['payment_method'] = $order->get_payment_method();     
     177        $input['payment_date'] = $order->get_date_paid();   
     178        $input['shipping_total'] = $order->get_shipping_total();
     179        $input['shipping_tax'] = $order->get_shipping_tax();
     180        $shipping_lines = $order->get_shipping_methods();
     181        foreach($shipping_lines as $id => $shipping_line){
     182            $shippingLineArray = $shipping_line->get_data();
     183            $taxesShipping = WC_Tax::get_rates($shipping_line->get_tax_class());
     184            foreach($taxesShipping as $taxShipping){
     185                $shippingLineArray["tax_rate"] = $taxShipping['rate'];
     186            }
     187            $input['shipping_lines'][] = $shippingLineArray;
     188        }
     189        $meta_data = $order->get_meta_data();
     190        foreach($meta_data as $meta){
     191            $meta = $meta->get_data();
     192            $input['meta_data'][] = $meta;
     193        }
     194        $input['order_total_inc'] = wc_format_decimal($order->get_total(), 2);
     195        $items = $order->get_items();
     196        foreach($items as $item){
     197            $itemIntel = $item->get_data();
     198            $itemArray = array();
     199            $product = new WC_Product($itemIntel['product_id']);
     200            $sku = $product->get_sku();
     201            $itemArray["sku"] = $sku;
     202            $itemArray["name"] = $itemIntel['name'];
     203            $itemArray["quantity"] = $itemIntel['quantity'];
     204            $itemArray["subtotal"] = $itemIntel['subtotal'];
     205            $itemArray["subtotal_tax"] = $itemIntel['subtotal_tax'];
     206            $taxes = WC_Tax::get_rates($item->get_tax_class());
     207            foreach($taxes as $tax){
     208                $itemArray["tax_rate"] = $tax['rate'];
     209            }
     210            $itemArray["meta_data"] = $itemIntel['meta_data'];
     211            $input['items'][] = $itemArray;
     212        }
     213        $fees = $order->get_items('fee');
     214        if($fees){
     215            $input['fee'] = array();
     216            foreach($fees as $fee){
     217                $feeArray = $fee->get_data();
     218                $taxesFee = WC_Tax::get_rates($fee->get_tax_class());
     219                foreach($taxesFee as $taxFee){
     220                    $feeArray["tax_rate"] = $taxFee['rate'];
     221                }
     222                $input['fee'][] = $feeArray;
     223            }
     224        }
     225       
     226       
     227        $url = 'https://app.orderbee.be/api/Woocommerce/NewOrder';
     228        $obfrwc_server_auth_id = get_option('obfrwc_server_auth_id');
     229        $arr_auth_param = array(
     230            'consumer_id' => $obfrwc_server_auth_id,
     231            'data' => json_encode($input),
     232            'http'     => $_SERVER["HTTP_HOST"]
     233        );
     234        $response      = wp_remote_post($url, ['body' => $arr_auth_param]);
     235        $response_code = wp_remote_retrieve_response_code($response);
     236    }
     237
     238    add_action('woocommerce_payment_complete', 'obfrwc_push_to_server');
     239}
Note: See TracChangeset for help on using the changeset viewer.