Changeset 3208968
- Timestamp:
- 12/17/2024 08:42:46 AM (15 months ago)
- Location:
- extendago-wp-connection/trunk
- Files:
-
- 6 edited
-
extendago-wp-connection.php (modified) (1 diff)
-
includes/api/class-extendago-web-api-functions.php (modified) (5 diffs)
-
includes/class-extendago-wp-connection-functions.php (modified) (3 diffs)
-
includes/cronjob/class-extendago-cronjob-functions.php (modified) (6 diffs)
-
includes/woocommerce/class-extendago-woocommerce-functions.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
extendago-wp-connection/trunk/extendago-wp-connection.php
r3176970 r3208968 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.5. 66 Version: 1.5.7 7 7 Requires Plugins: woocommerce 8 8 Author: Arture B.V. -
extendago-wp-connection/trunk/includes/api/class-extendago-web-api-functions.php
r3176970 r3208968 24 24 public function extendago_update_wc_product( $product, $full_sync = false ){ 25 25 26 $logging = new ExtendaGo_WP_Connection_Logging(); 27 26 28 $product = apply_filters('before_extendago_product_process', $product); 27 29 … … 35 37 // Find product by SKU 36 38 $post_id = $this->functions->custom_get_product_id_by_sku( $product['id'], $product['sku'] ); 39 40 41 $logging->log_file_write('DEBUG | POST ID: ' .$post_id); 37 42 38 43 $hide_from_web = 0; … … 127 132 } 128 133 134 $logging->log_file_write('DEBUG | INSERT POST'); 129 135 $post_id = wp_insert_post( $args ); 130 136 } … … 183 189 } 184 190 191 $logging->log_file_write('DEBUG | UPDATE POST'); 185 192 wp_update_post( $args ); 186 193 } … … 467 474 if (!isset($extendago_keep_product_status) || !$extendago_keep_product_status) { 468 475 $Product->set_status($no_image_post_status); 469 470 // LOG471 $logging = new ExtendaGo_WP_Connection_Logging();472 476 $logging->log_file_write('Status | Post (' . $post_id . ') has no image. Updating post-status to: ' . $no_image_post_status); 473 477 } -
extendago-wp-connection/trunk/includes/class-extendago-wp-connection-functions.php
r2945883 r3208968 40 40 } 41 41 42 public function custom_get_product_id_by_sku( $product_id, $sku ) { 42 public function custom_get_product_id_by_sku( $extendago_product_id, $sku ) { 43 44 $logging = new ExtendaGo_WP_Connection_Logging(); 43 45 44 46 $args = array( 45 'post_type' => 'product', 46 'post_status' => 'any', 47 'post_type' => 'product', 47 48 'posts_per_page' => -1, 49 'post_status' => array('publish', 'draft', 'pending', 'private', 'trash'), 48 50 'meta_query' => array( 49 51 array( 50 'key' => 'extendago_product_id', 51 'value' => $product_id 52 'key' => 'extendago_product_id', 53 'value' => $extendago_product_id, 54 'compare' => '=' 52 55 ) 53 56 ), 54 'fields' => 'ids' 57 'fields' => 'ids', // Retourneer alleen IDs 55 58 ); 56 59 $product_query = new WP_Query($args); … … 74 77 } 75 78 79 // Fallback if Product Query not working 80 if( empty($product_ids) ) { 81 global $wpdb; 82 $results = $wpdb->get_results(" 83 SELECT p.ID 84 FROM {$wpdb->posts} p 85 JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 86 WHERE pm.meta_key = 'extendago_product_id' 87 AND pm.meta_value = '{$extendago_product_id}' 88 AND p.post_type = 'product' 89 AND p.post_status IN ('publish', 'draft', 'pending', 'private', 'trash') 90 "); 91 $product_ids = wp_list_pluck($results, 'ID'); 92 } 93 76 94 // Remove duplicates based on SKU ( Unique identifier ) 77 95 if( count($product_ids) > 1 ){ 78 $logging = new ExtendaGo_WP_Connection_Logging();79 96 $product_id = end($product_ids); 80 97 … … 93 110 } 94 111 95 return ( $product_id ) ? intval( $product_id ) : 0;112 return $product_id; 96 113 } 97 114 -
extendago-wp-connection/trunk/includes/cronjob/class-extendago-cronjob-functions.php
r3176970 r3208968 46 46 if( $this->endsWith($_SERVER["REQUEST_URI"], '/extendago-process-changes') ){ 47 47 48 $this->logging->log_file_write( 'Cronjob Changes | SERVER' ); 49 48 50 // Check for existing export 49 51 if (isset($files) && count($files) > 3) { … … 51 53 } 52 54 else{ 53 $this->logging->log_file_write( 'Cronjob Changes | SERVER' );54 55 $this->process_changes_wc_products(); 55 56 } … … 569 570 570 571 $this->logging->log_file_write( 'Product cronjob | Processing batches' ); 572 $processing_batch_time = time(); 573 update_option( 'processing_batch_time', $processing_batch_time ); 571 574 572 575 natcasesort( $files ); … … 1266 1269 $extendago_location_id = get_option( "extendago_location_id" ); 1267 1270 1268 $params = array( 1269 'from' => time() - 60*12, // Afgelopen 12 minuten 1270 'include' => json_encode(array('products', 'promotion_campaigns', 'product_categories')) 1271 ); 1271 $new_processed_changes_time = time(); 1272 $last_processed_changes_time = get_option('last_processed_changes_time'); 1273 if( isset($last_processed_changes_time) && !empty($last_processed_changes_time) ){ 1274 $params = array( 1275 'from' => $last_processed_changes_time, 1276 'include' => json_encode(array('products', 'promotion_campaigns', 'product_categories')) 1277 ); 1278 } 1279 else{ 1280 $params = array( 1281 'from' => time() - 60*12, // Afgelopen 12 minuten 1282 'include' => json_encode(array('products', 'promotion_campaigns', 'product_categories')) 1283 ); 1284 } 1272 1285 $changes = $web_api->listChanges($params); 1273 1286 … … 1531 1544 $product = $product_change; 1532 1545 1533 $ remove_from_web = false;1534 foreach( $product['attributes'] as $ product_attribute){1535 foreach( $product_attribute as $attribute_key => $attribute_value ) {1536 if( ( $attribute_key == 'hide_from_web' && $attribute_value == '1' ) || ( $attribute_key == 'active' && $attribute_value == '0') ){1537 $remove_from_web = true;1538 }1546 $hide_from_web = false; 1547 foreach( $product['attributes'] as $key => $value){ 1548 $value = (array)$value; 1549 if( isset($value['hide_from_web']) ){ 1550 $hide_from_web = $value['hide_from_web']; 1551 break; 1539 1552 } 1540 1553 } 1541 1554 1542 1555 // Delete producten met de optie "Hide form web" 1543 if( $ remove_from_web || isset($product['active']) && $product['active'] == '0'){1544 $post_id = $this->functions->custom_get_product_id_by_sku($product _change['id'], $product_change['sku']);1556 if( $hide_from_web || ( isset($product['active']) && $product['active'] == '0' ) ){ 1557 $post_id = $this->functions->custom_get_product_id_by_sku($product['id'], $product['sku']); 1545 1558 if (isset($post_id) && !empty($post_id)) { 1546 1559 $this->logging->log_file_write('GetProductRemoved | Product removed from webshop ' . $post_id); … … 1642 1655 } 1643 1656 1657 update_option('last_processed_changes_time', $new_processed_changes_time ); 1644 1658 } 1645 1659 -
extendago-wp-connection/trunk/includes/woocommerce/class-extendago-woocommerce-functions.php
r3176970 r3208968 15 15 add_action( 'woocommerce_process_product_meta', array($this, 'woocommerce_extendago_product_fields_save') ); 16 16 17 add_filter('bulk_actions-edit-product', array($this, 'add_extenda_bulk_action'), 10, 1); 18 add_filter('handle_bulk_actions-edit-product', array($this, 'handle_extenda_bulk_action'), 10, 3); 19 add_action('admin_notices', array($this, 'show_extenda_bulk_succes_message')); 17 20 18 21 add_action( 'woocommerce_order_status_changed', array($this, 'process_cancelled_order_products'), 10, 4 ); 22 } 23 24 public function add_extenda_bulk_action($bulk_actions){ 25 $bulk_actions['extenda-export'] = 'Bulk export | Woocommerce --> Extenda GO'; 26 return $bulk_actions; 27 } 28 29 public function handle_extenda_bulk_action($redirect_url, $action, $product_ids){ 30 if ($action == 'extenda-export' && !empty($product_ids) ) { 31 32 // Upload directory 33 $upload = wp_upload_dir(); 34 $upload_dir = $upload['basedir']; 35 $new_upload_dir = $upload_dir . '/extendago/exports'; 36 37 $logging = new ExtendaGo_WP_Connection_Logging(); 38 $logging->log_file_write( 'Manual | Manual triggered bulk synchronisation for ' .count($product_ids). ' products.'); 39 40 $extendago_costs_field = get_option('extendago_costs_field'); 41 42 foreach( $product_ids as $product_id ){ 43 $product = wc_get_product( $product_id ); 44 45 $product_data = array(); 46 47 if( $product->is_taxable() && empty($product->get_tax_class()) ){ 48 $product_tax_class = 'null'; 49 } 50 else{ 51 $product_tax_class = $product->get_tax_class(); 52 } 53 54 $vat_rate_id = ''; 55 $Extendago = new Extendago_Web_Api(); 56 $VatRates = $Extendago->CurlRequest("/vat_rates", "GET"); 57 foreach ($VatRates as $VatRate){ 58 $value = get_option($VatRate['id']); 59 if( $value == $product_tax_class ){ 60 $vat_rate_id = $VatRate['id']; 61 break; 62 } 63 } 64 65 // Get Product General Info 66 $product_data['id'] = $product->get_id(); 67 $product_data['title'] = $product->get_name(); 68 $product_data['type'] = $product->get_type(); 69 $product_data['slug'] = $product->get_slug(); 70 $product_data['description'] = $product->get_description(); 71 $product_data['short_description'] = $product->get_short_description(); 72 $product_data['sku'] = $product->get_sku(); 73 $product_data['vat_rate_id'] = $vat_rate_id; 74 75 $woocommerce_prices_include_tax = get_option('woocommerce_prices_include_tax'); 76 $woocommerce_calc_taxes = get_option('woocommerce_calc_taxes'); 77 if( $woocommerce_prices_include_tax == 'no' && $woocommerce_calc_taxes == 'yes' ){ 78 $default_tax = '0'; 79 $default_tax_rates = WC_Tax::get_rates_for_tax_class( $product_tax_class ); 80 foreach( $default_tax_rates as $default_tax_rate ){ 81 if( $default_tax_rate->tax_rate > $default_tax ){ 82 $default_tax = (int)$default_tax_rate->tax_rate; 83 } 84 } 85 86 // Get Product Prices 87 $product_data['price'] = ( $product->get_price() / 100 ) * ( $default_tax + 100 ); 88 89 $product_regular_price = $product->get_regular_price(); 90 if( isset($product_regular_price) && !empty($product_regular_price) ){ 91 $product_data['regular_price'] = ( $product_regular_price / 100 ) * ( $default_tax + 100 ); 92 } 93 else{ 94 $product_data['regular_price'] = $product_data['price']; 95 } 96 97 $product_sale_price = $product->get_sale_price(); 98 if( isset($product_sale_price) && !empty($product_sale_price) ){ 99 $product_data['sale_price'] = ( $product_sale_price / 100 ) * ( $default_tax + 100 ); 100 } 101 else { 102 $product_data['sale_price'] = ''; 103 } 104 } 105 else{ 106 // Get Product Prices 107 $product_data['price'] = $product->get_price(); 108 $product_data['regular_price'] = $product->get_regular_price(); 109 $product_data['sale_price'] = $product->get_sale_price(); 110 } 111 112 $product_attributes = $product->get_attributes(); 113 if( isset($product_attributes) && !empty($product_attributes) ){ 114 foreach( $product_attributes as $product_attribute_name => $product_attribute ){ 115 $product_data['attributes'][$product_attribute_name] = $product->get_attribute( $product_attribute_name ); 116 } 117 } 118 119 if( $product_data['type'] == 'variable' ){ 120 $product_data['variations'] = array(); 121 $product_variations = $product->get_children(); 122 if( isset($product_variations) && !empty($product_variations) ){ 123 foreach( $product_variations as $product_variation_id ){ 124 $variation_meta = get_post_meta($product_variation_id); 125 $product_variant_name = array(); 126 foreach ($product_data['attributes'] as $attribute => $attribute_value) { 127 if (isset($variation_meta['attribute_' . $attribute])) { 128 $term_slug = $variation_meta['attribute_' . $attribute][0]; 129 $term_object = get_term_by('slug', $term_slug, $attribute); 130 $product_variant_name[] = $term_object->name; 131 } 132 } 133 134 if( isset($product_variant_name) ) { 135 136 $product_variant_name = implode('_', $product_variant_name); 137 138 // Get Product Prices 139 $variation_price = $variation_meta['_regular_price'][0]; 140 $variation_regular_price = $variation_meta['_regular_price'][0]; 141 $variation_sale_price = $variation_meta['_sale_price'][0]; 142 143 // Check for prices exclude vat 144 if( $woocommerce_prices_include_tax == 'no' && $woocommerce_calc_taxes == 'yes' ){ 145 146 $variation_price = ( $variation_price / 100 ) * ( $default_tax + 100 ); 147 148 if( isset($variation_regular_price) && !empty($variation_regular_price) ){ 149 $variation_regular_price = ( $variation_regular_price / 100 ) * ( $default_tax + 100 ); 150 } 151 152 if( isset($variation_sale_price) && !empty($variation_sale_price) ){ 153 $variation_sale_price = ( $variation_sale_price / 100 ) * ( $default_tax + 100 ); 154 } 155 } 156 157 $variant_data = array( 158 'id' => $product_variation_id, 159 'product_variant_name' => $product_variant_name, 160 'stock' => $variation_meta['_stock'][0], 161 'sku' => $variation_meta['_sku'][0], 162 'regular_price' => $variation_regular_price, 163 'retail_price' => $variation_price, 164 'cost_price' => 0, 165 'sale_price' => $variation_sale_price, 166 'vat_rate_id' => $vat_rate_id, 167 ); 168 169 // Costs of goods 170 if ( isset($extendago_costs_field) && !empty($extendago_costs_field) ) { 171 $cost_price = get_post_meta($product_variation_id, $extendago_costs_field, true); 172 173 $cost_price = str_replace(',', '.', $cost_price); 174 $cost_price = preg_replace("/[^0-9\.]/", "", $cost_price); 175 $cost_price = str_replace('.', '',substr($cost_price, 0, -3)) . substr($cost_price, -3); 176 177 if( !empty($cost_price) ) { 178 $variant_data['cost_price'] = number_format(((float)$cost_price * 100), 0, '.', ''); // price in cents 179 } 180 } 181 182 $product_data['variations'][] = $variant_data; 183 184 } 185 } 186 } 187 188 } 189 else{ 190 $product_data['quantity'] = $product->get_stock_quantity(); 191 $product_data['status'] = $product->get_stock_status(); 192 } 193 194 // Costs of goods 195 if ( isset($extendago_costs_field) && !empty($extendago_costs_field) ) { 196 $cost_price = get_post_meta($product->get_id(), $extendago_costs_field, true); 197 198 $cost_price = str_replace(',', '.', $cost_price); 199 $cost_price = preg_replace("/[^0-9\.]/", "", $cost_price); 200 $cost_price = str_replace('.', '',substr($cost_price, 0, -3)) . substr($cost_price, -3); 201 202 if( !empty($cost_price) ) { 203 $product_data['cost_price'] = number_format(((float)$cost_price * 100), 0, '.', ''); // price in cents 204 } 205 } 206 207 $product_categories = wp_get_object_terms($product_data['id'], 'product_cat'); 208 if( isset($product_categories) && !empty($product_categories) ){ 209 foreach( $product_categories as $product_category ){ 210 $product_data['categories'][$product_category->term_id] = array( 211 'name' => $product_category->name, 212 'slug' => $product_category->slug, 213 'description' => $product_category->description, 214 'parent' => $product_category->parent, 215 ); 216 } 217 } 218 219 // Get Product Images 220 $thumbnail_id = $product->get_image_id(); 221 if( isset($thumbnail_id) && !empty($thumbnail_id) ){ 222 $product_data['image'] = get_attached_file($thumbnail_id, true); 223 } 224 $gallery_image_ids = $product->get_gallery_image_ids(); 225 if( isset($gallery_image_ids) && !empty($gallery_image_ids) ){ 226 foreach( $gallery_image_ids as $gallery_image_id ){ 227 $product_data['gallery'][] = get_attached_file($gallery_image_id, true); 228 } 229 } 230 $products[] = $product_data; 231 } 232 233 $batch = 0; 234 $i = 0; 235 $total_products = count($products); 236 $products_array = array(); 237 foreach( $products as $product ) { 238 239 $products_array[ $product['id'] ] = $product; 240 241 // 50 producten per batch 242 if ( ( ( $i + 1 ) % 50 == 0 ) || $i + 1 == $total_products ) { 243 244 // Save and encode array to json 245 $products_array = json_encode($products_array); 246 247 $success = file_put_contents($new_upload_dir . '/products_batch_' . $batch . '.json', $products_array); 248 if( $success === FALSE ){ 249 $logging->log_file_write( 'ERROR | Product batch ' .$batch. 'not created!' ); 250 } 251 252 $products_array = array(); 253 $batch++; 254 } 255 256 $i++; 257 } 258 259 $redirect_url = add_query_arg('extenda-export-started', count($product_ids), $redirect_url); 260 } 261 return $redirect_url; 262 } 263 264 public function show_extenda_bulk_succes_message(){ 265 if (!empty($_REQUEST['extenda-export-started'])) { 266 $num_changed = (int) $_REQUEST['extenda-export-started']; 267 printf('<div id="message" class="updated notice is-dismissable"><p>Bulk synchronisation started for %d products.</p></div>', $num_changed); 268 } 19 269 } 20 270 -
extendago-wp-connection/trunk/readme.txt
r3176970 r3208968 4 4 Tags: extendago, extenda, woocommerce, arture, POS, 5 5 Requires at least: 6.0 6 Tested up to: 6. 6.26 Tested up to: 6.7.1 7 7 Stable tag: 1.5.6 8 8 Requires PHP: 7.4 … … 31 31 == Changelog == 32 32 33 = 1.5.7 = 34 * HPOS compatibility 35 * Fallback with Product Query 36 * Bulk export action 37 33 38 = 1.5.6 = 34 39 * New feature for Extenda product filters as Woocommerce attributes
Note: See TracChangeset
for help on using the changeset viewer.