Plugin Directory

Changeset 2917680


Ignore:
Timestamp:
05/26/2023 09:55:51 AM (3 years ago)
Author:
extendago
Message:

Version 1.3.3

Location:
extendago-wp-connection/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extendago-wp-connection/trunk/extendago-wp-connection.php

    r2913155 r2917680  
    44Plugin URI:  http://www.arture.nl/extendago
    55Description: The Wordpress plugin for connecting Woocommerce with Extendago / Wallmob. Manage your products inside Extendago and let our connection do the magic.
    6 Version:     1.3.2
     6Version:     1.3.3
    77Author:      Arture B.V.
    88Author URI:  https://arture.nl/
  • extendago-wp-connection/trunk/includes/admin/class-extendago-wp-connection-admin.php

    r2906999 r2917680  
    646646                $web_api = new ExtendaGo_Web_Api();
    647647                $extendago_shops = $web_api->listShops();
     648
    648649                if ( ! isset( $extendago_shops ) || empty( $extendago_shops ) ) {
    649650                    echo '<div class="alert alert-warning" role="alert">' . __('Extendago shops unavailable. Check connection!', 'extendago-wp-connection-plugin') . '</div>';
     
    721722    public function display_extendago_tax_rates_element(){
    722723
    723         global $woocommerce;
    724 
    725724        if ( class_exists( 'WooCommerce' ) ) {
    726725            $extendago_api_username     = get_option( 'extendago_api_username' );
     
    738737                $tax_classes = WC_Tax::get_tax_classes(); // Retrieve all tax classes.
    739738                if ( !in_array( '', $tax_classes ) ) { // Make sure "Standard rate" (empty class name) is present.
    740                     array_unshift( $tax_classes, '' );
    741                 }
     739                    array_unshift( $tax_classes, 'null' );
     740                }
     741
    742742                foreach ( $tax_classes as $tax_class ) { // For each tax class, get all rates.
    743                     $taxes = WC_Tax::get_rates_for_tax_class( $tax_class );
     743                    $taxes = WC_Tax::get_rates_for_tax_class($tax_class);
     744
     745                    // Check for default/standaard tax class
     746                    if ($tax_class == 'null'){
     747                        $default_tax = '0';
     748                        foreach ($taxes as $default_tax_rate) {
     749                            if ($default_tax_rate->tax_rate > $default_tax) {
     750                                $default_tax = (int)$default_tax_rate->tax_rate;
     751                            }
     752                        }
     753                    }
     754
    744755                    $wc_tax_rates = array_merge( $wc_tax_rates, $taxes );
    745756                }
     
    783794                    </table>
    784795                    <div class="info"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
    785                         <?php echo __('Leave blank if you want to use the default VAT rate of Woocommerce.', 'extendago-wp-connection-plugin'); ?>
     796                        <?php echo __('Leave blank if you want to use the default VAT rate of Woocommerce: ', 'extendago-wp-connection-plugin') . $default_tax . '%'; ?>
    786797                    </div>
    787798                    <?php
  • extendago-wp-connection/trunk/includes/api/class-extendago-web-api.php

    r2906999 r2917680  
    2929            $url = $this->extendago_api_url . $request;
    3030        }
    31 
    32 //        echo '<pre>';
    33 //        print_r($url . ' | ' .$method);
    34 //        echo '<pre>';
    3531
    3632        curl_setopt($ch, CURLOPT_URL, $url);
     
    236232    }
    237233
    238     public function listStockChanges( $params = array() ) {
    239         $Offset = 0;
    240         $Limit = 250;
    241         $HasMore = true;
    242         $StockChanges = array();
    243         while ($HasMore) {
    244             $HasMore = false;
    245             $Results = $this->CurlRequest("/stock_events", "GET", array("limit" => $Limit, "offset" => $Offset));
    246             foreach ($Results as $Result) {
    247                 if (isset($Result['id'])) {
    248                     $StockChanges[] = $Result;
    249                 }
    250             }
    251             if (count($Results) == $Limit) {
    252                 $HasMore = true;
    253                 $Offset += $Limit;
    254             }
    255         }
     234    public function listStockChanges() {
     235
     236        $last_processed_time = get_option('last_processed_time');
     237        if( isset($last_processed_time) ){
     238            $StockChanges = $this->CurlRequest("/stock_events", "GET", array("filters" => json_encode(array(array('property' =>'timestamp', 'comparator' => '>', 'value' => $last_processed_time)))));
     239        }
     240        else{
     241            $StockChanges = $this->CurlRequest("/stock_events", "GET", array("filters" => json_encode(array(array('property' =>'timestamp', 'comparator' => '>', 'value' => time())))));
     242        }
     243
    256244        return $StockChanges;
    257245    }
  • extendago-wp-connection/trunk/includes/cronjob/class-extendago-cronjob-functions.php

    r2913183 r2917680  
    580580                require_once(__DIR__ . "/../api/class-extendago-web-api.php");
    581581                $Extendago = new Extendago_Web_Api();
     582
     583                // Reason code Count is needed for stock_events and the ID is different foreach client :(
     584                $reason_code_id = get_option( "reason_code_id" );
     585                if( !isset($reason_code_id) || empty($reason_code_id) ) {
     586
     587                    $reason_codes = $Extendago->CurlRequest('/reason_codes', 'GET');
     588                    foreach( $reason_codes as $reason_code ){
     589
     590                        if( $reason_code['name'] == 'Count' ){
     591                            update_option('reason_code_id', $reason_code['id']);
     592                            $reason_code_id = $reason_code['id'];
     593                            break;
     594                        }
     595                    }
     596                }
    582597
    583598                $stock_location = get_option( "extendago_location_id" );
     
    830845                        }
    831846
     847                        $stock_value = array(
     848                            'type_id'               => '102', // Production
     849                            'description'           => 'extendago_connect',
     850                            'timestamp'             => (string)time(),
     851                            'stock_location_id'     => $stock_location,
     852                            'reason_code_id'        => $reason_code_id, // Count
     853                        );
     854
    832855                        // Set stock values
    833856                        if( isset($product['variations']) && !empty($product['variations']) ) {
    834857                            foreach ($ProductResponse['product_variants'] as $index => $product_variant) {
    835858                                $variation = $product['variations'][$index];
     859
    836860                                $Response = $Extendago->CurlRequest('/stock_values?filter-product_variant_id='.$product_variant['id'], 'GET');
    837                                 $stock_value = array(
    838                                     'id'                    => 'stock_value-'.$product_variant['id'],
    839                                     'quantity'              => $variation->stock,
    840                                     'product_id'            => $product['id'],
    841                                     'product_variant_id'    => $product_variant['id'],
    842                                     'stock_location_id'     => $stock_location
    843                                 );
     861
     862                                $stock_value['reference_id'] = 'UpdateStock - webshop';
     863                                $stock_value['stock_event_lines'] = json_encode( array( array(
     864                                        'current_quantity'      => $variation->stock,
     865                                        'product_id'            => $product['id'],
     866                                        'product_variant_id'    => $product_variant['id'],
     867                                        'name'                  => $product_variant['title'],
     868                                        'sku'                   => $product_variant['sku'],
     869                                    )
     870                                ));
    844871
    845872                                if( !isset($variation->stock) || empty($variation->stock) ) {
    846873                                    $this->logging->log_file_write('EXPORT | Product variation ID ' . $product_variant['id'] . ' has no stock value!');
    847874                                }
    848                                 else{
    849                                     $this->logging->log_file_write('EXPORT | Product variation ID ' . $product_variant['id'] . ' updated to stock: ' . $variation->stock);
    850                                 }
    851 
    852                                 if( empty($Response) || isset($Response['error']) ){
    853                                     $Response = $Extendago->CurlRequest('/stock_values', 'POST', $stock_value, false, true);
    854                                     update_post_meta( $variation->id, 'extendago_size_id', $product_variant['id']);
    855                                 }
    856                                 else{
    857                                     $Response = $Extendago->CurlRequest('/stock_values/' . $Response[0]['id'], 'PATCH', $stock_value, false, true);
     875                                else {
     876
     877                                    if( !empty($Response) ){
     878                                        if( isset($Response[0]['quantity']) && $Response[0]['quantity'] != $product['quantity'] ){
     879                                            $Response = $Extendago->CurlRequest('/count_stock', 'POST', $stock_value, false, true);
     880                                            $this->logging->log_file_write('EXPORT | Product variation ID ' .$product_variant['id']. ' updated to stock: ' .$variation->stock);
     881                                        }
     882                                    }
     883                                    else{
     884                                        $Response = $Extendago->CurlRequest('/count_stock', 'POST', $stock_value, false, true);
     885                                        $this->logging->log_file_write('EXPORT | Product variation ID ' .$product_variant['id']. ' set stock: ' .$variation->stock);
     886                                    }
    858887                                }
    859888                             }
     
    861890                        else{
    862891                            $Response = $Extendago->CurlRequest('/stock_values?filter-product_id='.$product['id'], 'GET');
    863                             $stock_value = array(
    864                                 'id'                    => 'stock_value-'.$product['id'],
    865                                 'quantity'              => $product['quantity'],
    866                                 'product_id'            => $product['id'],
    867                                 'stock_location_id'     => $stock_location
    868                             );
    869 
    870                             $this->logging->log_file_write('EXPORT | Product ID ' .$product['id']. ' updated to stock: ' .$product['quantity']);
    871 
    872                             if( empty($Response) || isset($Response['error']) ){
    873                                 $Response = $Extendago->CurlRequest('/stock_values', 'POST', $stock_value, false, true);
     892
     893                            $stock_value['reference_id'] = 'UpdateStock - webshop';
     894                            $stock_value['stock_event_lines'] = json_encode( array( array(
     895                                    'current_quantity'      => (string)$product['quantity'],
     896                                    'product_id'            => (string)$product['id'],
     897                                    'product_variant_id'    => null,
     898                                    'name'                  => $product['title'],
     899                                    'sku'                   => (string)$product['sku'],
     900                                )
     901                            ) );
     902
     903                            if( !empty($Response) ){
     904                                if( isset($Response[0]['quantity']) && $Response[0]['quantity'] != $product['quantity'] ){
     905                                    $Response = $Extendago->CurlRequest('/count_stock', 'POST', $stock_value, false, true);
     906                                    $this->logging->log_file_write('EXPORT | Product ID ' .$product['id']. ' updated to stock: ' .$product['quantity']);
     907                                }
    874908                            }
    875909                            else{
    876                                 $Response = $Extendago->CurlRequest('/stock_values/' . $Response[0]['id'], 'PATCH', $stock_value, false, true);
     910                                $Response = $Extendago->CurlRequest('/count_stock', 'POST', $stock_value, false, true);
     911                                $this->logging->log_file_write('EXPORT | Product ID ' .$product['id']. ' set stock: ' .$product['quantity']);
    877912                            }
    878913                        }
     
    882917
    883918                            update_post_meta($product['id'], 'extendago_product_id', $ProductResponse['id']);
     919                            update_post_meta( $product['id'], 'latest_update', date('Y-m-d h:i') );
    884920
    885921                            // Save changes to temp dir
     
    13521388                foreach ( $stock_change['stock_event_lines'] as $stock_event_line ) {
    13531389
    1354                     if( $stock_event_line['stock_event_lines']['name'] == 'CountStock of product' ){
     1390                    if( $stock_event_line['name'] == 'CountStock of product' || $stock_change['reference_id'] == 'UpdateStock - webshop' ){
    13551391                        continue;
    13561392                    }
     
    13631399                    $api_functions->extendago_update_wc_product_stock($stock_event_line);
    13641400                }
     1401                update_option('last_processed_time', $stock_change['timestamp']);
    13651402
    13661403                // The correctly processed products should be removed from the synchronization tables
    1367                 $web_api->deleteStockChange($stock_change['id']);
    1368             }
    1369         }
    1370 
    1371         $this->logging->log_file_write( 'ExtendaGo | Synchronise stock changes completed with '.$total_sychronized_stock_changes. ' products.' );
     1404                //$web_api->deleteStockChange($stock_change['id']);
     1405            }
     1406
     1407            $this->logging->log_file_write( 'ExtendaGo | Synchronise stock changes completed with '.$total_sychronized_stock_changes. ' products.' );
     1408        }
    13721409    }
    13731410
  • extendago-wp-connection/trunk/includes/woocommerce/class-extendago-woocommerce-functions.php

    r2906999 r2917680  
    112112    {
    113113
     114        // Check for real/maula post update
     115        if( !isset($_POST) || empty($_POST) ){
     116            return;
     117        }
     118
    114119        $post = get_post($product_id);
    115120
     
    131136
    132137        $Extendago = new Extendago_Web_Api();
     138
     139        if( $product->is_taxable() && empty($product->get_tax_class()) ){
     140            $product_tax_class = 'null';
     141        }
     142        else{
     143            $product_tax_class = $product->get_tax_class();
     144        }
     145
     146        $vat_rate_id = '';
    133147        $VatRates = $Extendago->CurlRequest("/vat_rates", "GET");
    134         $vat_rate_id = '';
    135148        foreach ($VatRates as $VatRate){
    136149            $value = get_option($VatRate['id']);
    137             if( $value == $product->get_tax_class() ){
     150            if( $value == $product_tax_class ){
    138151                $vat_rate_id = $VatRate['id'];
    139152                break;
     
    153166        $product_data['vat_rate_id'] = $vat_rate_id;
    154167
    155         // Get Product Prices
    156         $product_data['price'] = $product->get_price();
    157         $product_data['regular_price'] = $product->get_regular_price();
    158         $product_data['sale_price'] = $product->get_sale_price();
     168        $woocommerce_prices_include_tax = get_option('woocommerce_prices_include_tax');
     169        $woocommerce_calc_taxes = get_option('woocommerce_calc_taxes');
     170
     171        if( $woocommerce_prices_include_tax == 'no' && $woocommerce_calc_taxes == 'yes' ){
     172            $default_tax = '0';
     173            $default_tax_rates = WC_Tax::get_rates_for_tax_class( $product_tax_class );
     174            foreach( $default_tax_rates as $default_tax_rate ){
     175                if( $default_tax_rate->tax_rate > $default_tax ){
     176                    $default_tax = (int)$default_tax_rate->tax_rate;
     177                }
     178            }
     179
     180            // Get Product Prices
     181            $product_data['price'] = ( $product->get_price() / 100 ) * ( $default_tax + 100 );
     182
     183            $product_regular_price = $product->get_regular_price();
     184            if( isset($product_regular_price) && !empty($product_regular_price) ){
     185                $product_data['regular_price'] = ( $product_regular_price / 100 ) * ( $default_tax + 100 );
     186            }
     187            else{
     188                $product_data['regular_price'] = $product_data['price'];
     189            }
     190
     191            $product_sale_price = $product->get_sale_price();
     192            if( isset($product_sale_price) && !empty($product_sale_price) ){
     193                $product_data['sale_price'] = ( $product_sale_price / 100 ) * ( $default_tax + 100 );
     194            }
     195            else {
     196                $product_data['sale_price'] = '';
     197            }
     198        }
     199        else{
     200            // Get Product Prices
     201            $product_data['price'] = $product->get_price();
     202            $product_data['regular_price'] = $product->get_regular_price();
     203            $product_data['sale_price'] = $product->get_sale_price();
     204        }
    159205
    160206        $product_attributes = $product->get_attributes();
  • extendago-wp-connection/trunk/readme.txt

    r2913155 r2917680  
    55Requires at least: 6.0
    66Tested up to: 6.1.1
    7 Stable tag: 1.3.1
     7Stable tag: 1.3.3
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    3030
    3131== Changelog ==
     32
     33= 1.3.3 =
     34* Stock flow improvements with stock events register
     35* VAT check for shops using prices withour VAT and processing inside Extenda with VAT
    3236
    3337= 1.3.2 =
Note: See TracChangeset for help on using the changeset viewer.