Changeset 2985881
- Timestamp:
- 10/30/2023 07:46:16 AM (2 years ago)
- Location:
- extendago-wp-connection/trunk
- Files:
-
- 4 edited
-
extendago-wp-connection.php (modified) (1 diff)
-
includes/api/class-extendago-web-api.php (modified) (1 diff)
-
includes/cronjob/class-extendago-cronjob-functions.php (modified) (8 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
extendago-wp-connection/trunk/extendago-wp-connection.php
r2973949 r2985881 4 4 Plugin URI: http://www.arture.nl/extendago 5 5 Description: 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. 36 Version: 1.4.4 7 7 Author: Arture B.V. 8 8 Author URI: https://arture.nl/ -
extendago-wp-connection/trunk/includes/api/class-extendago-web-api.php
r2973949 r2985881 206 206 } 207 207 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 234 208 public function listStockChanges() { 235 209 -
extendago-wp-connection/trunk/includes/cronjob/class-extendago-cronjob-functions.php
r2973949 r2985881 846 846 if( isset($product['variations']) && is_array($product['variations']) && count($product['variations']) != count($ProductResponse['product_variants']) ){ 847 847 $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 } 848 853 } 849 854 elseif( isset($ProductResponse['product_variants'][0]['product_data']) && count($ProductResponse['product_variants'][0]['product_data']) > 1 ){ 850 855 $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 } 851 861 } 852 862 else{ … … 1060 1070 update_option( 'processing_export_time', $processing_export_time ); 1061 1071 } 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 1062 1097 } 1063 1098 … … 1116 1151 $changes = $web_api->listChanges($params); 1117 1152 1153 echo '<pre>'; 1154 print_r($changes); 1155 echo '</pre>'; 1156 1118 1157 // Upload directory 1119 1158 $upload = wp_upload_dir(); … … 1128 1167 1129 1168 update_option('process_product_changes', date('Y-m-d H:i')); 1130 1131 // Product changes1132 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 product1143 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 product1153 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 products1174 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 product1177 }1178 else{1179 break;1180 }1181 }1182 1183 // Get all promotion campaigns/discount rules1184 $promotion_campaigns = $web_api->listPromotionCampaigns();1185 $discount_rules = array();1186 foreach( $promotion_campaigns as $promotion_campaign ){1187 1188 // Skip inactive campaigns1189 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 location1206 $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 data1220 foreach( $product['product_variants'] as $index => $product_variant ){1221 1222 // Check for specific stock location1223 $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 data1238 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 batch1249 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 Masterdata1257 $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 }1264 1169 1265 1170 // Categorie changes … … 1278 1183 foreach ($changes['product_categories'] as $product_category) { 1279 1184 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) ){ 1294 1199 foreach( $terms as $term ){ 1295 1200 wp_delete_term($term->term_id, 'product_cat'); … … 1297 1202 } 1298 1203 else { 1299 1300 1204 $extendago_masterdata['ProductCategories'][$product_category['id']] = $product_category; 1301 1205 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( 1306 1208 'name' => $product_category['name'], 1307 1209 )); … … 1310 1212 $api_functions = new ExtendaGo_Web_Api_Functions(); 1311 1213 $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)); 1313 1215 } 1314 1216 } … … 1464 1366 } 1465 1367 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 1466 1502 } 1467 1503 -
extendago-wp-connection/trunk/readme.txt
r2973949 r2985881 5 5 Requires at least: 6.0 6 6 Tested up to: 6.3.0 7 Stable tag: 1.4. 37 Stable tag: 1.4.4 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 31 31 == Changelog == 32 32 33 = 1.4.4 = 34 * Flow optimalisation for export and stock changes 35 * Bugfix for category name changes 36 33 37 = 1.4.3 = 34 38 * Some minor improvements and code updates
Note: See TracChangeset
for help on using the changeset viewer.