Plugin Directory

Changeset 2849244


Ignore:
Timestamp:
01/16/2023 03:13:15 PM (3 years ago)
Author:
extendago
Message:

Version 1.2.7

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

Legend:

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

    r2839827 r2849244  
    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.2.6
     6Version:     1.2.7
    77Author:      Arture B.V.
    88Author URI:  https://arture.nl/
  • extendago-wp-connection/trunk/includes/admin/class-extendago-wp-connection-admin.php

    r2826526 r2849244  
    9696        register_setting('extendago_api_options', 'extendago_api_arture_key');
    9797
    98         // Iterate Woocommerce shipping methods
    9998        if ( class_exists( 'WooCommerce' ) ) {
    100 
    10199            $Extendago = new Extendago_Web_Api();
    102100            $VatRates = $Extendago->CurlRequest("/vat_rates", "GET");
  • extendago-wp-connection/trunk/includes/cronjob/class-extendago-cronjob-functions.php

    r2839827 r2849244  
    108108        if( !isset($_POST['product_id']) ) $this->logging->log_file_write( 'GetAllWebshopProducts | ' .count($products) );
    109109
    110         if( isset($_POST['sc_product_id']) && !empty($_POST['sc_product_id']) ) {
    111             $this->logging->log_file_write( 'Manual | Manual triggered synchronisation for product: ' .$_POST['sc_product_id']);
     110        if( isset($_POST['product_id']) && !empty($_POST['product_id']) ) {
     111            $this->logging->log_file_write( 'Manual | Manual triggered synchronisation for product: ' .$_POST['product_id']);
    112112        }
    113113
     
    641641
    642642                        // Process featured image
     643                        $ExtendagoProductJSON['image'] = '';
    643644                        if (isset($product['image']) && !empty($product['image'])){
    644645                            $image = new \CurlFile($product['image'], mime_content_type($product['image']), time().'_'.basename($product['image']));
     
    659660                                'product_id'            => $product['id'],
    660661                                'price_region_id'       => $price_region_id,
    661                                 'vat_rate_id'           => null,
     662                                'vat_rate_id'           => $product['vat_rate_id'],
    662663                                'least_quantity'        => null,
    663664                                'weekcover'             => 0,
     
    681682                                    $unit_id = 'pc';
    682683                                }
     684
    683685
    684686                                // First variation
     
    692694                                            'product_id'            => $product['id'],
    693695                                            'price_region_id'       => $price_region_id,
    694                                             'vat_rate_id'           => null,
     696                                            'vat_rate_id'           => $variation->vat_rate_id,
    695697                                            'least_quantity'        => null,
    696698                                            'weekcover'             => 0,
     
    714716                                            'product_variant_id'    => $variation->id,
    715717                                            'price_region_id'       => $price_region_id,
    716                                             'vat_rate_id'           => null,
     718                                            'vat_rate_id'           => $variation->vat_rate_id,
    717719                                            'least_quantity'        => null,
    718720                                            'weekcover'             => 0,
     
    12731275                foreach ( $stock_change['stock_event_lines'] as $stock_event_line ) {
    12741276
     1277                    if( $stock_event_line['stock_event_lines']['name'] == 'CountStock of product' ){
     1278                        continue;
     1279                    }
     1280
    12751281                    $total_sychronized_stock_changes++;
    12761282
    1277                     $this->logging->log_file_write('ExtendaGo | ' . strtok($stock_change['reference_id'], ' -') . ' of product: ' . $stock_event_line['name']);
     1283                    $this->logging->log_file_write('ExtendaGo | ' . strtok($stock_change['reference_id'], ' -') . ' of product: ' . $stock_event_line['stock_event_lines']['name']);
    12781284
    12791285                    // Save new product stock values
  • extendago-wp-connection/trunk/includes/woocommerce/class-extendago-woocommerce-functions.php

    r2839827 r2849244  
    99        add_action( 'woocommerce_update_product', array($this, 'save_product_as_export_batch'), 10, 1 );
    1010        add_action( 'wp_trash_post', array($this, 'after_wp_trash_post'));
     11        add_action( 'untrash_post', array($this, 'save_product_as_export_batch'));
    1112
    1213        add_filter( 'woocommerce_product_data_tabs', array($this, 'add_extendago_product_data_tab') );
     
    4647        if($post->post_type === 'product') {
    4748
    48 //            $extendago_product_id = get_post_meta( $post_id, 'extendago_product_id', true );
    49 //
    50 //            //require_once(__DIR__ . "/../api/class-extendago-web-api.php");
    51 //            $Extendago = new Extendago_Web_Api();
    52 //            $ProductResponse = $Extendago->CurlRequest('/products/'.$extendago_product_id, 'GET');
    53 //
    54 //            echo '<pre>';
    55 //            print_r($ProductResponse);
    56 //            echo '</pre>';
    57 //            if( isset($ProductResponse['id']) ){
    58 //                $ExtendagoProductJSON = array(
    59 //                    'id'                    => $extendago_product_id,
    60 //                    'attributes' => array(
    61 //                        'hide_from_web' => '1'
    62 //                    )
    63 //                );
    64 //
    65 //                $test = $Extendago->CurlRequest('/products/'.$extendago_product_id, 'PUT', $ExtendagoProductJSON, false, true);
    66 //
    67 //                echo '<pre>';
    68 //                print_r($test);
    69 //                echo '</pre>';
    70 //            }
    71 //
    72 //            exit;
    73 
     49            $extendago_product_id = get_post_meta( $post_id, 'extendago_product_id', true );
     50
     51            require_once(__DIR__ . "/../api/class-extendago-web-api.php");
     52            $Extendago = new Extendago_Web_Api();
     53            $ProductResponse = $Extendago->CurlRequest('/products/'.$extendago_product_id, 'GET');
     54
     55            if( isset($ProductResponse['id']) ){
     56                $Extendago->CurlRequest('/products/'.$extendago_product_id, 'DELETE', array(), false, true);
     57            }
    7458        }
    7559
     
    125109    }
    126110
    127     function save_product_as_export_batch( $product_id ) {
     111    function save_product_as_export_batch( $product_id )
     112    {
     113
     114        $post = get_post($product_id);
     115
     116        if ($post->post_type !== 'product') {
     117            return;
     118        }
    128119
    129120        $extendago_export_only = get_option('extendago_export_only');
    130         if ( !isset($extendago_export_only) || $extendago_export_only == '0' || $extendago_export_only == '' ) {
     121        if (!isset($extendago_export_only) || $extendago_export_only == '0' || $extendago_export_only == '') {
    131122            return;
    132123        }
    133124
    134         $product = wc_get_product( $product_id );
     125        $product = wc_get_product($product_id);
    135126
    136127        // Upload directory
     
    138129        $upload_dir = $upload['basedir'];
    139130        $new_upload_dir = $upload_dir . '/extendago/exports';
     131
     132        $Extendago = new Extendago_Web_Api();
     133        $VatRates = $Extendago->CurlRequest("/vat_rates", "GET");
     134        $vat_rate_id = '';
     135        foreach ($VatRates as $VatRate){
     136            $value = get_option($VatRate['id']);
     137            if( $value == $product->get_tax_class() ){
     138                $vat_rate_id = $VatRate['id'];
     139                break;
     140            }
     141        }
    140142
    141143        $product_data = array();
     
    149151        $product_data['short_description'] = $product->get_short_description();
    150152        $product_data['sku'] = $product->get_sku();
     153        $product_data['vat_rate_id'] = $vat_rate_id;
    151154
    152155        // Get Product Prices
     
    156159
    157160        $product_attributes = $product->get_attributes();
    158         if( isset($product_attributes) && !empty($product_attributes) ){
    159             foreach( $product_attributes as $product_attribute_name => $product_attribute ){
    160                 $product_data['attributes'][$product_attribute_name] = $product->get_attribute( $product_attribute_name );
    161             }
    162         }
    163 
    164         if( $product_data['type'] == 'variable' ){
     161        if (isset($product_attributes) && !empty($product_attributes)) {
     162            foreach ($product_attributes as $product_attribute_name => $product_attribute) {
     163                $product_data['attributes'][$product_attribute_name] = $product->get_attribute($product_attribute_name);
     164            }
     165        }
     166
     167        if ($product_data['type'] == 'variable') {
    165168            $product_data['variations'] = array();
    166169            $product_variations = $product->get_children();
    167             if( isset($product_variations) && !empty($product_variations) ){
    168                 foreach( $product_variations as $product_variation_id ){
    169 
    170                     $variation_meta = get_post_meta($product_variation_id);
    171                     foreach( $product_data['attributes'] as $attribute => $attribute_value ){
    172                         if( isset($variation_meta['attribute_'.$attribute]) ){
    173                             $product_variant_name = $variation_meta['attribute_'.$attribute][0];
     170            if (isset($product_variations) && !empty($product_variations)) {
     171                foreach ($product_variations as $product_variation_id) {
     172                    $Variation = new WC_Product_Variation($product_variation_id);
     173
     174                    $vat_rate_id = $product_data['vat_rate_id'];
     175                    foreach ($VatRates as $VatRate){
     176                        $value = get_option($VatRate['id']);
     177                        if( $value == $Variation->get_tax_class() ){
     178                            $vat_rate_id = $VatRate['id'];
    174179                            break;
    175180                        }
     
    177182
    178183                    $variation_meta = get_post_meta($product_variation_id);
    179                     foreach( $product_data['attributes'] as $attribute => $attribute_value ){
    180                         if( isset($variation_meta['attribute_'.$attribute]) ){
    181                             $Variation = new WC_Product_Variation( $product_variation_id );
     184                    foreach ($product_data['attributes'] as $attribute => $attribute_value) {
     185                        if (isset($variation_meta['attribute_' . $attribute])) {
     186                            $product_variant_name = $variation_meta['attribute_' . $attribute][0];
     187                            break;
     188                        }
     189                    }
     190
     191                    $variation_meta = get_post_meta($product_variation_id);
     192                    foreach ($product_data['attributes'] as $attribute => $attribute_value) {
     193                        if (isset($variation_meta['attribute_' . $attribute])) {
    182194                            $attribute_name = $Variation->get_name();
    183195                            $attribute_name = explode(" - ", $attribute_name);
     
    187199                    }
    188200
    189                     if( isset($product_variant_name) ) {
     201                    if (isset($product_variant_name)) {
    190202                        $product_data['variations'][] = array(
    191203                            'id' => $product_variation_id,
     
    196208                            'retail_price' => $variation_meta['_price'][0],
    197209                            'sale_price' => $variation_meta['_sale_price'][0],
     210                            'vat_rate_id' => $vat_rate_id,
    198211                        );
    199212                    }
     
    201214            }
    202215
    203         }
    204         else{
     216        } else {
    205217            $product_data['quantity'] = $product->get_stock_quantity();
    206218            $product_data['status'] = $product->get_stock_status();
     
    208220
    209221        $product_categories = wp_get_object_terms($product_data['id'], 'product_cat');
    210         if( isset($product_categories) && !empty($product_categories) ){
    211             foreach( $product_categories as $product_category ){
     222        if (isset($product_categories) && !empty($product_categories)) {
     223            foreach ($product_categories as $product_category) {
    212224                $product_data['categories'][$product_category->term_id] = array(
    213225                    'name' => $product_category->name,
     
    221233        // Get Product Images
    222234        $thumbnail_id = $product->get_image_id();
    223         if( isset($thumbnail_id) && !empty($thumbnail_id) ){
     235        if (isset($thumbnail_id) && !empty($thumbnail_id)) {
    224236            $product_data['image'] = get_attached_file($thumbnail_id, true);
    225237        }
    226238        $gallery_image_ids = $product->get_gallery_image_ids();
    227         if( isset($gallery_image_ids) && !empty($gallery_image_ids) ){
    228             foreach( $gallery_image_ids as $gallery_image_id ){
     239        if (isset($gallery_image_ids) && !empty($gallery_image_ids)) {
     240            foreach ($gallery_image_ids as $gallery_image_id) {
    229241                $product_data['gallery'][] = get_attached_file($gallery_image_id, true);
    230242            }
  • extendago-wp-connection/trunk/readme.txt

    r2839827 r2849244  
    55Requires at least: 6.0
    66Tested up to: 6.1.1
    7 Stable tag: 1.2.6
     7Stable tag: 1.2.7
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    3030
    3131== Changelog ==
     32
     33= 1.2.7 =
     34* Vat rate processing for exports
     35* Performance updates
     36* Image delete action
     37* Product delete action
    3238
    3339= 1.2.6 =
Note: See TracChangeset for help on using the changeset viewer.