Plugin Directory

Changeset 2985881


Ignore:
Timestamp:
10/30/2023 07:46:16 AM (2 years ago)
Author:
extendago
Message:

Version 1.4.4

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

Legend:

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

    r2973949 r2985881  
    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.3
     6Version:     1.4.4
    77Author:      Arture B.V.
    88Author URI:  https://arture.nl/
  • extendago-wp-connection/trunk/includes/api/class-extendago-web-api.php

    r2973949 r2985881  
    206206    }
    207207
    208     public function listStockValues() {
    209         $Offset = 0;
    210         $Limit = 250;
    211         $HasMore = true;
    212         $StockValues = array();
    213         while ($HasMore) {
    214             $HasMore = false;
    215             $Results = $this->CurlRequest("/stock_values", "GET", array("limit" => $Limit, "offset" => $Offset));
    216             foreach ($Results as $Result) {
    217                 if (isset($Result['id'])) {
    218                     if( isset($Result['product_variant_id']) && !empty($Result['product_variant_id']) ){
    219                         $StockValues[$Result['product_variant_id']][] = $Result;
    220                     }
    221                     else{
    222                         $StockValues[$Result['product_id']][] = $Result;
    223                     }
    224                 }
    225             }
    226             if (count($Results) == $Limit) {
    227                 $HasMore = true;
    228                 $Offset += $Limit;
    229             }
    230         }
    231         return $StockValues;
    232     }
    233 
    234208    public function listStockChanges() {
    235209
  • extendago-wp-connection/trunk/includes/cronjob/class-extendago-cronjob-functions.php

    r2973949 r2985881  
    846846                            if( isset($product['variations']) && is_array($product['variations']) && count($product['variations']) != count($ProductResponse['product_variants']) ){
    847847                                $ProductResponse = $Extendago->CurlRequest('/products/'.$product['id'], 'PUT', $ExtendagoProductJSON, false, true);
     848                                if( is_null($ProductResponse) ){
     849                                    unset($ExtendagoProductJSON['image']);
     850                                    $this->logging->log_file_write('ERROR | Product ' . $product['id'] . ' image is not available of too large');
     851                                    $ProductResponse = $Extendago->CurlRequest('/products/'.$product['id'], 'PUT', $ExtendagoProductJSON, false, true);
     852                                }
    848853                            }
    849854                            elseif( isset($ProductResponse['product_variants'][0]['product_data']) && count($ProductResponse['product_variants'][0]['product_data']) > 1 ){
    850855                                $ProductResponse = $Extendago->CurlRequest('/products/'.$product['id'], 'PUT', $ExtendagoProductJSON, false, true);
     856                                if( is_null($ProductResponse) ){
     857                                    unset($ExtendagoProductJSON['image']);
     858                                    $this->logging->log_file_write('ERROR | Product ' . $product['id'] . ' image is not available of too large');
     859                                    $ProductResponse = $Extendago->CurlRequest('/products/'.$product['id'], 'PUT', $ExtendagoProductJSON, false, true);
     860                                }
    851861                            }
    852862                            else{
     
    10601070                            update_option( 'processing_export_time', $processing_export_time );
    10611071                        }
     1072                        else{
     1073
     1074                            // ERROR flow
     1075                            update_post_meta( $product['id'], 'latest_update', date('Y-m-d h:i') );
     1076
     1077                            // Save changes to temp dir
     1078                            if( strpos($file, 'product_added') !== false || strpos($file, 'product_changed') !== false ){
     1079                                // Move file to temp folder
     1080                                $current_file_path = $directory . '/' . $file;
     1081
     1082                                $file = str_replace('json', 'error', $file);
     1083                                $new_file_path = $directory . '/temp/' . $file;
     1084                                rename($current_file_path, $new_file_path);
     1085                            }
     1086                            else {
     1087                                $products->$key->processed = 'true';
     1088                                $products->$key->has_error = 'true';
     1089                                file_put_contents($directory . '/' . $file, json_encode($products));
     1090                            }
     1091
     1092                            // Update time after every succefull processed product
     1093                            $processing_export_time = time();
     1094                            update_option( 'processing_export_time', $processing_export_time );
     1095                        }
     1096
    10621097                    }
    10631098
     
    11161151        $changes = $web_api->listChanges($params);
    11171152
     1153        echo '<pre>';
     1154        print_r($changes);
     1155        echo '</pre>';
     1156
    11181157        // Upload directory
    11191158        $upload = wp_upload_dir();
     
    11281167
    11291168            update_option('process_product_changes', date('Y-m-d H:i'));
    1130 
    1131             // Product changes
    1132             if( isset($changes['products']) && !empty($changes['products']) ) {
    1133 
    1134                 $import_shop_products = get_option( 'extendago_import_shop_products' );
    1135                 $extendago_shop_group_ids = get_option( 'extendago_shop_group_ids' );
    1136 
    1137                 $products_array = array();
    1138                 foreach( $changes['products'] as $product_change ) {
    1139 
    1140                     switch ($product_change) {
    1141 
    1142                         // Deleted product
    1143                         case (isset($product_change['deleted']) && $product_change['deleted'] == '1' ):
    1144 
    1145                             $post_id = $this->functions->custom_get_product_id_by_sku($product_change['id'], $product_change['sku']);
    1146                             if (isset($post_id) && !empty($post_id)) {
    1147                                 $this->logging->log_file_write('GetProductRemoved | Product removed from webshop ' . $post_id);
    1148                                 wp_trash_post($post_id);
    1149                             }
    1150                             break;
    1151 
    1152                         // Added product
    1153                         case (isset($product_change['product_data']) ):
    1154 
    1155                             $product = $product_change;
    1156 
    1157                             // Delete producten met de optie "Hide form web"
    1158                             if(
    1159                                 isset($product['attributes'][1]['hide_from_web']) && $product['attributes'][1]['hide_from_web'] == '1'
    1160                                 ||
    1161                                 isset($product['active']) && $product['active'] == '0'
    1162                             ){
    1163                                 $total_products--;
    1164 
    1165                                 $post_id = $this->functions->custom_get_product_id_by_sku($product_change['id'], $product_change['sku']);
    1166                                 if (isset($post_id) && !empty($post_id)) {
    1167                                     $this->logging->log_file_write('GetProductRemoved | Product removed from webshop ' . $post_id);
    1168                                     wp_trash_post($post_id);
    1169                                 }
    1170                                 break;
    1171                             }
    1172 
    1173                             // Process only shop/group specific products
    1174                             if( isset($import_shop_products) && $import_shop_products && isset($extendago_shop_group_ids) ) {
    1175                                 if( isset($product['shop_groups']) && in_array($extendago_shop_group_ids, $product['shop_groups']) ){
    1176                                     // Process product
    1177                                 }
    1178                                 else{
    1179                                     break;
    1180                                 }
    1181                             }
    1182 
    1183                             // Get all promotion campaigns/discount rules
    1184                             $promotion_campaigns = $web_api->listPromotionCampaigns();
    1185                             $discount_rules = array();
    1186                             foreach( $promotion_campaigns as $promotion_campaign ){
    1187 
    1188                                 // Skip inactive campaigns
    1189                                 if( !isset($promotion_campaign['enabled']) || !$promotion_campaign['enabled'] ){
    1190                                     continue;
    1191                                 }
    1192 
    1193                                 foreach( $promotion_campaign['benefit_products'] as $benefit_product){
    1194                                     $discount_rules[$benefit_product['product_id']] = array(
    1195                                         'discount_id'           => $promotion_campaign['id'],
    1196                                         'discount_percentage'   => $promotion_campaign['benefit']['percentage_off'],
    1197                                         'discount_amount'       => $promotion_campaign['benefit']['amount_off'],
    1198                                         'discount_fixed_price'  => $promotion_campaign['benefit']['fixed_price'],
    1199                                         'discount_date_from'    => $promotion_campaign['date_from'],
    1200                                         'discount_date_until'   => $promotion_campaign['date_to'],
    1201                                     );
    1202                                 }
    1203                             }
    1204 
    1205                             // Check for specific stock location
    1206                             $stock_values = $web_api->CurlRequest('/stock_values?filter-product_id='.$product['id'], 'GET');
    1207                             if( isset($extendago_location_id) && !empty($extendago_location_id) ){
    1208                                 foreach( $stock_values as $stock_value ){
    1209                                     if( $stock_value['stock_location_id'] == $extendago_location_id ){
    1210                                         $product['stock'] = floor($stock_value['quantity']);
    1211                                         break;
    1212                                     }
    1213                                 }
    1214                             }
    1215                             else{
    1216                                 $product['stock'] = floor($stock_values[0]['quantity']);
    1217                             }
    1218 
    1219                             // Set product variants stock data
    1220                             foreach( $product['product_variants'] as $index => $product_variant ){
    1221 
    1222                                 // Check for specific stock location
    1223                                 $stock_values = $web_api->CurlRequest('/stock_values?filter-product_variant_id='.$product_variant['id'], 'GET');
    1224                                 if( isset($extendago_location_id) && !empty($extendago_location_id) ){
    1225                                     foreach( $stock_values as $stock_value ){
    1226                                         if( $stock_value['stock_location_id'] == $extendago_location_id ){
    1227                                             $product['product_variants'][$index]['stock'] = floor($stock_value['quantity']);
    1228                                             break;
    1229                                         }
    1230                                     }
    1231                                 }
    1232                                 else{
    1233                                     $product['product_variants'][$index]['stock'] = floor($stock_values[0]['quantity']);
    1234                                 }
    1235                             }
    1236 
    1237                             // Set product discount data
    1238                             if( isset($discount_rules[$product['id']]) ){
    1239                                 $product = array_merge($product, $discount_rules[$product['id']]);
    1240                             }
    1241 
    1242                             $products_array[ $product['id'] ] = $product;
    1243                             break;
    1244                     }
    1245                 }
    1246 
    1247 
    1248                 // Verwerk toegevoegde producten in batch
    1249                 if( count($products_array) > 0 ){
    1250 
    1251                     $extendago_masterdata = array();
    1252 
    1253                     $product_categories = $web_api->listProductCategories();
    1254                     $extendago_masterdata['ProductCategories'] = $product_categories;
    1255 
    1256                     // Save Masterdata
    1257                     $directory  = $upload_dir . '/extendago';
    1258                     file_put_contents($directory . '/MasterData.json', json_encode($extendago_masterdata));
    1259                     $this->logging->log_file_write( 'MasterData | SAVED' );
    1260 
    1261                     $success = file_put_contents($new_upload_dir . '/'.$sync_round_identifier.'_products_changed_batch.json', json_encode($products_array));
    1262                 }
    1263             }
    12641169
    12651170            // Categorie changes
     
    12781183                foreach ($changes['product_categories'] as $product_category) {
    12791184
    1280                     if( isset($product_category['deleted']) ){
    1281                         $args = array(
    1282                             'hide_empty' => false,
    1283                             'meta_query' => array(
    1284                                 array(
    1285                                     'key'       => 'extendago_id',
    1286                                     'value'     => $product_category['id'],
    1287                                     'compare'   => '='
    1288                                 )
    1289                             ),
    1290                             'taxonomy'  => 'product_cat',
    1291                         );
    1292                         $terms = get_terms( $args );
    1293 
     1185                    $args = array(
     1186                        'hide_empty' => false,
     1187                        'meta_query' => array(
     1188                            array(
     1189                                'key'       => 'extendago_id',
     1190                                'value'     => $product_category['id'],
     1191                                'compare'   => '='
     1192                            )
     1193                        ),
     1194                        'taxonomy'  => 'product_cat',
     1195                    );
     1196                    $terms = get_terms( $args );
     1197
     1198                    if( isset($product_category['deleted']) && !empty($terms) ){
    12941199                        foreach( $terms as $term ){
    12951200                            wp_delete_term($term->term_id, 'product_cat');
     
    12971202                    }
    12981203                    else {
    1299 
    13001204                        $extendago_masterdata['ProductCategories'][$product_category['id']] = $product_category;
    13011205
    1302                         $category_term = term_exists(sanitize_title($product_category['name']), 'product_cat');
    1303                         if (isset($category_term) && !empty($category_term)) {
    1304 
    1305                             wp_update_term($category_term['term_id'], 'product_cat', array(
     1206                        if (isset($terms[0]) && !empty($terms)) {
     1207                            wp_update_term($terms[0]->term_id, 'product_cat', array(
    13061208                                'name' => $product_category['name'],
    13071209                            ));
     
    13101212                                $api_functions = new ExtendaGo_Web_Api_Functions();
    13111213                                $attach_id = $api_functions->upload_external_file($product_category['image']);
    1312                                 update_term_meta($category_term['term_id'], 'thumbnail_id', absint($attach_id));
     1214                                update_term_meta($terms[0]->term_id, 'thumbnail_id', absint($attach_id));
    13131215                            }
    13141216                        }
     
    14641366            }
    14651367
     1368            // Product changes
     1369            if( isset($changes['products']) && !empty($changes['products']) ) {
     1370
     1371                $import_shop_products = get_option( 'extendago_import_shop_products' );
     1372                $extendago_shop_group_ids = get_option( 'extendago_shop_group_ids' );
     1373
     1374                $products_array = array();
     1375                foreach( $changes['products'] as $product_change ) {
     1376
     1377                    switch ($product_change) {
     1378
     1379                        // Deleted product
     1380                        case (isset($product_change['deleted']) && $product_change['deleted'] == '1' ):
     1381
     1382                            $post_id = $this->functions->custom_get_product_id_by_sku($product_change['id'], $product_change['sku']);
     1383                            if (isset($post_id) && !empty($post_id)) {
     1384                                $this->logging->log_file_write('GetProductRemoved | Product removed from webshop ' . $post_id);
     1385                                wp_trash_post($post_id);
     1386                            }
     1387                            break;
     1388
     1389                        // Added product
     1390                        case (isset($product_change['product_data']) ):
     1391
     1392                            $product = $product_change;
     1393
     1394                            // Delete producten met de optie "Hide form web"
     1395                            if(
     1396                                isset($product['attributes'][1]['hide_from_web']) && $product['attributes'][1]['hide_from_web'] == '1'
     1397                                ||
     1398                                isset($product['active']) && $product['active'] == '0'
     1399                            ){
     1400                                $total_products--;
     1401
     1402                                $post_id = $this->functions->custom_get_product_id_by_sku($product_change['id'], $product_change['sku']);
     1403                                if (isset($post_id) && !empty($post_id)) {
     1404                                    $this->logging->log_file_write('GetProductRemoved | Product removed from webshop ' . $post_id);
     1405                                    wp_trash_post($post_id);
     1406                                }
     1407                                break;
     1408                            }
     1409
     1410                            // Process only shop/group specific products
     1411                            if( isset($import_shop_products) && $import_shop_products && isset($extendago_shop_group_ids) ) {
     1412                                if( isset($product['shop_groups']) && in_array($extendago_shop_group_ids, $product['shop_groups']) ){
     1413                                    // Process product
     1414                                }
     1415                                else{
     1416                                    break;
     1417                                }
     1418                            }
     1419
     1420                            // Get all promotion campaigns/discount rules
     1421                            $promotion_campaigns = $web_api->listPromotionCampaigns();
     1422                            $discount_rules = array();
     1423                            foreach( $promotion_campaigns as $promotion_campaign ){
     1424
     1425                                // Skip inactive campaigns
     1426                                if( !isset($promotion_campaign['enabled']) || !$promotion_campaign['enabled'] ){
     1427                                    continue;
     1428                                }
     1429
     1430                                foreach( $promotion_campaign['benefit_products'] as $benefit_product){
     1431                                    $discount_rules[$benefit_product['product_id']] = array(
     1432                                        'discount_id'           => $promotion_campaign['id'],
     1433                                        'discount_percentage'   => $promotion_campaign['benefit']['percentage_off'],
     1434                                        'discount_amount'       => $promotion_campaign['benefit']['amount_off'],
     1435                                        'discount_fixed_price'  => $promotion_campaign['benefit']['fixed_price'],
     1436                                        'discount_date_from'    => $promotion_campaign['date_from'],
     1437                                        'discount_date_until'   => $promotion_campaign['date_to'],
     1438                                    );
     1439                                }
     1440                            }
     1441
     1442                            // Check for specific stock location
     1443                            $stock_values = $web_api->CurlRequest('/stock_values?filter-product_id='.$product['id'], 'GET');
     1444                            if( isset($extendago_location_id) && !empty($extendago_location_id) ){
     1445                                foreach( $stock_values as $stock_value ){
     1446                                    if( $stock_value['stock_location_id'] == $extendago_location_id ){
     1447                                        $product['stock'] = floor($stock_value['quantity']);
     1448                                        break;
     1449                                    }
     1450                                }
     1451                            }
     1452                            else{
     1453                                $product['stock'] = floor($stock_values[0]['quantity']);
     1454                            }
     1455
     1456                            // Set product variants stock data
     1457                            foreach( $product['product_variants'] as $index => $product_variant ){
     1458
     1459                                // Check for specific stock location
     1460                                $stock_values = $web_api->CurlRequest('/stock_values?filter-product_variant_id='.$product_variant['id'], 'GET');
     1461                                if( isset($extendago_location_id) && !empty($extendago_location_id) ){
     1462                                    foreach( $stock_values as $stock_value ){
     1463                                        if( $stock_value['stock_location_id'] == $extendago_location_id ){
     1464                                            $product['product_variants'][$index]['stock'] = floor($stock_value['quantity']);
     1465                                            break;
     1466                                        }
     1467                                    }
     1468                                }
     1469                                else{
     1470                                    $product['product_variants'][$index]['stock'] = floor($stock_values[0]['quantity']);
     1471                                }
     1472                            }
     1473
     1474                            // Set product discount data
     1475                            if( isset($discount_rules[$product['id']]) ){
     1476                                $product = array_merge($product, $discount_rules[$product['id']]);
     1477                            }
     1478
     1479                            $products_array[ $product['id'] ] = $product;
     1480                            break;
     1481                    }
     1482                }
     1483
     1484
     1485                // Verwerk toegevoegde producten in batch
     1486                if( count($products_array) > 0 ){
     1487
     1488                    $extendago_masterdata = array();
     1489
     1490                    $product_categories = $web_api->listProductCategories();
     1491                    $extendago_masterdata['ProductCategories'] = $product_categories;
     1492
     1493                    // Save Masterdata
     1494                    $directory  = $upload_dir . '/extendago';
     1495                    file_put_contents($directory . '/MasterData.json', json_encode($extendago_masterdata));
     1496                    $this->logging->log_file_write( 'MasterData | SAVED' );
     1497
     1498                    $success = file_put_contents($new_upload_dir . '/'.$sync_round_identifier.'_products_changed_batch.json', json_encode($products_array));
     1499                }
     1500            }
     1501
    14661502        }
    14671503
  • extendago-wp-connection/trunk/readme.txt

    r2973949 r2985881  
    55Requires at least: 6.0
    66Tested up to: 6.3.0
    7 Stable tag: 1.4.3
     7Stable tag: 1.4.4
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    3131== Changelog ==
    3232
     33= 1.4.4 =
     34* Flow optimalisation for export and stock changes
     35* Bugfix for category name changes
     36
    3337= 1.4.3 =
    3438* Some minor improvements and code updates
Note: See TracChangeset for help on using the changeset viewer.