Plugin Directory

Changeset 2633497


Ignore:
Timestamp:
11/22/2021 12:10:52 PM (4 years ago)
Author:
phcwordpress
Message:

upd 20211122

Location:
drivefx-woocommerce/trunk
Files:
6 edited

Legend:

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

    r2579467 r2633497  
    194194                            $fees = $ft->fees;
    195195
    196                             //fees
     196                            #fees
    197197                            if (isset($fees)){
    198198                                foreach ($fees as $fee) {
    199199                                    $fi= new stdClass();
    200200
    201                                     $fi->design = $fee['name'];
     201                                    if($settings->feesName != "0") {
     202                                   
     203                                        $responseSt = $this->utils_services->filterItem_Query($ch, $credentials, 'St', 'ref', $settings->feesName);
     204   
     205                                        //$this->logs->writeFileLog('ResponseST', $response);
     206   
     207                                        if(empty($responseSt)) {                                       
     208                                            //Reset Fees data like on WC
     209                                            $this->logs->writeFileLog('Warning', "We couldn't find a reference for Fees (FT), so we'll use WC data");
     210                                            $fi->ref = "";                             
     211                                            $fi->design = $fee['name'];                                     
     212                                        } else {
     213                                            //Set Service Data from PHC GO
     214                                            $fi->ref = $responseSt['result'][0]['ref'];
     215                                            $fi->design = $responseSt['result'][0]['design'];
     216   
     217                                        }
     218                                    } else {
     219                                        //Set Fees data like on WC
     220                                        $fi->ref = "";                             
     221                                        $fi->design = $fee['name'];
     222                                    }
     223
    202224                                    $fi->qtt = 1;
    203                                     $fi->etiliquido = $fi->epv = $fee['value'];
    204 
    205                                     if($settings->feesName != "") {
    206                                         $fi->ref = $settings->feesName;
    207                                     }
    208 
    209225                                    // IVA
    210226                                    if ($settings->includeTaxonSendCost == "true") {
     227                                        $fi->etiliquido = $fi->epv = $fee['value'] + $fee['tax_value'];
    211228                                        $fi->ivaincl=true;
     229                                    } else {
     230                                        $fi->etiliquido = $fi->epv = $fee['value'];
    212231                                    }
    213232                                    if ($fi->etiliquido == 0) {
     
    218237                                }
    219238                            }
    220                             //shipping
     239                           
     240                            #shipping
    221241                            if (isset($ft->shipping_name)){
    222242                                $fi= new stdClass();
    223243
    224                                 if($settings->shippingName != "") {
    225                                     $fi->ref = $settings->shippingName;
    226                                 }
     244                                if($settings->shippingName != "0") {
     245                                    $responseSt = $this->utils_services->filterItem_Query($ch, $credentials, 'St', 'ref', $settings->shippingName);
     246
     247                                    //$this->logs->writeFileLog('ResponseST', $response);
     248           
     249                                    if(empty($responseSt)) {                                       
     250                                        //Reset shipping data like on WC
     251                                        $this->logs->writeFileLog('Warning', "We couldn't find a reference for Shipping (FT), so we'll use WC data");
     252                                        $fi->ref = "";                             
     253                                        $fi->design = $ft->shipping_name;                                     
     254                                    } else {
     255                                        //Set Service Data from PHC GO
     256                                        $fi->ref = $responseSt['result'][0]['ref'];
     257                                        $fi->design = $responseSt['result'][0]['design'];
     258               
     259                                    }
     260                                } else {
     261                                    //Set shipping data like on WC
     262                                    $fi->ref = "";                                                   
     263                                    $fi->design = $ft->shipping_name;
     264                                }   
    227265
    228266                                $fi->design = $ft->shipping_name;
    229267                                $fi->qtt = 1;
     268                                $fi->etiliquido = $ft->shipping_value;
    230269
    231270                                if($settings->includeTaxonSendCost == "true") {
     
    255294                                $response['result'][0]['fis'][]= $fi;
    256295                            }
     296
     297                            #Obtain vouchers
     298                            if (isset($dataPack->vouchers)){
     299                                foreach ($dataPack->vouchers as $voucher) {
     300                                    //voucher                   
     301                                    $fi = new stdClass();
     302
     303                                    $fi->ref = "";
     304                                    if($voucher['type'] == "fixed_cart"){
     305                                        $fi->design = "Voucher: ".$voucher['code']." (".$voucher['value'].")";
     306                                    } elseif ($voucher['type'] == "percent"){
     307                                        $fi->design = "Voucher: ".$voucher['code']." (".$voucher['value']."%)";
     308                                    } else {
     309                                        $fi->design = "Voucher: ".$voucher['code'];
     310                                    }
     311                                   
     312                                    $fi->etiliquido = $fi->epv = 0;
     313                                    $fi->qtt = 0;
     314                                    $fi->ivaincl=false;
     315                                    //fulfill Fis
     316                                    $response['result'][0]['fis'][] = $fi;
     317                                   
     318                                }
     319                            }
     320
    257321                            //actEntity
    258322                            $response2 = $this->utils_services->actEntity($ch, $credentials, 'FtWS', $response);
     
    359423                                    }
    360424                                }
     425                                //Set Discount Voucher
     426                               /*  if (isset($dataPack->vouchers)){
     427                                    foreach ($dataPack->vouchers as $voucher) {
     428                                        $response['result'][0]['efinvat'] += $voucher['value'];
     429                                    }
     430                                } */
    361431
    362432                                #actEntity
  • drivefx-woocommerce/trunk/PHCLibrary/orders.php

    r2607350 r2633497  
    420420                    $this->logs->writeFileLog('addNewOrder13.1.1', $responseTaxes['messages'][0]['messageCodeLocale']);
    421421                }
    422 
    423                 #Obtain name and price of delivery
    424                 //Obtain VO with updated Bo
     422             
     423                #Obtain VO with updated Bo
    425424                foreach ($order->cart as $product) {
    426425                    //product
     
    439438                    $bi= new stdClass();
    440439
    441                     if($settings->shippingName != "") {
    442                         $bi->ref = $settings->shippingName;
    443                     }
    444 
    445                     $bi->design = $shipping->shipping_name;
     440                    if($settings->shippingName != "0") {
     441
     442                        $responseSt = $this->utils_services->filterItem_Query($ch, $credentials, 'St', 'ref', $settings->shippingName);
     443
     444                        //$this->logs->writeFileLog('ResponseST.01', $response);
     445
     446                        if(empty($responseSt)) {                                       
     447                            //Reset shipping data like on WC
     448                            $this->logs->writeFileLog('Warning', "We couldn't find a reference for Shipping, so we'll use WC data");
     449                            $bi->ref = "";                             
     450                            $bi->design = $shipping->shipping_name;                                     
     451                        } else {
     452                            //Set Service Data from PHC GO
     453                            $bi->ref = $responseSt['result'][0]['ref'];
     454                            $bi->design = $responseSt['result'][0]['design'];
     455   
     456                        }
     457                    } else {
     458                        //Set shipping data like on WC
     459                        $bi->ref = "";                                                   
     460                        $bi->design = $shipping->shipping_name;
     461                    }   
     462
    446463                    $bi->qtt = 1;
    447464                    $bi->edebito = $bi->ettdeb = $shipping->shipping_value;
     
    609626                            foreach ($fees as $fee) {
    610627                                $bi= new stdClass();
    611 
    612                                 $bi->design = $fee['name'];
     628                               
     629                                if($settings->feesName != "0") {
     630                                   
     631                                    $responseSt = $this->utils_services->filterItem_Query($ch, $credentials, 'St', 'ref', $settings->feesName);
     632
     633                                    //$this->logs->writeFileLog('ResponseST', $response);
     634
     635                                    if(empty($responseSt)) {                                       
     636                                        //Reset Fees data like on WC
     637                                        $this->logs->writeFileLog('Warning', "We couldn't find a reference for Fees, so we'll use WC data");
     638                                        $bi->ref = "";                             
     639                                        $bi->design = $fee['name'];                                     
     640                                    } else {
     641                                        //Set Service Data from PHC GO
     642                                        $bi->ref = $responseSt['result'][0]['ref'];
     643                                        $bi->design = $responseSt['result'][0]['design'];
     644
     645                                    }
     646                                } else {
     647                                    //Set Fees data like on WC
     648                                    $bi->ref = "";                             
     649                                    $bi->design = $fee['name'];
     650                                }
    613651                                $bi->qtt = 1;
    614                                 $bi->edebito = $bi->ettdeb = $fee['value'];
    615 
    616                                 if($settings->feesName != "") {
    617                                     $bi->ref = $settings->feesName;
     652                               
     653                                if($settings->includeTaxonSendCost == "true") {                           
     654                                    $bi->edebito = $bi->ettdeb = $fee['value'] + $fee['tax_value'];
     655                                    $bi->ivaincl=true;
     656                                } else {
     657                                    $bi->edebito = $bi->ettdeb = $fee['value'];
    618658                                }
    619659
     
    627667                                    }
    628668                                }
     669                           
    629670                                $response['result'][0]['bis'][]= $bi;
    630                             }
    631                         }
     671                             
     672                            }
     673                        }
     674
     675                        #Obtain vouchers
     676                        if (isset($dataPack->vouchers)){
     677                            foreach ($dataPack->vouchers as $voucher) {
     678                                //voucher                   
     679                                $bi = new stdClass();
     680
     681                                $bi->ref = "";
     682                                if($voucher['type'] == "fixed_cart"){
     683                                    $bi->design = "Voucher: ".$voucher['code']." (".$voucher['value'].")";
     684                                } elseif ($voucher['type'] == "percent"){
     685                                    $bi->design = "Voucher: ".$voucher['code']." (".$voucher['value']."%)";
     686                                } else {
     687                                    $bi->design = "Voucher: ".$voucher['code'];
     688                                }
     689                                $bi->edebito = $bi->ettdeb = 0;
     690                                $bi->qtt = 0;
     691                                $bi->ivaincl=false;
     692                                //fulfill Bis
     693                                $response['result'][0]['bis'][] = $bi;
     694                               
     695                            }
     696                        }
     697
    632698                        # Discounts
    633699                        if (isset($order->discount) && $order->discount > 0){
     
    636702
    637703                            $discount['bistamp'] = '';
    638                             if($settings->discountRef != "") {
     704                            if($settings->discountRef != 0) {
    639705                                $discount['ref'] = $settings->discountRef;
    640706                            } else {
     
    649715                            array_push($response['result'][0]['bis'], $discount);
    650716                        }
     717
    651718                        //actEntity
    652719                        $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response);
  • drivefx-woocommerce/trunk/PHCLibrary/utils.php

    r2624007 r2633497  
    214214        return $response;
    215215    }
     216
     217    /*******************************************************************
     218    *                   --- FilterItem InnerJoin ---                    *
     219    ********************************************************************/
     220                /** Quary to get Products by wharehouse **/
    216221
    217222    public function entityName_Query1($ch, $credentials, $armazem){
  • drivefx-woocommerce/trunk/class.DriveFxWoocommerce.php

    r2624007 r2633497  
    12601260            $wooOrder = $this->syncro_services->fetchOrderData($orderid);
    12611261            $prodPack = $this->syncro_services->processProducts($orderid);
    1262             $dataPack = $this->syncro_services->transformWcToPhcData($wooOrder, $prodPack, $ftprodPack);
     1262            $couponPack = $this->syncro_services->processVouchers($orderid);
     1263            $dataPack = $this->syncro_services->transformWcToPhcData($wooOrder, $prodPack, $ftprodPack, $couponPack);
    12631264            $response = $this->orders_services->processOrder($credentials, $dataPack, $this->fieldStatus);
    12641265            //add to table postmeta a key of order and stamp of internal document
     
    13841385
    13851386        //If status of order is completed (creates FT)
    1386         public function completedOrder( $order_id ){
     1387        public function completedOrder($order_id){
    13871388            $this->lockStart();
    13881389            $this->logs->writeFileLog('completedOrder', "Entrei" . $order_id);
     
    15301531            $wooOrder = $this->syncro_services->fetchOrderData($orderid);
    15311532            $ftprodPack = $this->syncro_services->processFtProducts($orderid);
    1532             $dataPack = $this->syncro_services->transformWcToPhcData($wooOrder, $prodPack, $ftprodPack);
     1533            $dataPack = $this->syncro_services->transformWcToPhcData($wooOrder, $prodPack, $ftprodPack, $couponPack);
    15331534            $response = $this->invoices_services->addInternalDocInvoice($response, $ch, $credentials, $dataPack);
    15341535
     
    15471548            $wooOrder = $this->syncro_services->fetchOrderData($orderid);
    15481549            $ftprodPack = $this->syncro_services->processFtProducts($orderid);
    1549             $dataPack = $this->syncro_services->transformWcToPhcData($wooOrder, $prodPack, $ftprodPack);
     1550            $couponPack = $this->syncro_services->processVouchers($orderid);
     1551            $dataPack = $this->syncro_services->transformWcToPhcData($wooOrder, $prodPack, $ftprodPack, $couponPack);
    15501552            $response = $this->invoices_services->addSimpleInvoice($ch, $credentials, $dataPack);
    15511553
  • drivefx-woocommerce/trunk/drivefx-woocommerce.php

    r2456862 r2633497  
    33 * Plugin Name: PHC GO WooCommerce
    44 * Description: Easy integration between Woocommerce WordPress and your PHC GO installation.
    5  * Version: 4.6.0
     5 * Version: 4.7.0
    66 * Author: PHC Software, S.A.
    77 * Author URI: https://www.phcgo.net/
  • drivefx-woocommerce/trunk/settings/syncro_gate.php

    r2607350 r2633497  
    418418                $bofees = [];
    419419
     420                $the_order = wc_get_order($order_id);
     421
     422                if(!empty($the_order)){
     423                    // Iterating through order fee items ONLY
     424                    foreach( $the_order->get_items('fee') as $item_id => $item_fee){
     425
     426                        // The fee name
     427                        $fee_name = $item_fee->get_name();
     428                   
     429                        // The fee total amount
     430                        $fee_total = $item_fee->get_total();
     431                   
     432                        // The fee total tax amount
     433                        $fee_total_tax = $item_fee->get_total_tax();
     434                   
     435                        array_push($bofees,[
     436                            'name' =>  $fee_name,
     437                            'value' =>  $fee_total,
     438                            'tax_value' => $fee_total_tax
     439                        ]);
     440                    }
     441                }
     442     
    420443                # fees data (Queries)
    421444
    422445                //get fee from mysql
    423                 $table_name = $wpdb->prefix."woocommerce_order_items";
     446               /* $table_name = $wpdb->prefix."woocommerce_order_items";
    424447                $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type = 'fee'";
    425448                $resultsFee_bo = $wpdb->get_results(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $packDocId->nextPostId)));
     
    440463                ]);
    441464
    442                 }
     465                } */
    443466                $boFeesPack = $bofees;
    444467                $syncroData->fees_bo = $boFeesPack;
     
    495518
    496519                //Obtain id of order and products
    497                 $order = new WC_Order($orderid);
     520              /*   $order = new WC_Order($orderid);
    498521                $orderPostId = $order->post->ID;
    499522                //build common object
     
    525548
    526549                $addPack = $fees;
    527                 $syncroData->fees_ft = $addPack;
     550                $syncroData->fees_ft = $addPack; */
    528551
    529552            //$this->logs->writeFileLog('syncroData', $syncroData);
     
    540563
    541564            $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME);
    542 
    543565            $prodPack = new stdClass();
    544 
    545566            $products = [];
    546567            $cart_contents = WC()->cart->cart_contents;
     
    548569            if (is_array($cart_contents)){
    549570                foreach (WC()->cart->cart_contents as $key => $value){
     571                 
    550572                    //Obtain info about products in cart
    551573                    $productData = WC()->cart->cart_contents[$key];
     574
     575                    //$this->logs->writeFileLog('productData', $productData);
    552576
    553577                    //obtain reference items in cart
     
    573597                    ]);
    574598                }
    575             // $this->logs->writeFileLog('products_1', $products);
     599             //$this->logs->writeFileLog('products_1', $products);
    576600            }
    577601
     
    697721            return $products;
    698722        }
    699 
     723    /*******************************************************************
     724    *                       --- Vouchers Data  ---                     *
     725    ********************************************************************/ 
     726        public function processVouchers($orderid) {
     727
     728            $vouchers = [];   
     729            if(!empty($orderid)){       
     730                $coupons_codes = wc_get_order($orderid)->get_used_coupons();
     731                // get vouchers code
     732                if (is_array($coupons_codes)){
     733                    foreach($coupons_codes as $coupon_code){
     734                       
     735                        $coupon_post_obj = get_page_by_title($coupon_code, OBJECT, 'shop_coupon');
     736                        $coupon_id = $coupon_post_obj->ID;
     737       
     738                        //Get an instance of WC_Coupon object in an array
     739                        $coupon = new WC_Coupon($coupon_id);
     740                        $coupon_amount = $coupon->get_amount();
     741                        $coupon_type = $coupon->get_discount_type();
     742
     743                        if(!empty($coupon_code)){
     744                            $voucherCode = $coupon_code;
     745                        }
     746                        array_push($vouchers, [
     747                            'code' => $voucherCode,
     748                            'value' => $coupon_amount,
     749                            'type' => $coupon_type                 
     750                        ]);               
     751                    }
     752                }
     753            }
     754            //$this->logs->writeFileLog('voucher', $vouchers);
     755
     756            return $vouchers;
     757        }
    700758    /*******************************************************************
    701759    *                   ---  Invoice Cart Data ---                     *
     
    859917    *                    ---  Object PackData ---                       *
    860918    ********************************************************************/
    861         public function transformWcToPhcData($wooOrder, $prodPack, $ftprodPack) {
     919        public function transformWcToPhcData($wooOrder, $prodPack, $ftprodPack, $couponPack) {
    862920
    863921            $dataPack = new stdClass();
     
    870928            $order = new Order();
    871929            $ft = new Invoice();
     930            $vouchers = new stdClass();
    872931
    873932            #settings data
     
    9661025            $ft->shipping_taxValue = $wooOrder->shipping_taxValue;
    9671026            $ft->shipping_tax = $wooOrder->shipping_tax;
    968             $ft->fees = $wooOrder->fees_ft;
     1027            //$ft->fees = $wooOrder->fees_ft;
     1028            $ft->fees = $wooOrder->fees_bo;
     1029
     1030            $vouchers = $couponPack;
    9691031
    9701032
     
    9791041            $dataPack->order = $order;
    9801042            $dataPack->ft = $ft;
    981 
    982             //$this->logs->writeFileLog('dataPack', $dataPack);
     1043            $dataPack->vouchers = $vouchers;
     1044
     1045            // $this->logs->writeFileLog('dataPack', $dataPack);
    9831046
    9841047            return $dataPack;
Note: See TracChangeset for help on using the changeset viewer.