Plugin Directory

Changeset 3019318


Ignore:
Timestamp:
01/09/2024 01:50:48 PM (2 years ago)
Author:
extendago
Message:

Version 1.4.5

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

Legend:

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

    r2985881 r3019318  
    44Plugin URI:  http://www.arture.nl/extendago
    55Description: The Wordpress plugin for connecting Woocommerce with Extenda GO / Wallmob. You can manage your products inside Extenda GO or make your webshop as leading foor product manangement. You Stock changes will be two-way binding.
    6 Version:     1.4.4
     6Version:     1.4.5
    77Author:      Arture B.V.
    88Author URI:  https://arture.nl/
  • extendago-wp-connection/trunk/includes/admin/class-extendago-wp-connection-admin.php

    r2956645 r3019318  
    99        $extendago_api_username     = get_option( 'extendago_api_username' );
    1010        $extendago_api_password     = get_option( 'extendago_api_password' );
    11         $extendago_client_id     = get_option( 'extendago_client_id' );
    12         $extendago_client_secret     = get_option( 'extendago_client_secret' );
     11        $extendago_client_id        = get_option( 'extendago_client_id' );
     12        $extendago_client_secret    = get_option( 'extendago_client_secret' );
    1313
    1414        // Check if connection available
     
    114114        add_settings_field('extendago_location_id', esc_html(__('Stock location', 'extendago-wp-connection-plugin')),  array( $this, 'display_extendago_locations_element' ), 'extendago_woocommerce_options', 'woocommerce_section');
    115115        add_settings_field('extendago_tax_rates', 'Tax rates',  array( $this, 'display_extendago_tax_rates_element' ), 'extendago_woocommerce_options', 'woocommerce_section');
    116         add_settings_field('extendago_wc_new_order', esc_html(__('New orders', 'extendago-wp-connection-plugin')),  array( $this, 'display_extendago_wc_new_order_element' ), 'extendago_woocommerce_options', 'woocommerce_section');
     116        add_settings_field('extendago_wc_new_order', esc_html(__('Orders', 'extendago-wp-connection-plugin')),  array( $this, 'display_extendago_wc_new_order_element' ), 'extendago_woocommerce_options', 'woocommerce_section');
     117        add_settings_field('extendago_costs_field', esc_html(__('Costs field', 'extendago-wp-connection-plugin')),  array( $this, 'display_extendago_costs_field_element' ), 'extendago_woocommerce_options', 'woocommerce_section');
    117118        add_settings_field('extendago_click_and_collect', esc_html(__('Click and Collect BETA!', 'extendago-wp-connection-plugin')),  array( $this, 'display_extendago_click_and_collect_element' ), 'extendago_woocommerce_options', 'woocommerce_section');
    118119
     
    141142        register_setting('extendago_woocommerce_options', 'extendago_location_id');
    142143        register_setting('extendago_woocommerce_options', 'extendago_wc_new_order');
     144        register_setting('extendago_woocommerce_options', 'extendago_costs_field');
    143145        register_setting('extendago_woocommerce_options', 'extendago_click_and_collect');
    144146
     
    278280        echo '<li class="list-group-item"><span style="min-width: 255px; float: left;">'.__('Full sychronisation', 'extendago-wp-connection').'</span>'.esc_html($extendago_init_sync).'</li>';
    279281        echo '<li class="list-group-item"><span style="min-width: 255px; float: left;">'.__('Changes synchronisation', 'extendago-wp-connection').'</span>'.esc_html($process_product_changes).'</li>';
    280         echo '<li class="list-group-item"><span style="min-width: 255px; float: left;">'.__('Stock synchornisation', 'extendago-wp-connection').'</span>'.esc_html($process_stock_changes).'</li>';
     282        echo '<li class="list-group-item"><span style="min-width: 255px; float: left;">'.__('Stock synchronisation', 'extendago-wp-connection').'</span>'.esc_html($process_stock_changes).'</li>';
    281283        echo '</ul>';
    282284    }
     
    812814                ?>
    813815                <label class="checkbox-inline">
    814                     <input name="extendago_wc_new_order" value="1" <?php checked( '1', get_option( 'extendago_wc_new_order' ) ); ?> data-toggle="toggle" data-onstyle="success" type="checkbox"> <?php echo __( 'Enable/Disable', 'extendago-wp-connection-plugin' ); ?>
     816                    <input name="extendago_wc_new_order" value="1" <?php checked( '1', get_option( 'extendago_wc_new_order' ) ); ?> data-toggle="toggle" data-onstyle="success" type="checkbox"> <?php echo __( 'Disable/Enable', 'extendago-wp-connection-plugin' ); ?>
    815817                </label>
    816818
    817819                <div class="info"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
    818                     <?php echo __('When enabled; new paid order(s) will automatically created in ExtendaGo!', 'extendago-wp-connection-plugin'); ?>
     820                    <?php echo __('When enabled; new paid order(s) will automatically created in ExtendaGo including refund orders!', 'extendago-wp-connection-plugin'); ?>
    819821                </div>
    820822                <?php
     
    827829            echo '<div class="alert alert-warning" role="alert">' . __( 'Woocommerce not activated!', 'extendago-wp-connection-plugin' ) . '</div>';
    828830        }
     831    }
     832
     833    public function display_extendago_costs_field_element(){
     834
     835        $all_meta_keys = $this->get_all_meta_keys('product');
     836        $extendago_costs_field = get_option('extendago_costs_field');
     837        ?>
     838        <select name="extendago_costs_field">
     839            <?php
     840            echo '<option value="">Select your costs field</option>';
     841            foreach( $all_meta_keys as $meta_key ){
     842                echo '<option value="' .$meta_key. '" ' . selected($meta_key, $extendago_costs_field ) . '>' .$meta_key. '</option>';
     843            }
     844            ?>
     845        </select>
     846        <div class="info">
     847            <?php echo __('OPTIONAL: Woocommerce don\'t have any generic field for the product costs price. You can select a custom field if available to process this field into Extenda.', 'extendago-wp-connection'); ?><br/>
     848        </div>
     849        <?php
    829850    }
    830851
     
    960981    public function show_marketing_banners()
    961982    {
     983
     984        // Get the API key from the options
     985        $extendago_client_id = get_option('extendago_client_id');
     986
     987        // Check whether the saved key makes sense
     988        if( !isset($extendago_client_id) || empty($extendago_client_id) ) {
     989            $web_api = new Arture_Web_Api();
     990            $web_api->create_message("error", "IMPORTANT! You are currently using the deprecated Extenda API. We recommend updating this soon for a stable connection. Request the CLIENT ID and SECRET from your dealer and enter them in the API settings.");
     991        }
     992
    962993        $banner_showed = get_option('orderpickingapp1');
    963994        if( (isset($banner_showed) && !empty($banner_showed)) || isset($_GET['skip']) ){
     
    10091040    }
    10101041
     1042    public function get_all_meta_keys($post_type = 'post', $exclude_empty = false, $exclude_hidden = false){
     1043        global $wpdb;
     1044        $query = "
     1045        SELECT DISTINCT($wpdb->postmeta.meta_key)
     1046        FROM $wpdb->posts
     1047        LEFT JOIN $wpdb->postmeta
     1048        ON $wpdb->posts.ID = $wpdb->postmeta.post_id
     1049        WHERE $wpdb->posts.post_type = '%s'
     1050    ";
     1051        if($exclude_empty)
     1052            $query .= " AND $wpdb->postmeta.meta_key != ''";
     1053        if($exclude_hidden)
     1054            $query .= " AND $wpdb->postmeta.meta_key NOT RegExp '(^[_0-9].+$)' ";
     1055
     1056        $meta_keys = $wpdb->get_col($wpdb->prepare($query, $post_type));
     1057
     1058        return $meta_keys;
     1059    }
     1060
    10111061}
  • extendago-wp-connection/trunk/includes/api/class-arture-web-api.php

    r2930779 r3019318  
    117117    }
    118118
    119     private function create_message($status, $message) {
     119    public function create_message($status, $message) {
    120120        // Check whether the values are entered
    121121        if (isset($status) && !empty($status) && $status != '' && $status != null && isset($message) && !empty($message) && $message != '' && $message != null) {
  • extendago-wp-connection/trunk/includes/api/class-extendago-web-api-functions.php

    r2973949 r3019318  
    3636        $post_id = $this->functions->custom_get_product_id_by_sku( $product['id'], $product['sku'] );
    3737
    38         // Delete producten met de optie "Hide form web"
    3938        if(
    4039            isset($product['attributes'][1]->hide_from_web) && $product['attributes'][1]->hide_from_web == '1'
     
    357356
    358357        $product_attributes = array();
     358        $current_product_attributes = $Product->get_attributes();
     359        if( !empty($current_product_attributes) ){
     360            foreach ($current_product_attributes as $attribute_key => $current_product_attribute) {
     361                $product_attributes[str_replace('pa_', '', $attribute_key)] = $current_product_attribute;
     362            }
     363        }
    359364
    360365        // Save color as attribute
     
    417422            $product_attributes['supplier_reference'] = $Attribute;
    418423        }
    419 
    420424
    421425        // Save product variations
  • extendago-wp-connection/trunk/includes/api/class-extendago-web-api.php

    r2985881 r3019318  
    5252            );
    5353        }
     54
     55        //$Headers[] = 'Wm-Api-Version: 2';
    5456
    5557        if ($AsMultipart) $Headers[] = 'Content-Type: multipart/form-data';
  • extendago-wp-connection/trunk/includes/class-extendago-wp-connection.php

    r2941124 r3019318  
    7373        $this->loader->add_action( 'add_meta_boxes', $woocommerce, 'register_plugin_metaboxes' );
    7474
    75        add_action( 'woocommerce_product_after_variable_attributes', array($woocommerce, 'show_size_id_field_variation_data'), 10, 3 );
     75        add_action( 'woocommerce_product_after_variable_attributes', array($woocommerce, 'show_size_id_field_variation_data'), 10, 3 );
    7676
    7777        // Logging
  • extendago-wp-connection/trunk/includes/cronjob/class-extendago-cronjob-functions.php

    r2985881 r3019318  
    138138                }
    139139
    140                 // Skip producten met de optie "Hide form web"
    141                 if( isset($product['attributes'][1]['hide_from_web']) && $product['attributes'][1]['hide_from_web'] == '1' ){
    142                     $total_products = $total_products - 1;
    143                     $skip_product = true;
    144                 }
    145 
    146140                // Process only shop/group specific products
    147141                if( isset($import_shop_products) && $import_shop_products && isset($extendago_shop_group_ids) ) {
     
    243237    }
    244238
    245     public function woocommerce_extendago_sync(){
     239    public function woocommerce_extendago_sync( $product_ids = array() ){
    246240
    247241        // Upload directory
     
    282276            $args['post__in'] = array($_POST['product_id']);
    283277        }
     278        elseif( isset($product_ids) && !empty($product_ids) ) {
     279            $args['post__in'] = $product_ids;
     280        }
    284281
    285282        $products_query = new WP_Query( $args );
     
    474471        }
    475472
    476         $this->logging->log_file_write( 'EXPORT | '.$total_products .' new products exported/saved into Extendago POS' );
    477 
    478         wp_send_json_success(
    479             array(
    480                 'html' => '<div class="notice notice-success"><p>Export started with ' . $total_products . ' products. Refresh the page and check if the export is finished</p></div>'
    481             )
    482         );
     473        // Refund/Cancel products
     474        if( isset($product_ids) && !empty($product_ids) ) {
     475            $this->logging->log_file_write( 'EXPORT | '.$total_products .' products exported/saved into Extendago POS because order cancellation of refund' );
     476        }
     477        else{
     478            $this->logging->log_file_write( 'EXPORT | '.$total_products .' new products exported/saved into Extendago POS' );
     479
     480            wp_send_json_success(
     481                array(
     482                    'html' => '<div class="notice notice-success"><p>Export started with ' . $total_products . ' products. Refresh the page and check if the export is finished</p></div>'
     483                )
     484            );
     485        }
    483486    }
    484487
     
    642645               return;
    643646            }
     647
     648            $extendago_costs_field = get_option('extendago_costs_field');
    644649
    645650            natcasesort( $files );
     
    756761                        }
    757762
    758                         $ExtendagoProductJSON['product_data'] = json_encode(array(
     763                        $product_data = array(
    759764                            array(
    760765                                'id'                    => $product['id'],
     
    769774                                'unit_id'               => $unit_id
    770775                            )
    771                         ));
     776                        );
     777
     778                        // Costs of goods
     779                        if ( isset($extendago_costs_field) && !empty($extendago_costs_field) && !empty($product['cost_price']) ) {
     780                            $product_data[0]['cost_price'] = number_format(((float)$product['cost_price'] * 100), 0, '.', '');
     781                        }
     782
     783                        $ExtendagoProductJSON['product_data'] = json_encode($product_data);
    772784
    773785                        if( isset($product['variations']) && !empty($product['variations']) ) {
     
    789801                                // First variation
    790802                                if( $i == 1 ){
    791                                     $ExtendagoProductJSON['product_data'] = json_encode(array(
     803                                    $product_variation_data = array(
    792804                                        array(
    793805                                            'id'                    => $product['id'],
     
    802814                                            'unit_id'               => $unit_id
    803815                                        )
    804                                     ));
     816                                    );
     817
     818                                    $ExtendagoProductJSON['product_data'] = json_encode($product_variation_data);
    805819                                }
    806820
     
    827841                                );
    828842
     843                                // Costs of goods
     844                                if ( isset($extendago_costs_field) && !empty($extendago_costs_field) ) {
     845                                    $product_variant['product_data'][0]['cost_price'] = number_format(((float)$variation->cost_price * 100), 0, '.', '');
     846                                }
     847
    829848                                $ExtendagoProductJSON['product_variants'][] = $product_variant;
    830849                            }
     
    869888                            }
    870889                        }
    871 
    872890
    873891                        if( empty($ProductResponse) || isset($ProductResponse['error']) ){
     
    10981116
    10991117                    $this->logging->log_file_write('EXPORT | Batch finished: ' . $file);
     1118                    if (file_exists($directory . '/' . $file)) {
     1119                        $current_file_path = $directory . '/' . $file;
     1120                        $new_file_path = $directory . '/temp/' . $file;
     1121                        rename($current_file_path, $new_file_path);
     1122                    }
    11001123                }
    11011124                else{
  • extendago-wp-connection/trunk/includes/woocommerce/class-extendago-woocommerce-functions.php

    r2956645 r3019318  
    1515        add_action( 'woocommerce_process_product_meta', array($this, 'woocommerce_extendago_product_fields_save') );
    1616
    17         //add_action( 'save_post_shop_order', array($this, 'process_order_to_extendago'), 10, 3 );
     17
     18        add_action( 'woocommerce_order_status_changed', array($this, 'process_cancelled_order_products'), 10, 4 );
     19    }
     20
     21    public function process_cancelled_order_products( $order_id, $status_transition_from, $status_transition_to, $that ){
     22
     23        if(
     24            ($status_transition_from == 'processing' || $status_transition_to == 'completed')
     25            &&
     26            ($status_transition_to == 'cancelled' || $status_transition_to == 'refunded')
     27        ){
     28
     29            // Check if "New order" option is enabled
     30            $extendago_wc_new_order = get_option( 'extendago_wc_new_order' );
     31            if( (isset($extendago_wc_new_order) && $extendago_wc_new_order == '1')  ) {
     32                $this->create_extendago_new_order($order_id, true, true);
     33            }
     34        }
     35
    1836    }
    1937
     
    132150        }
    133151
     152        $extendago_costs_field = get_option('extendago_costs_field');
     153
    134154        $product = wc_get_product($product_id);
    135155
     
    170190        $product_data['vat_rate_id'] = $vat_rate_id;
    171191
     192        // Costs of goods
     193        if ( isset($extendago_costs_field) && !empty($extendago_costs_field) ) {
     194            $product_data['cost_price'] = get_post_meta($product->get_id(), $extendago_costs_field, true);
     195        }
     196
    172197        $woocommerce_prices_include_tax = get_option('woocommerce_prices_include_tax');
    173198        $woocommerce_calc_taxes = get_option('woocommerce_calc_taxes');
     
    275300                        }
    276301
    277                         $product_data['variations'][] = array(
     302                        $variant_data = array(
    278303                            'id' => $product_variation_id,
    279304                            'product_variant_name' => $product_variant_name,
     
    285310                            'vat_rate_id' => $vat_rate_id,
    286311                        );
     312
     313                        // Costs of goods
     314                        if ( isset($extendago_costs_field) && !empty($extendago_costs_field) ) {
     315                            $variant_data['cost_price'] = get_post_meta($product_variation_id, $extendago_costs_field, true);
     316                        }
     317
     318                        $product_data['variations'][] = $variant_data;
    287319                    }
    288320                }
     
    440472    }
    441473
    442     public function create_extendago_new_order( $order_id, $response = false ) {
     474    public function create_extendago_new_order( $order_id, $response = false, $refund = false ) {
    443475
    444476        // Check if "New order" option is enabled
     
    448480        $web_api = new ExtendaGo_Web_Api();
    449481
    450         if( isset($extendago_wc_new_order) && $extendago_wc_new_order == '1' ) {
     482        if( (isset($extendago_wc_new_order) && $extendago_wc_new_order == '1') || $refund ) {
    451483            $order = new WC_Order( $order_id );
    452484
    453             $logging->log_file_write('NewOrder | WebOrder status changed to: '.$order->get_status());
     485            if( $refund ){
     486                $logging->log_file_write('Refunding | WebOrder status changed to: '.$order->get_status());
     487            }
     488            else{
     489                $logging->log_file_write('NewOrder | WebOrder status changed to: '.$order->get_status());
     490            }
    454491
    455492            // Skip already processed orders
    456             $order_returned_successfully_to_extendago = get_post_meta($order_id, 'order_returned_successfully_to_extendago', true);
    457             if( $order_returned_successfully_to_extendago == '1' ) {
    458                 return '';
     493            if( !$refund ) {
     494                $order_returned_successfully_to_extendago = get_post_meta($order_id, 'order_returned_successfully_to_extendago', true);
     495                if ($order_returned_successfully_to_extendago == '1') {
     496                    return '';
     497                }
    459498            }
    460499
     
    491530                }
    492531            }
     532            elseif( $refund ){
     533                $process_order = true;
     534                $order_is_paid = true;
     535            }
    493536
    494537            if( $process_order ){
     
    507550                $data['timestamp'] = $order_date;
    508551
     552                // Use the date of today when the refuns has been made
     553                if( $refund ){
     554                    $data['timestamp'] = time();
     555                }
     556
    509557                $data['currency'] = $order->get_currency();
    510                 //$data['email'] = $order_data['billing']['email']; // Uitgeschakeld gezien deze automatisch een mail verstuurd vanuit WallMob
    511558
    512559                // Get customer by email
     
    546593                    );
    547594                    $data['customer_id'] = $web_api->createCustomer($params);
    548                     //$data['customer_name'] = $params['name'];
    549595                }
    550596
    551597                $data['is_paid'] = $order_is_paid;
     598
     599                // Compatibility for plugin "Aangepaste bestelnummers voor WooCommerce"
    552600                $data['sequence_number'] = $order_data['id'];
    553                 //$data['register_sequence_number'] = $order_data['id'];
     601                $custom_order_number = get_post_meta($order_data['id'], '_alg_wc_full_custom_order_number', true);
     602                if( isset($custom_order_number) && !empty($custom_order_number) ){
     603                    $data['sequence_number'] = $custom_order_number;
     604                }
     605
    554606                $data['is_preorder'] = true;
    555607
    556608                $regular_order_total = 0;
    557                 $discount_amount = 0;
    558609                foreach ($order->get_items() as $item_id => $item) {
    559610
     
    646697                    $order_line_item['total_line_amount'] = (int)($total_line_amount * 100 );
    647698
     699                    if( $refund ){
     700                        $order_line_item['quantity']            = '-'.$order_line_item['quantity'];
     701                        $order_line_item['vat_amount']          = '-'.$order_line_item['vat_amount'];
     702                        $order_line_item['retail_price']        = '-'.$order_line_item['retail_price'];
     703                        $order_line_item['total_line_amount']   = '-'.$order_line_item['total_line_amount'];
     704                    }
     705
    648706                    $regular_order_total += number_format($retail_price * $item_data['quantity'], 3, '.', '');
    649707                    $order_line_item['vat_rate'] = '0.' . $vat_rate; // 0021 = 21%
     
    767825                    }
    768826
     827                    if( $refund ){
     828                        $order_line_item['quantity']            = '-'.$order_line_item['quantity'];
     829                        $order_line_item['vat_amount']          = ( $order_line_item['vat_amount'] > 0 )? '-'.$order_line_item['vat_amount'] : $order_line_item['vat_amount'];
     830                        $order_line_item['retail_price']          = ( $order_line_item['retail_price'] > 0 )? '-'.$order_line_item['retail_price'] : $order_line_item['retail_price'];
     831                    }
     832
    769833                    $order_line_item['vat_rate'] = '0.' . $vat_rate; // 0021 = 21%
    770834                    $data['order_line_items'][] = $order_line_item;
     
    773837                if( $click_and_collect_order == 'no' ) {
    774838                    $currency_code = $order->get_currency();
    775                     $data['transactions'][] = array(
    776                         'order_id' => $order_id,
    777                         'type' => 'WM_TRANSACTION_TYPE_ECOMMERCE',
    778                         'state' => 'WM_TRANSACTION_STATE_CAPTURED',
    779                         'base_currency' => $currency_code,
    780                         'base_currency_amount' => number_format($order->get_total(), 2, '', ''),
    781                         'currency' => $currency_code,
    782                         'currency_amount' => number_format($order->get_total(), 2, '', ''),
    783                     );
     839
     840                    if( $refund ){
     841                        $data['transactions'][] = array(
     842                            'order_id' => $order_id,
     843                            'type' => 'WM_TRANSACTION_TYPE_ECOMMERCE',
     844                            'state' => 'WM_TRANSACTION_STATE_CAPTURED',
     845                            'base_currency' => $currency_code,
     846                            'base_currency_amount' => '-'.number_format($order->get_total(), 2, '', ''),
     847                            'currency' => $currency_code,
     848                            'currency_amount' => '-'.number_format($order->get_total(), 2, '', ''),
     849                        );
     850                    }
     851                    else {
     852                        $data['transactions'][] = array(
     853                            'order_id' => $order_id,
     854                            'type' => 'WM_TRANSACTION_TYPE_ECOMMERCE',
     855                            'state' => 'WM_TRANSACTION_STATE_CAPTURED',
     856                            'base_currency' => $currency_code,
     857                            'base_currency_amount' => number_format($order->get_total(), 2, '', ''),
     858                            'currency' => $currency_code,
     859                            'currency_amount' => number_format($order->get_total(), 2, '', ''),
     860                        );
     861                    }
    784862                }
    785863
     
    796874                else{
    797875                    $message = 'OrderId processed: ' . $order_data['id'];
    798                     //update_post_meta($order_id, 'extendago_order_id', $results['id']);
    799876                    update_post_meta($order_id, 'order_returned_successfully_to_extendago', '1');
    800877                    update_post_meta($order_id, 'click_and_collect_order', $click_and_collect_order);
  • extendago-wp-connection/trunk/readme.txt

    r2985881 r3019318  
    44Tags: extendago, extenda, woocommerce, arture, POS,
    55Requires at least: 6.0
    6 Tested up to: 6.3.0
    7 Stable tag: 1.4.4
     6Tested up to: 6.4.2
     7Stable tag: 1.4.5
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    3131== Changelog ==
    3232
     33= 1.4.5 =
     34* New feature for processing costs price
     35
    3336= 1.4.4 =
    3437* Flow optimalisation for export and stock changes
Note: See TracChangeset for help on using the changeset viewer.