Plugin Directory

Changeset 3147200


Ignore:
Timestamp:
09/05/2024 04:13:11 PM (18 months ago)
Author:
phcwordpress
Message:

new option for update stock & prices

Location:
drivefx-woocommerce/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • drivefx-woocommerce/trunk/PHCLibrary/classes/invoice.php

    r2556290 r3147200  
    55    public $billing_name;
    66    public $billing_email;
    7     public $billing_address_1;
     7    public $billing_address;
    88    public $billing_city;
    99    public $billing_phone;
  • drivefx-woocommerce/trunk/PHCLibrary/invoices.php

    r3059006 r3147200  
    340340                                # Billing address data
    341341                                $response['result'][0]['nome2'] = $ft->billing_name;
    342                                 $response['result'][0]['morada'] = $ft->billing_address_1;
     342                                $response['result'][0]['morada'] = $ft->billing_address;
    343343                                $response['result'][0]['local'] = $ft->billing_city;
    344344                                $response['result'][0]['provincia'] = $ft->billing_city;
  • drivefx-woocommerce/trunk/class.DriveFxWoocommerce.php

    r3063623 r3147200  
    375375            $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME);
    376376            $method = sanitize_text_field( $_POST['method'] );
    377             $refs = (isset($_POST['refs']) && is_array($_POST['refs'])) ? filter_var_array($_POST['refs'], FILTER_SANITIZE_STRING) : '';
     377            $refs = (isset($_POST['refs']) && is_array($_POST['refs'])) ? array_map('htmlspecialchars', $_POST['refs']) : '';
    378378            $selectItems = isset($_POST['selectItems']) ? filter_var($_POST['selectItems'], FILTER_SANITIZE_STRING) : '';
    379379            $typeOfOrder = isset($_POST['typeOfOrder']) ? filter_var($_POST['typeOfOrder'], FILTER_SANITIZE_STRING) : '';
     
    19811981                $this->logs->writeFileLog('listProducts', $ch);
    19821982                unset($_SESSION['username']);
     1983                return "";
    19831984            } else if(empty($response)){
    19841985                $this->logs->writeFileLog('listProducts', 'EMPTY RESPONSE');
    19851986                unset($_SESSION['username']);
     1987                return "";
    19861988            } else if(isset($response['messages'][0]['messageCodeLocale'])){
    19871989                $this->logs->writeFileLog('listProducts', $response['messages'][0]['messageCodeLocale']);
    19881990                unset($_SESSION['username']);
     1991                return "";
    19891992            } else {
    19901993                # Get the Engine-Auth token and add to credentials
     
    20142017
    20152018                // Set if Vat is included or not (by default = false)
    2016                 $taxIncluded = 0;
    2017                 if (isset($settings['backend']['includeTaxonSendCost']) && $settings['backend']['includeTaxonSendCost'] == "true"){
    2018                     $taxIncluded = 1;
    2019                 }
     2019                $taxIncluded = isset($settings['backend']['includeTaxonSendCost']) && $settings['backend']['includeTaxonSendCost'] == "true" ? 1 : 0;
    20202020
    20212021                // Obtain PHC gama
     
    20732073                    $response = $this->utils_services->productQuery($ch, $credentials, "st.".$settings['backend']['productPriceColumn'], $filterItems);
    20742074                    //$this->logs->writeFileLog('Sts result:', $response);
    2075 
    20762075                } else {                                       
    20772076                    $response = $this->utils_services->productQuery2($ch, $credentials, "st.".$settings['backend']['productPriceColumn'],$settings['backend']['warehouse'], $filterItems);
     
    21102109                    }
    21112110
    2112                     //Create rows with information of products
    21132111                    $tableProducts = '';
    2114                     $tableProducts .= "<thead><tr><th style='text-align: left;'><input type='checkbox' onClick='toggle(this)'/> Select all</th><th style='text-align: left;'>Ref</th><th style='text-align: left;'>Product Name</th><th style='text-align: left;'>Family</th><th style='text-align: left;'>Sale Price</th>";
    2115 
    2116                     if($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9){
    2117                         $tableProducts .= "<th style='text-align: right;'>Stock</th></tr></thead>";
    2118                     } else {
    2119                         $tableProducts .= "</tr></thead>";
    2120                     }
    2121 
    2122                     if(is_array($response['result'])){
    2123                         if(!empty($settings['backend']['productPriceColumn']) && $settings['backend']['productPriceColumn'] != 'epv0'){
    2124                             foreach ($response['result'] as $key => $value) {
    2125 
    2126                                 # get the list of products by sku, from "wp_postmeta" table (already imported)
    2127                                 global $wpdb;
    2128                                 $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $response['result'][$key]['ref'] ) );
    2129                                 //$this->logs->writeFileLog('product_id:', $product_id);
    2130 
    2131                                 //Create Table
    2132                                 $tableProducts .= "<tr>";
    2133                                 if($product_id == ""){
    2134                                     if($arrayRef[$response['result'][$key]['ref']] < 0){
    2135 
    2136                                         $tableProducts .= "<td style='text-align: left;'><input type='checkbox' disabled name='checkboxes' value='".$response['result'][$key]['ref']."'></td>";
    2137                                     } else {
    2138                                         $tableProducts .= "<td style='text-align: left;'><input type='checkbox' name='checkboxes' value='".$response['result'][$key]['ref']."'></td>";
    2139                                     }
    2140                                 } else {
    2141                                     $tableProducts .= "<td style='text-align: left;'><div class='updateStockShop' id='".$response['result'][$key]['ref']."'><img src='".plugins_url('/images/right.png', __FILE__)."' alt='' width='16' height='16'></div></td>";
    2142                                 }
    2143 
    2144                                 $tableProducts .= "<td style='text-align: left;'>". $response['result'][$key]['ref'].
    2145                                                     "</td><td style='text-align: left;'>". $response['result'][$key]['design'].
    2146                                                     "</td><td style='text-align: left;'>". $response['result'][$key]['familia'].
    2147                                                     "</td><td style='text-align: left;'>". $response['result'][$key][$settings['backend']['productPriceColumn']]."</td>";
    2148 
    2149                                 //Only exists stocks after Star GAMA
    2150                                 if($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9){
    2151                                     if($response['result'][$key]['stock'] < 0){
    2152                                         $tableProducts .= "<td style='text-align: right; color: red;'>".$arrayRef[$response['result'][$key]['ref']]."</td></tr>";
    2153                                     } else {
    2154                                         $tableProducts .= "<td style='text-align: right;'>".$arrayRef[$response['result'][$key]['ref']]."</td></tr>";
    2155                                     }
    2156                                 }
    2157                             }
     2112
     2113                    if (is_array($response['result'])) {
     2114                        if (!empty($settings['backend']['productPriceColumn']) && $settings['backend']['productPriceColumn'] != 'epv0') {
     2115                            // Generate The Product Table
     2116                            $tableProducts = $this->generateProductTable($response['result'], $arrayRef, $settings);
    21582117                            echo $tableProducts;
    21592118                        } else {
    21602119                            $this->logs->writeFileLog('listProducts4', 'Products: Empty productPriceColumn');
    21612120                        }
    2162                     }               
     2121                    } else {
     2122                        $this->logs->writeFileLog('listProducts4', 'Products: No data available');
     2123                    }   
    21632124                }
    21642125
     
    21692130        }
    21702131
     2132        private function generateProductTable($products, $arrayRef, $settings)
     2133        {
     2134            $tableProducts = '';
     2135            $tableProducts .= "<thead><tr><th style='text-align: left;'><input type='checkbox' onClick='toggle(this)'/> Select all</th><th style='text-align: left;'>Ref</th><th style='text-align: left;'>Product Name</th><th style='text-align: left;'>Family</th><th style='text-align: left;'>Sale Price</th>";
     2136
     2137            if ($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9) {
     2138                $tableProducts .= "<th style='text-align: right;'>Stock</th></tr></thead>";
     2139            } else {
     2140                $tableProducts .= "</tr></thead>";
     2141            }
     2142
     2143            if (is_array($products)) {
     2144                if (!empty($settings['backend']['productPriceColumn']) && $settings['backend']['productPriceColumn'] != 'epv0') {
     2145                    foreach ($products as $value) {
     2146                        global $wpdb;
     2147                        $sku = $value['ref'];
     2148                        $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value=%s LIMIT 1", $sku));
     2149
     2150                        $tableProducts .= "<tr>";
     2151                        if ($product_id == "") {
     2152                            $tableProducts .= $arrayRef[$sku] < 0 ? "<td style='text-align: left;'><input type='checkbox' disabled name='checkboxes' value='$sku'></td>" : "<td style='text-align: left;'><input type='checkbox' name='checkboxes' value='$sku'></td>";
     2153                        } else {
     2154                            $tableProducts .= "<td style='text-align: left;'><div class='updateStockShop' id='$sku'><img src='" . plugins_url('/images/right.png', __FILE__) . "' alt='' width='16' height='16'></div></td>";
     2155                        }
     2156
     2157                        $tableProducts .= "<td style='text-align: left;'>$sku</td><td style='text-align: left;'>" . $value['design'] . "</td><td style='text-align: left;'>" . $value['familia'] . "</td><td style='text-align: left;'>" . $value[$settings['backend']['productPriceColumn']] . "</td>";
     2158
     2159                        if ($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9) {
     2160                            $tableProducts .= $value['stock'] < 0 ? "<td style='text-align: right; color: red;'>" . $arrayRef[$sku] . "</td></tr>" : "<td style='text-align: right;'>" . $arrayRef[$sku] . "</td></tr>";
     2161                        }
     2162                    }
     2163                } else {
     2164                    $this->logs->writeFileLog('listProducts4', 'Products: Empty productPriceColumn');
     2165                }
     2166            }
     2167            return $tableProducts;
     2168        }
     2169
    21712170        # Save products in online shop
    21722171        public function saveProducts($refs){
    21732172            $ch = curl_init();
    2174 
     2173           
    21752174            if(is_array($refs)){           
    21762175                # Get Credentials
  • drivefx-woocommerce/trunk/css/style_datatable.css

    r2526532 r3147200  
    498498}
    499499
    500 #updateStocks, #updateStocks, #updatePrices, #updateAllFields {
     500#updateStocks, #updateStocks, #updatePrices, #updateAllFields, #applyForEntireTable{
    501501    margin-left: 10px;
    502502    cursor: pointer;
    503503    margin-top: 20px;
    504504    float:left;
     505}
     506
     507#applyForEntireTable{
     508  background-color: #e4eaf1;
     509  padding: 5px;
     510  border-radius: 5px;
    505511}
    506512
  • drivefx-woocommerce/trunk/js/drivefx-woocommerce.js

    r2526532 r3147200  
    22
    33jQuery(document).ready(function() {
    4 
    54    //Initialize plugin
    65    jQuery('#backend_url_initialize').click(function (){
     
    3130    jQuery('#updatePrices').hide();
    3231    jQuery('#updateAllFields').hide();
     32    jQuery('#applyForEntireTable').hide();
    3333
    3434    jQuery.post(url, {
     
    8989                jQuery('#updatePrices').show();
    9090                jQuery('#updateAllFields').show();
     91                jQuery('#applyForEntireTable').show();
    9192                jQuery('#saveProductInShop').show();
    9293                jQuery('#importToShop').show();
     
    99100                jQuery('#updatePrices').hide();
    100101                jQuery('#updateAllFields').hide();
     102                jQuery('#applyForEntireTable').hide();
    101103                jQuery('#saveProductInShop').hide();
    102104            }
     
    118120        jQuery('#updatePrices').hide();
    119121        jQuery('#updateAllFields').hide();
     122        jQuery('#applyForEntireTable').hide();
    120123
    121124        // stop normal form submission handler
     
    143146            jQuery('#updatePrices').show();
    144147            jQuery('#updateAllFields').show();
     148            jQuery('#applyForEntireTable').show();
    145149            jQuery('#loader2').html('');
    146150
     
    165169                    jQuery('#updatePrices').show();
    166170                    jQuery('#updateAllFields').show();
     171                    jQuery('#applyForEntireTable').show();
    167172                    jQuery('#saveProductInShop').show();
    168173                    jQuery('#importToShop').show();
     
    175180                    jQuery('#updatePrices').hide();
    176181                    jQuery('#updateAllFields').hide();
     182                    jQuery('#applyForEntireTable').hide();
    177183                    jQuery('#saveProductInShop').hide();
    178184                }
     
    186192        //Update products
    187193        var arr = new Array();
    188         jQuery(".updateStockShop").each(function() {
    189           arr.push(jQuery(this).attr('id'));
    190         });
    191 
     194
     195        // Verify if the #applyForEntireTableCheckbox is checked
     196        if (jQuery('#applyForEntireTableCheckbox').is(':checked')) {
     197            // If checked, we get all data from the table
     198            const data = jQuery('#tableOfProducts').DataTable().fnGetData();
     199            arr = data.filter(element => element[0].indexOf('updateStockShop') !== -1).map(value => value[1]);
     200        } else {
     201            // If unchecked, we only iterate through the visible elements on the page
     202            jQuery(".updateStockShop").each(function() {
     203                arr.push(jQuery(this).attr('id'));
     204            });
     205        }
     206       
    192207        jQuery('#loader2').html('<img style="margin-top: 10px; margin-left: 20px;" src="'+pathPlugin+'images/ajax-loader.gif" title="Loading..">');
    193208        jQuery('#saveProductInShop').hide();
     
    195210        jQuery('#updatePrices').hide();
    196211        jQuery('#updateAllFields').hide();
     212        jQuery('#applyForEntireTable').hide();
    197213
    198214        // stop normal form submission handler
     
    216232            jQuery('#updatePrices').show();
    217233            jQuery('#updateAllFields').show();
     234            jQuery('#applyForEntireTable').show();
    218235            jQuery('#loader2').html('');
    219236
     
    238255                    jQuery('#updatePrices').show();
    239256                    jQuery('#updateAllFields').show();
     257                    jQuery('#applyForEntireTable').show();
    240258                    jQuery('#saveProductInShop').show();
    241259                    jQuery('#importToShop').show();
     
    248266                    jQuery('#updatePrices').hide();
    249267                    jQuery('#updateAllFields').hide();
     268                    jQuery('#applyForEntireTable').hide();
    250269                    jQuery('#saveProductInShop').hide();
    251270                }
     
    259278        //Update products
    260279        var arr = new Array();
    261         jQuery(".updateStockShop").each(function() {
    262           arr.push(jQuery(this).attr('id'));
    263         });
    264 
     280
     281        // Verify if the #applyForEntireTableCheckbox is checked
     282        if (jQuery('#applyForEntireTableCheckbox').is(':checked')) {
     283            // If checked, we get all data from the table
     284            const data = jQuery('#tableOfProducts').DataTable().fnGetData();
     285            arr = data.filter(element => element[0].indexOf('updateStockShop') !== -1).map(value => value[1]);
     286        } else {
     287            // If unchecked, we only iterate through the visible elements on the page
     288            jQuery(".updateStockShop").each(function() {
     289                arr.push(jQuery(this).attr('id'));
     290            });
     291        }
     292   
    265293        jQuery('#loader2').html('<img style="margin-top: 10px; margin-left: 20px;" src="'+pathPlugin+'images/ajax-loader.gif" title="Loading..">');
    266294        jQuery('#saveProductInShop').hide();
     
    268296        jQuery('#updatePrices').hide();
    269297        jQuery('#updateAllFields').hide();
     298        jQuery('#applyForEntireTable').hide();
    270299        // stop normal form submission handler
    271300        event.preventDefault();
    272         //save products in MySQL
     301        // save products in MySQL
    273302        jQuery.post(url, {
    274303            action: 'woocommerce_fx',
     
    287316            jQuery('#updatePrices').show();
    288317            jQuery('#updateAllFields').show();
     318            jQuery('#applyForEntireTable').show();
    289319            jQuery('#loader2').html('');
    290320
     
    309339                    jQuery('#updatePrices').show();
    310340                    jQuery('#updateAllFields').show();
     341                    jQuery('#applyForEntireTable').show();
    311342                    jQuery('#saveProductInShop').show();
    312343                    jQuery('#importToShop').show();
     
    319350                    jQuery('#updatePrices').hide();
    320351                    jQuery('#updateAllFields').hide();
     352                    jQuery('#applyForEntireTable').hide();
    321353                    jQuery('#saveProductInShop').hide();
    322354                }
     
    330362        //Update products
    331363        var arr = new Array();
    332         jQuery(".updateStockShop").each(function() {
    333           arr.push(jQuery(this).attr('id'));
    334         });
     364
     365        // Verify if the #applyForEntireTableCheckbox is checked
     366        if (jQuery('#applyForEntireTableCheckbox').is(':checked')) {
     367            // If checked, we get all data from the table
     368            const data = jQuery('#tableOfProducts').DataTable().fnGetData();
     369            arr = data.filter(element => element[0].indexOf('updateStockShop') !== -1).map(value => value[1]);
     370        } else {
     371            // If unchecked, we only iterate through the visible elements on the page
     372            jQuery(".updateStockShop").each(function() {
     373                arr.push(jQuery(this).attr('id'));
     374            });
     375        }
    335376
    336377        jQuery('#loader2').html('<img style="margin-top: 10px; margin-left: 20px;" src="'+pathPlugin+'images/ajax-loader.gif" title="Loading..">');
     
    339380        jQuery('#updatePrices').hide();
    340381        jQuery('#updateAllFields').hide();
     382        jQuery('#applyForEntireTable').hide();
    341383        // stop normal form submission handler
    342384        event.preventDefault();
     
    358400            jQuery('#updatePrices').show();
    359401            jQuery('#updateAllFields').show();
     402            jQuery('#applyForEntireTable').show();
    360403            jQuery('#loader2').html('');
    361404
     
    380423                    jQuery('#updatePrices').show();
    381424                    jQuery('#updateAllFields').show();
     425                    jQuery('#applyForEntireTable').show();
    382426                    jQuery('#saveProductInShop').show();
    383427                    jQuery('#importToShop').show();
     
    390434                    jQuery('#updatePrices').hide();
    391435                    jQuery('#updateAllFields').hide();
     436                    jQuery('#applyForEntireTable').hide();
    392437                    jQuery('#saveProductInShop').hide();
    393438                }
  • drivefx-woocommerce/trunk/settings/import-products.php

    r2526532 r3147200  
    3434
    3535<div id="updateAllFields" class="button button-primary" title="Update all fields of products from PHC">
    36     <img id="plus" src="<?php echo plugins_url('/../images/update.png', __FILE__) ?>" title="Update all fields of products in your online store"> Update all fields
     36    <img id="plus" src="<?php echo plugins_url('/../images/update.png', __FILE__) ?>" title="Update all data of products in your online store"> Update all Fields
    3737</div>
     38
     39<!-- Checkbox option -->
     40<div id="applyForEntireTable" class="option" title="Apply the updates for all imported products, from the whole table">
     41    <input id="applyForEntireTableCheckbox" type="checkbox" name="newOptionCheckbox" value="1">
     42    <label for="applyForEntireTableCheckbox">Apply for all imported products</label>
     43</div>
  • drivefx-woocommerce/trunk/settings/syncro_gate.php

    r3081910 r3147200  
    2323    *                      ---  CREDENTIALS ---                       *
    2424    ******************************************************************/
     25
    2526        public function fetchCredentials(){
    2627            $credentials = new stdClass();
    27 
     28       
    2829            $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME);
    29             //$this->logs->writeFileLog('settings', $settings);
    30 
    31             // get token
     30       
     31            # Check if settings are available
     32            if (!$settings) {
     33                $this->logs->writeFileLog('credentials_error_001:', "PHC GO plugin configurations are missing");
     34                return null;
     35            }
     36       
     37            # Get token
    3238            global $wpdb;
    33             $table_name = $wpdb->prefix."postmeta";
    34             $query = "SELECT meta_value FROM %s WHERE meta_key = %s";
    35             $resultDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, '_token')));
    36 
    37             // build our web service full URL     
    38             if(!is_array($settings['backend']['url'])){
    39                 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html/');
    40                 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html');
    41                 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/');
    42             }
    43            
    44             // build credencials
    45             $credentials->backendUrl = isset($settings['backend']['url']) ? $settings['backend']['url'].$this->extraurl : null;
    46             $credentials->userCode = isset($settings['backend']['username']) ? $settings['backend']['username'] : null;
    47             $credentials->password = isset($settings['backend']['password']) ? $settings['backend']['password'] : null;
    48             $credentials->appId = isset($resultDB->meta_value) ? $resultDB->meta_value : null;
    49             $credentials->company = isset($settings['backend']['dbname']) ? $settings['backend']['dbname'] : null;
    50             $credentials->invoiceType = isset($settings['backend']['typeOfInvoice']) ? $settings['backend']['typeOfInvoice'] : null;
    51             $credentials->invoiceType_EU = isset($settings['backend']['typeOf_EU_Invoice']) ? $settings['backend']['typeOf_EU_Invoice'] : null;
    52 
     39            $meta_value = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = %s", '_token' ) );
     40       
     41            # Build credentials
     42            $credentials->backendUrl = isset($settings['backend']['url']) ? rtrim($settings['backend']['url'], '/html/') . $this->extraurl : null;
     43            $credentials->userCode = $settings['backend']['username'] ?? null;
     44            $credentials->password = $settings['backend']['password'] ?? null;
     45            $credentials->appId = $meta_value ?? null;
     46            $credentials->company = $settings['backend']['dbname'] ?? null;
     47            $credentials->invoiceType = $settings['backend']['typeOfInvoice'] ?? null;
     48            $credentials->invoiceType_EU = $settings['backend']['typeOf_EU_Invoice'] ?? null;
     49                 
    5350            return $credentials;
    5451        }
     
    5855    ******************************************************************/
    5956        public function fetchOrderData($order_id) {
    60             //get backendinfo from woocommerce
    61             $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME);
    62 
    63             #Get billind data query
    64             global $wpdb;
    65             $table_name = $wpdb->prefix."postmeta";
    66             $query = "SELECT meta_key, meta_value FROM %s where post_id = %d";
    67             $raw_order = $wpdb->get_results(str_replace("'", "", $wpdb->prepare($query, $table_name, sanitize_text_field($order_id))));
    68             //$this->logs->writeFileLog('raw_order', $raw_order);
    69 
    70             //get NIF name field (billing) from backendinfo
    71             $ft_nifName = '_billing_'.$settings['backend']['fieldNif'];
    72             //get NIF name field (shipping) from backendinfo
    73             $ship_nifName = '_shipping_'.$settings['backend']['fieldNif'];
    74 
    75             //get price column field from backendinfo
    76             $preco = intval(str_replace('epv', '', $settings['backend']['productPriceColumn']));
    77 
    7857            # Inicialize the syncro class
    7958            $syncroData = new stdClass();
    80                
     59           
    8160            /*******************************************************************
    82             *                       --- billing data  ---                      *
     61            *                 --- Settings backend Data  ---                   *
    8362            ********************************************************************/
    84                 foreach ($raw_order as $key => $value) {
    85                     if($value->meta_key == '_billing_country'){
    86                         $syncroData->billing_country = $value->meta_value;
    87                     }  else if($value->meta_key == '_billing_first_name') {
    88                         $syncroData->billing_first_name = $value->meta_value;
    89                     } else if($value->meta_key == '_billing_last_name') {
    90                         $syncroData->billing_last_name = $value->meta_value;
    91                     } else if($value->meta_key == '_billing_address_1') {
    92                         $syncroData->billing_address_1 = $value->meta_value;
    93                     } else if($value->meta_key == '_billing_city') {
    94                         $syncroData->billing_city = $value->meta_value;
    95                     } else if($value->meta_key == '_billing_postcode') {
    96                         $syncroData->billing_postcode = $value->meta_value;
    97                     } else if($value->meta_key == $ft_nifName) {
    98                         $syncroData->ft_nifName = $value->meta_value;
    99                     } else if($value->meta_key == '_billing_email') {
    100                         $syncroData->billing_email = $value->meta_value;
    101                     } else if($value->meta_key == '_billing_phone') {
    102                         $syncroData->billing_phone = $value->meta_value;
    103                     } else if($value->meta_key == '_shipping_country') {
    104                         $syncroData->shipping_country = $value->meta_value;
    105                     }  else if($value->meta_key == '_shipping_first_name') {
    106                         $syncroData->shipping_first_name = $value->meta_value;
    107                     } else if($value->meta_key == '_shipping_last_name') {
    108                         $syncroData->shipping_last_name = $value->meta_value;
    109                     } else if($value->meta_key == $ship_nifName) {
    110                         $syncroData->ship_nifName = $value->meta_value;
    111                     } else if($value->meta_key == '_shipping_address_1') {
    112                         $syncroData->shipping_address_1 = $value->meta_value;
    113                     } else if($value->meta_key == '_shipping_city') {
    114                         $syncroData->shipping_city = $value->meta_value;
    115                     } else if($value->meta_key == '_shipping_postcode') {
    116                         $syncroData->shipping_postcode = $value->meta_value;
    117                     } else if($value->meta_key == '_customer_user') {
    118                         $syncroData->customer_user = $value->meta_value;
    119                     }
    120                 }
    121 
     63                global $wpdb;
     64
     65                # Get backendinfo from woocommerce
     66                $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME);
     67
     68                # Check if settings are available
     69                if (!$settings) {
     70                    $this->logs->writeFileLog('syncro_error_001:', "PHC GO plugin configurations are missing");
     71                    return null;
     72                }
     73
     74                // Get NIF name field (billing) from plugin configs
     75                $bill_nifName = '_billing_'.$settings['backend']['fieldNif'];
     76                // Get NIF name field (shipping) from plugin configs
     77                $ship_nifName = '_shipping_'.$settings['backend']['fieldNif'];
     78                // Get price column field from plugin configs
     79                $preco = intval(str_replace('epv', '', $settings['backend']['productPriceColumn']));
     80           
     81                $syncroData->createInvoice = (isset($settings['backend']['createInvoice']) && $settings['backend']['createInvoice'] == 'on');
     82                $syncroData->doInvoice = (isset($settings['backend']['doInvoice']) && $settings['backend']['doInvoice'] == 'on');
     83                $syncroData->typeOfInvoice = $settings['backend']['typeOfInvoice'] ?? null;
     84                $syncroData->typeOf_EU_Invoice = $settings['backend']['typeOf_EU_Invoice'] ?? null;
     85                $syncroData->toSignInvoice = (isset($settings['backend']['toSignInvoice']) && $settings['backend']['toSignInvoice'] == 'on');
     86                $syncroData->fieldNif = $settings['backend']['fieldNif'] ?? null;
     87                $syncroData->includeTaxonSendCost = $settings['backend']['includeTaxonSendCost'] ?? null;
     88                $syncroData->createExemptPT = (isset($settings['backend']['createExemptPT']) && $settings['backend']['createExemptPT'] == 'on');
     89                $syncroData->createExemptEU = (isset($settings['backend']['createExemptEU']) && $settings['backend']['createExemptEU'] == 'on');
     90                $syncroData->createExemptCO = (isset($settings['backend']['createExemptCO']) && $settings['backend']['createExemptCO'] == 'on');
     91                $syncroData->typeOfCountry = $settings['backend']['typeOfCountry'] ?? null;
     92                $syncroData->typeOfReason = $settings['backend']['typeOfReason'] ?? null;
     93                $syncroData->typeOfReasonEU = $settings['backend']['typeOfReasonEU'] ?? null;
     94                $syncroData->typeOfReasonCO = $settings['backend']['typeOfReasonCO'] ?? null;
     95                $syncroData->doOrder = (isset($settings['backend']['doOrder']) && $settings['backend']['doOrder'] == 'on');
     96                $syncroData->warehouseOrder = $settings['backend']['warehouseOrder'] ?? null;
     97                $syncroData->typeOfOrder = $settings['backend']['typeOfOrder'] ?? null;
     98                $syncroData->toSignOrder = (isset($settings['backend']['toSignOrder']) && $settings['backend']['toSignOrder'] == 'on');
     99                $syncroData->numberOfOrder = $settings['backend']['numberOfOrder'] ?? null;
     100                $syncroData->statusOfOrder = $settings['backend']['statusOfOrder'] ?? null;
     101                $syncroData->shippingName = $settings['backend']['shippingName'] ?? null;
     102                $syncroData->feesName = $settings['backend']['feesName'] ?? null;
     103                $syncroData->manageStock = (isset($settings['backend']['manageStock']) && $settings['backend']['manageStock'] == 'on');
     104                $syncroData->productPriceColumn = $preco;
     105                $syncroData->warehouse = $settings['backend']['warehouse'] ?? null;
     106                $syncroData->sendInvoice = $settings['backend']['sendInvoice'] ?? null;
     107                $syncroData->typeOfReport = $settings['backend']['typeOfReport'] ?? null; 
     108                     
    122109            /*******************************************************************
    123             *                 --- settings backend Data  ---                   *
    124             ********************************************************************/
    125                 $syncroData->createInvoice = (isset($settings['backend']['createInvoice']) && $settings['backend']['createInvoice'] == 'on') ? true : false;           
    126                 $syncroData->doInvoice = (isset($settings['backend']['doInvoice']) && $settings['backend']['doInvoice'] == 'on') ? true : false;
    127                 $syncroData->typeOfInvoice = (isset($settings['backend']['typeOfInvoice'])) ? $settings['backend']['typeOfInvoice'] : null;
    128                 $syncroData->typeOf_EU_Invoice = (isset($settings['backend']['typeOf_EU_Invoice'])) ? $settings['backend']['typeOf_EU_Invoice'] : null;
    129                 $syncroData->toSignInvoice = (isset($settings['backend']['toSignInvoice']) && $settings['backend']['toSignInvoice'] == 'on') ? true : false;
    130                 $syncroData->fieldNif = isset($settings['backend']['fieldNif']) ? $settings['backend']['fieldNif'] : null;
    131                 $syncroData->includeTaxonSendCost = isset($settings['backend']['includeTaxonSendCost']) ? $settings['backend']['includeTaxonSendCost'] : null;
    132                 $syncroData->createExemptPT = (isset($settings['backend']['createExemptPT']) && $settings['backend']['createExemptPT'] == 'on') ? true : false;
    133                 $syncroData->createExemptEU = (isset($settings['backend']['createExemptEU']) && $settings['backend']['createExemptEU'] == 'on') ? true : false;
    134                 $syncroData->createExemptCO = (isset($settings['backend']['createExemptCO']) && $settings['backend']['createExemptCO'] == 'on') ? true : false;
    135                 $syncroData->typeOfCountry = isset($settings['backend']['typeOfCountry']) ? $settings['backend']['typeOfCountry'] : null;
    136                 $syncroData->typeOfReason = isset($settings['backend']['typeOfReason']) ? $settings['backend']['typeOfReason'] : null;
    137                 $syncroData->typeOfReasonEU = isset($settings['backend']['typeOfReasonEU']) ? $settings['backend']['typeOfReasonEU'] : null;
    138                 $syncroData->typeOfReasonCO = isset($settings['backend']['typeOfReasonCO']) ? $settings['backend']['typeOfReasonCO'] : null;
    139                 $syncroData->doOrder = (isset($settings['backend']['doOrder']) && $settings['backend']['doOrder'] == 'on') ? true : false;
    140                 $syncroData->warehouseOrder = isset($settings['backend']['warehouseOrder']) ? $settings['backend']['warehouseOrder'] : null;
    141                 $syncroData->typeOfOrder = isset($settings['backend']['typeOfOrder']) ? $settings['backend']['typeOfOrder'] : null;
    142                 $syncroData->toSignOrder = (isset($settings['backend']['toSignOrder']) && $settings['backend']['toSignOrder'] == 'on') ? true : false;
    143                 $syncroData->numberOfOrder = isset($settings['backend']['numberOfOrder']) ? $settings['backend']['numberOfOrder'] : null;
    144                 $syncroData->statusOfOrder = isset($settings['backend']['statusOfOrder']) ? $settings['backend']['statusOfOrder'] : null;
    145                 $syncroData->shippingName = isset($settings['backend']['shippingName']) ? $settings['backend']['shippingName'] : null;
    146                 $syncroData->feesName = isset($settings['backend']['feesName']) ? $settings['backend']['feesName'] : null;
    147                 $syncroData->manageStock = (isset($settings['backend']['manageStock']) && $settings['backend']['manageStock'] == 'on') ? true : false;
    148                 $syncroData->productPriceColumn = isset($settings['backend']['productPriceColumn']) ? $preco : null;
    149                 $syncroData->warehouse = isset($settings['backend']['warehouse']) ? $settings['backend']['warehouse'] : null;
    150                 $syncroData->sendInvoice = isset($settings['backend']['sendInvoice']) ? $settings['backend']['sendInvoice'] : null;
    151                 $syncroData->typeOfReport = isset($settings['backend']['typeOfReport']) ? $settings['backend']['typeOfReport'] : null;
    152 
    153             /*******************************************************************
    154             *                   --- Company/Users Data  ---                    *
    155             ********************************************************************/
    156                 // Obtain customer ID to obtain email in Woocommerce Users
    157                 global $wpdb;
    158                 $table_name = $wpdb->prefix."users";
    159                 // Obtain next post_id of order in MySQL
    160                 $query = "SELECT user_email FROM %s WHERE id = %d";
    161                 $docid = $wpdb->get_results(str_replace("'", "", $wpdb->prepare($query, $table_name, sanitize_text_field($syncroData->customer_user))));
    162                 // set user enail
    163                 $syncroData->user_email = empty($docid) ? "" : $docid[0]->user_email;
    164 
    165                 #Get POST Id for current order
    166                 global $wpdb;
    167                 $table_name = $wpdb->prefix."postmeta";
    168                 //Obtain post_id of order in MySQL
    169                 $query = "SELECT MAX(post_id) as postId FROM %s";
    170                 $post_docid = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name)));
    171                 //Post Id
    172                 $syncroData->post_ID = sanitize_text_field($post_docid->postId);
    173 
    174                 if($syncroData->post_ID == ''){$post_ID = sanitize_text_field($order_id);}
    175 
    176                 //Obtain doc ID based in order
    177                 $docid = get_post_meta($order_id);
    178 
    179                 $syncroData->docId = isset($docid['_docid'][0]) ? $docid['_docid'][0] : null;           
     110            *                       --- Billing data  ---                      *
     111            ********************************************************************/                           
     112                // Create order object             
     113                $order = wc_get_order($order_id);
     114                //$this->logs->writeFileLog('order', $order);
     115           
     116                if ($order) {
     117                    $syncroData->billing_country = $order->get_billing_country();
     118                    $syncroData->billing_first_name = $order->get_billing_first_name();
     119                    $syncroData->billing_last_name = $order->get_billing_last_name();
     120                    $syncroData->billing_address = $order->get_billing_address_1();
     121                    $syncroData->billing_city = $order->get_billing_city();
     122                    $syncroData->billing_postcode = $order->get_billing_postcode();
     123                    $syncroData->billing_nif = $order->get_meta($bill_nifName);
     124                    $syncroData->billing_email = $order->get_billing_email();
     125                    $syncroData->billing_phone = $order->get_billing_phone();
     126
     127                    // Customer data on shipment
     128                    $syncroData->shipping_country = $order->get_shipping_country();
     129                    $syncroData->shipping_cl_first_name = $order->get_shipping_first_name();
     130                    $syncroData->shipping_cl_last_name = $order->get_shipping_last_name();
     131                    $syncroData->shipping_address = $order->get_shipping_address_1();
     132                    $syncroData->shipping_city = $order->get_shipping_city();
     133                    $syncroData->shipping_postcode = $order->get_shipping_postcode();
     134                    $syncroData->shipping_cl_nif = $order->get_meta($ship_nifName);   
     135                   
     136                    // Obtain user email
     137                    $user = $order->get_user();
     138                    $syncroData->user_email = $user ? $user->user_email : ''; 
     139
     140                    // Get tax country
     141                    $tax_rate_id = '';
     142                    foreach($order->get_items('tax') as $item_id => $item ) {
     143                        $tax_rate_id = $item->get_rate_id(); // Tax rate ID
     144                    }
     145                   
     146                    $syncroData->taxCountry = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_country FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_id=%d LIMIT 1", $tax_rate_id ) );
     147       
     148                    // Other data
     149                    $syncroData->post_ID = $order->get_id();
     150                    $syncroData->docId = $order->get_meta('_docid');
     151                    $syncroData->statusOrder = $order->get_status();
     152                    $syncroData->obs = $order->get_customer_note();
     153                } else {
     154                    # Alternative way to get the billing data                 
     155                    $order_meta = get_post_meta($order_id);
     156                    //$this->logs->writeFileLog('order_meta', $order_meta);
     157
     158                    if (!$order_meta) {
     159                        $this->logs->writeFileLog('syncro_error_002:', "Order data is missing");
     160                    }
     161                                 
     162                    $syncroData->billing_country = !empty($order_meta['_billing_country'][0]) ? $order_meta['_billing_country'][0] : sanitize_text_field($_REQUEST['_billing_country']);             
     163                    $syncroData->billing_first_name = $order_meta['_billing_first_name'][0];
     164                    $syncroData->billing_last_name = $order_meta['_billing_last_name'][0];
     165
     166                    $syncroData->billing_address = $order_meta['_billing_address_1'][0];
     167                    $syncroData->billing_city = $order_meta['_billing_city'][0];
     168                    $syncroData->billing_postcode = $order_meta['_billing_postcode'][0];
     169                    $syncroData->billing_nif = $order_meta['_billing_'.$settings['backend']['fieldNif']][0];
     170                    $syncroData->billing_email = $order_meta['_billing_email'][0];
     171                    $syncroData->billing_phone = $order_meta['_billing_phone'][0];
     172
     173                    // Customer data on shipment
     174                    $syncroData->shipping_country = $order_meta['_shipping_country'][0];
     175                    $syncroData->shipping_cl_first_name = $order_meta['_shipping_first_name'][0];
     176                    $syncroData->shipping_cl_last_name = $order_meta['_shipping_last_name'][0];
     177                    $syncroData->shipping_address = $order_meta['_shipping_address_1'][0];
     178                    $syncroData->shipping_city = $order_meta['_shipping_city'][0];
     179                    $syncroData->shipping_postcode = $order_meta['_shipping_postcode'][0];
     180                    $syncroData->shipping_cl_nif = $order_meta['_shipping_'.$settings['backend']['fieldNif']][0];
     181                   
     182                    // Get User
     183                    $syncroData->customer_user = $order_meta['_customer_user'][0];                   
     184                    $table_name = $wpdb->prefix."users";
     185                    // Obtain next post_id of order in MySQL
     186                    $query = "SELECT user_email FROM %s WHERE id = %d";
     187                    $docid = $wpdb->get_results(str_replace("'", "", $wpdb->prepare($query, $table_name, sanitize_text_field($syncroData->customer_user))));
     188                    // Get user email
     189                    $syncroData->user_email = empty($docid) ? "" : $docid[0]->user_email;
     190                                       
     191                    // Get the tax_country
     192                    $tax_rate_id = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM ".$wpdb->prefix."woocommerce_order_itemmeta WHERE meta_key='rate_id' ORDER BY order_item_id DESC  LIMIT 1" ) );
     193                    $syncroData->taxCountry  = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_country FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_id='".$tax_rate_id."' LIMIT 1" ) );
     194                }
     195       
     196                # Store data
    180197                $syncroData->orderId = sanitize_text_field($order_id);
    181 
    182                 #Customer notes
    183                 $syncroData->obs = isset($_REQUEST['order_comments']) ? $_REQUEST['order_comments'] : null;   
    184                 #Get Currency from woocommerce
    185198                $syncroData->wooCurrency = get_option('woocommerce_currency');
    186                 #get order received endpoint from woocommerce
    187199                $syncroData->order_received = get_option('woocommerce_checkout_order_received_endpoint');
    188                 #get company country from woocommerce
    189200                $syncroData->companyCountry = WC()->countries->countries[WC()->countries->get_base_country()];
    190                
    191                 # Get order data
    192                 $order = new WC_Order($order_id);
    193                
    194                 #get order tax rate country
    195                 foreach($order->get_items('tax') as $item_id => $item ) {
    196                     $tax_rate_id = $item->get_rate_id(); // Tax rate ID               
    197                 }
    198                 $syncroData->taxCountry = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_country FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_id='".$tax_rate_id."' LIMIT 1" ) );
    199                
    200                 //get status of order atualizated
    201                 $syncroData->statusOrder = $order->get_status();
    202 
    203             /*******************************************************************
    204             *               --- Alternative select Data  ---                   *
    205             ********************************************************************/
    206 
    207                /* if some data is not received from webhook or order object
    208                        here we fount alternative methods (like for create invoice process)*/
    209 
    210                 #nextPostId
    211                 global $wpdb;
    212                 $table_name = $wpdb->prefix."postmeta";
    213                 //Obtain next post_id of order in MySQL
    214                 $query = "SELECT MAX(post_id) as nextPostId FROM %s";
    215                 $packDocId = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name)));
    216 
    217                 //Save nextPostId
    218                 $syncroData->nextPostId = $packDocId->nextPostId;
    219 
    220                 if(empty($raw_order)){
    221                     #get alternative stdClass Object data
    222                     $table = $wpdb->prefix . 'postmeta';
    223                     $sql = 'SELECT * FROM `'. $table . '` WHERE post_id = '. $syncroData->nextPostId;
    224                     $resultStdClass = $wpdb->get_results($sql);
    225                     //$this->logs->writeFileLog('resultStdClass', $resultStdClass);
    226 
    227                     foreach($resultStdClass as $res) {
    228                         if(empty($syncroData->billing_email)) {
    229                             if( $res->meta_key == '_billing_email'){
    230                                 $syncroData->billing_email = $res->meta_value; // get customer email
    231                             }
    232                         }
    233                         if(empty($syncroData->ft_nifName)) {
    234                             if( $res->meta_key == $ft_nifName){
    235                                 $syncroData->ft_nifName = $res->meta_value; // get customer nif
    236                             }
    237                         }
    238                         if(empty($syncroData->billing_address_1)) {
    239                             if( $res->meta_key == '_billing_address_1'){
    240                                 $syncroData->billing_address_1 = $res->meta_value; // get customer address
    241                             }
    242                         }
    243                         if(empty($syncroData->billing_first_name)) {
    244                             if( $res->meta_key == '_billing_first_name'){
    245                                 $syncroData->billing_first_name = $res->meta_value; // get customer name
    246                             }
    247                         }
    248                         if(empty($syncroData->billing_last_name)) {
    249                             if( $res->meta_key == '_billing_last_name'){
    250                                 $syncroData->billing_last_name = $res->meta_value; // get customer surname
    251                             }
    252                         }
    253                     }
    254                 }
    255 
     201                                   
    256202            /*******************************************************************
    257203            *                  --- Order Shipping Data  ---                     *
    258             ********************************************************************/
    259 
     204            ********************************************************************/       
    260205                # shipping data (Queries)
    261206                $table_name = $wpdb->prefix."woocommerce_order_items";
    262207                $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type = 'shipping'";
    263208                $resultShipping = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $order_id)));             
    264              
     209           
    265210                //get tax value for shipping
    266211                $table_name = $wpdb->prefix."woocommerce_order_itemmeta";
     
    311256                    $this->logs->writeFileLog('Warning', 'Without shipping tax');
    312257                }
    313              
     258           
    314259                if(isset($resultDB)) {
    315260                    if($settings['backend']['includeTaxonSendCost']=="true"){
     
    325270                $syncroData->post_title = isset( $post->post_title ) ? $post->post_title : '';
    326271                $syncroData->edescc = isset( WC()->cart->coupon_discount_amounts['saco'] ) ? WC()->cart->coupon_discount_amounts['saco'] : 0;
    327 
    328272            /*******************************************************************
    329273            *                    --- Order Fees Data  ---                      *
    330274            ********************************************************************/
    331                 //build common object
    332                 $boFeesPack = new stdClass();
    333275                $bofees = [];
    334 
    335                 $the_order = wc_get_order($order_id);
    336 
    337                 if(!empty($the_order)){
    338                     // Iterating through order fee items ONLY
    339                     foreach( $the_order->get_items('fee') as $item_id => $item_fee){
    340 
    341                         // The fee name
    342                         $fee_name = $item_fee->get_name();
    343                    
    344                         // The fee total amount
    345                         $fee_total = $item_fee->get_total();
    346                    
    347                         // The fee total tax amount
    348                         $fee_total_tax = $item_fee->get_total_tax();
    349                    
    350                         array_push($bofees,[
    351                             'name' =>  $fee_name,
    352                             'value' =>  $fee_total,
    353                             'tax_value' => $fee_total_tax
    354                         ]);
    355                     }
    356                 }
    357            
    358                 $boFeesPack = $bofees;
    359                 $syncroData->fees_bo = $boFeesPack;
    360 
    361                 # Fetch fees data
    362 
    363                 if(isset($resultFee)) {
    364                     $syncroData->fee_name = $resultFee->order_item_name;
    365                 }
    366                 if(isset($resultFeeValue)) {
    367                     $syncroData->fee_value = $resultFeeValue->meta_value;
    368                 }
    369 
    370             /*******************************************************************
    371             *                      --- Invoice Data  ---                       *
    372             ********************************************************************/
    373                 #get country for Ft
    374                 $order_meta = get_post_meta($order_id);
    375                 //$this->logs->writeFileLog('order_meta', $order_meta);
    376              
    377                 $syncroData->$bill_country_ft = isset( $order_meta['_billing_country'][0] ) ? $order_meta['_billing_country'][0] : '';
    378                 if($syncroData->billing_country != ''){
    379                     $syncroData->billing_country_ft = $syncroData->billing_country;
    380                 } else {
    381                     $syncroData->billing_country_ft = sanitize_text_field( $_REQUEST['_billing_country'] );
    382                 }
    383 
    384                 #get Billing data
    385                 $syncroData->billing_first_name_ft = $order_meta['_billing_first_name'][0];
    386                 $syncroData->billing_last_name_ft = $order_meta['_billing_last_name'][0];
    387                 $syncroData->billing_email_ft = $order_meta['_billing_email'][0];
    388                 $syncroData->billing_address_1_ft = $order_meta['_billing_address_1'][0];
    389                 $syncroData->billing_city_ft = $order_meta['_billing_city'][0];
    390                 $syncroData->billing_phone_ft = $order_meta['_billing_phone'][0];
    391                 $syncroData->billing_postcode_ft = $order_meta['_billing_postcode'][0];
    392                 $syncroData->billing_nif_ft = isset($order_meta) ? $order_meta['_billing_'.$settings['backend']['fieldNif']][0] : '';
    393          
    394             /*******************************************************************
    395             *                 --- Invoice Shipping Data  ---                   *
    396             ********************************************************************/
    397 
    398                 /* To avoid repetitive code,
    399                                    data is taken from "Order Shipping Data" */
    400 
    401             //$this->logs->writeFileLog('syncroData', $syncroData);
    402 
     276                foreach( $order->get_items('fee') as $item_id => $item_fee){
     277                    $fee_name = $item_fee->get_name();
     278                    $fee_total = $item_fee->get_total();
     279                    $fee_total_tax = $item_fee->get_total_tax();
     280                    $bofees[] = [
     281                        'name' =>  $fee_name,
     282                        'value' =>  $fee_total,
     283                        'tax_value' => $fee_total_tax
     284                    ];
     285                }
     286                $syncroData->fees_bo = $bofees;   
     287   
     288            //$this->logs->writeFileLog('syncroData', $syncroData);     
    403289            return $syncroData;
    404         }
    405 
     290        } 
    406291    /******************************************************************
    407292    *                   ---  Order Cart Data ---                      *
     
    414299            $products = [];
    415300            $cart_contents = WC()->cart->cart_contents;
    416 
    417            // $this->logs->writeFileLog('cart_contents', $cart_contents);
     301            //$this->logs->writeFileLog('cart_contents', $cart_contents);
    418302
    419303            if (is_array($cart_contents)){
     
    775659            return $ftProducts;
    776660        }
    777 
    778 
    779 
    780661    /******************************************************************
    781662    *                    ---  Object PackData ---                     *
     
    831712                $bill->nome = $wooOrder->billing_first_name. " " .$wooOrder->billing_last_name;
    832713                $bill->email = $wooOrder->billing_email;
    833                 $bill->morada = $wooOrder->billing_address_1;
     714                $bill->morada = $wooOrder->billing_address;
    834715                $bill->local = $wooOrder->billing_city;
    835716                $bill->provincia = $wooOrder->billing_city;
    836717                $bill->telefone = $wooOrder->billing_phone;
    837718                $bill->codpost = $wooOrder->billing_postcode;
    838                 $bill->ncont = $wooOrder->ft_nifName;
     719                $bill->ncont = $wooOrder->billing_nif;
    839720
    840721            # shipping data
    841                 $shipping->cl_name = $wooOrder->shipping_first_name. " " .$wooOrder->shipping_last_name;
    842                 $shipping->ncont = $wooOrder->ship_nifName;
     722                $shipping->cl_name = $wooOrder->shipping_cl_first_name. " " .$wooOrder->shipping_cl_last_name;
     723                $shipping->ncont = $wooOrder->shipping_cl_nif;
    843724                $shipping->paisto = $wooOrder->shipping_country;
    844                 $shipping->moradato = $wooOrder->shipping_address_1;
     725                $shipping->moradato = $wooOrder->shipping_address;
    845726                $shipping->localto = $wooOrder->shipping_city;
    846727                $shipping->codpostto = $wooOrder->shipping_postcode;
     
    854735                $customer->nome = $wooOrder->billing_first_name. " " .$wooOrder->billing_last_name;
    855736                $customer->email = $wooOrder->billing_email;
    856                 $customer->morada = $wooOrder->billing_address_1;
     737                $customer->morada = $wooOrder->billing_address;
    857738                $customer->local = $wooOrder->billing_city;
    858739                $customer->provincia = $wooOrder->billing_city;
    859740                $customer->telefone = $wooOrder->billing_phone;
    860741                $customer->codpost = $wooOrder->billing_postcode;
    861                 $customer->ncont = $wooOrder->ft_nifName;
     742                $customer->ncont = $wooOrder->billing_nif;
    862743                $customer->preco = $wooOrder->productPriceColumn;
    863744                $customer->country = $wooOrder->billing_country;
     
    878759
    879760            # invoice
    880                 $ft->country = $wooOrder->billing_country_ft;
     761                $ft->country = $wooOrder->billing_country;
    881762                $ft->cart = $ftprodPack;
    882                 $ft->billing_name = $wooOrder->billing_first_name_ft. " " .$wooOrder->billing_last_name_ft;
    883                 $ft->billing_email = $wooOrder->billing_email_ft;
    884                 $ft->billing_address_1 = $wooOrder->billing_address_1_ft;
    885                 $ft->billing_city = $wooOrder->billing_city_ft;
    886                 $ft->billing_phone = $wooOrder->billing_phone_ft;
    887                 $ft->billing_postcode = $wooOrder->billing_postcode_ft;
    888                 $ft->billing_nif = $wooOrder->billing_nif_ft;
     763                $ft->billing_name = $wooOrder->billing_first_name. " " .$wooOrder->billing_last_name;
     764                $ft->billing_email = $wooOrder->billing_email;
     765                $ft->billing_address = $wooOrder->billing_address;
     766                $ft->billing_city = $wooOrder->billing_city;
     767                $ft->billing_phone = $wooOrder->billing_phone;
     768                $ft->billing_postcode = $wooOrder->billing_postcode;
     769                $ft->billing_nif = $wooOrder->billing_nif;
    889770                $ft->shipping_name = $wooOrder->shipping_name;
    890771                $ft->shipping_value = $wooOrder->shipping_value;
Note: See TracChangeset for help on using the changeset viewer.