Changeset 3019318
- Timestamp:
- 01/09/2024 01:50:48 PM (2 years ago)
- Location:
- extendago-wp-connection/trunk
- Files:
-
- 9 edited
-
extendago-wp-connection.php (modified) (1 diff)
-
includes/admin/class-extendago-wp-connection-admin.php (modified) (8 diffs)
-
includes/api/class-arture-web-api.php (modified) (1 diff)
-
includes/api/class-extendago-web-api-functions.php (modified) (3 diffs)
-
includes/api/class-extendago-web-api.php (modified) (1 diff)
-
includes/class-extendago-wp-connection.php (modified) (1 diff)
-
includes/cronjob/class-extendago-cronjob-functions.php (modified) (12 diffs)
-
includes/woocommerce/class-extendago-woocommerce-functions.php (modified) (14 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
extendago-wp-connection/trunk/extendago-wp-connection.php
r2985881 r3019318 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. 46 Version: 1.4.5 7 7 Author: Arture B.V. 8 8 Author URI: https://arture.nl/ -
extendago-wp-connection/trunk/includes/admin/class-extendago-wp-connection-admin.php
r2956645 r3019318 9 9 $extendago_api_username = get_option( 'extendago_api_username' ); 10 10 $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' ); 13 13 14 14 // Check if connection available … … 114 114 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'); 115 115 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'); 117 118 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'); 118 119 … … 141 142 register_setting('extendago_woocommerce_options', 'extendago_location_id'); 142 143 register_setting('extendago_woocommerce_options', 'extendago_wc_new_order'); 144 register_setting('extendago_woocommerce_options', 'extendago_costs_field'); 143 145 register_setting('extendago_woocommerce_options', 'extendago_click_and_collect'); 144 146 … … 278 280 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>'; 279 281 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 synch ornisation', '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>'; 281 283 echo '</ul>'; 282 284 } … … 812 814 ?> 813 815 <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' ); ?> 815 817 </label> 816 818 817 819 <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'); ?> 819 821 </div> 820 822 <?php … … 827 829 echo '<div class="alert alert-warning" role="alert">' . __( 'Woocommerce not activated!', 'extendago-wp-connection-plugin' ) . '</div>'; 828 830 } 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 829 850 } 830 851 … … 960 981 public function show_marketing_banners() 961 982 { 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 962 993 $banner_showed = get_option('orderpickingapp1'); 963 994 if( (isset($banner_showed) && !empty($banner_showed)) || isset($_GET['skip']) ){ … … 1009 1040 } 1010 1041 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 1011 1061 } -
extendago-wp-connection/trunk/includes/api/class-arture-web-api.php
r2930779 r3019318 117 117 } 118 118 119 p rivatefunction create_message($status, $message) {119 public function create_message($status, $message) { 120 120 // Check whether the values are entered 121 121 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 36 36 $post_id = $this->functions->custom_get_product_id_by_sku( $product['id'], $product['sku'] ); 37 37 38 // Delete producten met de optie "Hide form web"39 38 if( 40 39 isset($product['attributes'][1]->hide_from_web) && $product['attributes'][1]->hide_from_web == '1' … … 357 356 358 357 $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 } 359 364 360 365 // Save color as attribute … … 417 422 $product_attributes['supplier_reference'] = $Attribute; 418 423 } 419 420 424 421 425 // Save product variations -
extendago-wp-connection/trunk/includes/api/class-extendago-web-api.php
r2985881 r3019318 52 52 ); 53 53 } 54 55 //$Headers[] = 'Wm-Api-Version: 2'; 54 56 55 57 if ($AsMultipart) $Headers[] = 'Content-Type: multipart/form-data'; -
extendago-wp-connection/trunk/includes/class-extendago-wp-connection.php
r2941124 r3019318 73 73 $this->loader->add_action( 'add_meta_boxes', $woocommerce, 'register_plugin_metaboxes' ); 74 74 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 ); 76 76 77 77 // Logging -
extendago-wp-connection/trunk/includes/cronjob/class-extendago-cronjob-functions.php
r2985881 r3019318 138 138 } 139 139 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 146 140 // Process only shop/group specific products 147 141 if( isset($import_shop_products) && $import_shop_products && isset($extendago_shop_group_ids) ) { … … 243 237 } 244 238 245 public function woocommerce_extendago_sync( ){239 public function woocommerce_extendago_sync( $product_ids = array() ){ 246 240 247 241 // Upload directory … … 282 276 $args['post__in'] = array($_POST['product_id']); 283 277 } 278 elseif( isset($product_ids) && !empty($product_ids) ) { 279 $args['post__in'] = $product_ids; 280 } 284 281 285 282 $products_query = new WP_Query( $args ); … … 474 471 } 475 472 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 } 483 486 } 484 487 … … 642 645 return; 643 646 } 647 648 $extendago_costs_field = get_option('extendago_costs_field'); 644 649 645 650 natcasesort( $files ); … … 756 761 } 757 762 758 $ ExtendagoProductJSON['product_data'] = json_encode(array(763 $product_data = array( 759 764 array( 760 765 'id' => $product['id'], … … 769 774 'unit_id' => $unit_id 770 775 ) 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); 772 784 773 785 if( isset($product['variations']) && !empty($product['variations']) ) { … … 789 801 // First variation 790 802 if( $i == 1 ){ 791 $ ExtendagoProductJSON['product_data'] = json_encode(array(803 $product_variation_data = array( 792 804 array( 793 805 'id' => $product['id'], … … 802 814 'unit_id' => $unit_id 803 815 ) 804 )); 816 ); 817 818 $ExtendagoProductJSON['product_data'] = json_encode($product_variation_data); 805 819 } 806 820 … … 827 841 ); 828 842 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 829 848 $ExtendagoProductJSON['product_variants'][] = $product_variant; 830 849 } … … 869 888 } 870 889 } 871 872 890 873 891 if( empty($ProductResponse) || isset($ProductResponse['error']) ){ … … 1098 1116 1099 1117 $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 } 1100 1123 } 1101 1124 else{ -
extendago-wp-connection/trunk/includes/woocommerce/class-extendago-woocommerce-functions.php
r2956645 r3019318 15 15 add_action( 'woocommerce_process_product_meta', array($this, 'woocommerce_extendago_product_fields_save') ); 16 16 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 18 36 } 19 37 … … 132 150 } 133 151 152 $extendago_costs_field = get_option('extendago_costs_field'); 153 134 154 $product = wc_get_product($product_id); 135 155 … … 170 190 $product_data['vat_rate_id'] = $vat_rate_id; 171 191 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 172 197 $woocommerce_prices_include_tax = get_option('woocommerce_prices_include_tax'); 173 198 $woocommerce_calc_taxes = get_option('woocommerce_calc_taxes'); … … 275 300 } 276 301 277 $ product_data['variations'][]= array(302 $variant_data = array( 278 303 'id' => $product_variation_id, 279 304 'product_variant_name' => $product_variant_name, … … 285 310 'vat_rate_id' => $vat_rate_id, 286 311 ); 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; 287 319 } 288 320 } … … 440 472 } 441 473 442 public function create_extendago_new_order( $order_id, $response = false ) {474 public function create_extendago_new_order( $order_id, $response = false, $refund = false ) { 443 475 444 476 // Check if "New order" option is enabled … … 448 480 $web_api = new ExtendaGo_Web_Api(); 449 481 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 ) { 451 483 $order = new WC_Order( $order_id ); 452 484 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 } 454 491 455 492 // 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 } 459 498 } 460 499 … … 491 530 } 492 531 } 532 elseif( $refund ){ 533 $process_order = true; 534 $order_is_paid = true; 535 } 493 536 494 537 if( $process_order ){ … … 507 550 $data['timestamp'] = $order_date; 508 551 552 // Use the date of today when the refuns has been made 553 if( $refund ){ 554 $data['timestamp'] = time(); 555 } 556 509 557 $data['currency'] = $order->get_currency(); 510 //$data['email'] = $order_data['billing']['email']; // Uitgeschakeld gezien deze automatisch een mail verstuurd vanuit WallMob511 558 512 559 // Get customer by email … … 546 593 ); 547 594 $data['customer_id'] = $web_api->createCustomer($params); 548 //$data['customer_name'] = $params['name'];549 595 } 550 596 551 597 $data['is_paid'] = $order_is_paid; 598 599 // Compatibility for plugin "Aangepaste bestelnummers voor WooCommerce" 552 600 $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 554 606 $data['is_preorder'] = true; 555 607 556 608 $regular_order_total = 0; 557 $discount_amount = 0;558 609 foreach ($order->get_items() as $item_id => $item) { 559 610 … … 646 697 $order_line_item['total_line_amount'] = (int)($total_line_amount * 100 ); 647 698 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 648 706 $regular_order_total += number_format($retail_price * $item_data['quantity'], 3, '.', ''); 649 707 $order_line_item['vat_rate'] = '0.' . $vat_rate; // 0021 = 21% … … 767 825 } 768 826 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 769 833 $order_line_item['vat_rate'] = '0.' . $vat_rate; // 0021 = 21% 770 834 $data['order_line_items'][] = $order_line_item; … … 773 837 if( $click_and_collect_order == 'no' ) { 774 838 $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 } 784 862 } 785 863 … … 796 874 else{ 797 875 $message = 'OrderId processed: ' . $order_data['id']; 798 //update_post_meta($order_id, 'extendago_order_id', $results['id']);799 876 update_post_meta($order_id, 'order_returned_successfully_to_extendago', '1'); 800 877 update_post_meta($order_id, 'click_and_collect_order', $click_and_collect_order); -
extendago-wp-connection/trunk/readme.txt
r2985881 r3019318 4 4 Tags: extendago, extenda, woocommerce, arture, POS, 5 5 Requires at least: 6.0 6 Tested up to: 6. 3.07 Stable tag: 1.4. 46 Tested up to: 6.4.2 7 Stable tag: 1.4.5 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 31 31 == Changelog == 32 32 33 = 1.4.5 = 34 * New feature for processing costs price 35 33 36 = 1.4.4 = 34 37 * Flow optimalisation for export and stock changes
Note: See TracChangeset
for help on using the changeset viewer.