Changeset 2917680
- Timestamp:
- 05/26/2023 09:55:51 AM (3 years ago)
- Location:
- extendago-wp-connection/trunk
- Files:
-
- 6 edited
-
extendago-wp-connection.php (modified) (1 diff)
-
includes/admin/class-extendago-wp-connection-admin.php (modified) (4 diffs)
-
includes/api/class-extendago-web-api.php (modified) (2 diffs)
-
includes/cronjob/class-extendago-cronjob-functions.php (modified) (6 diffs)
-
includes/woocommerce/class-extendago-woocommerce-functions.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
extendago-wp-connection/trunk/extendago-wp-connection.php
r2913155 r2917680 4 4 Plugin URI: http://www.arture.nl/extendago 5 5 Description: The Wordpress plugin for connecting Woocommerce with Extendago / Wallmob. Manage your products inside Extendago and let our connection do the magic. 6 Version: 1.3. 26 Version: 1.3.3 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
r2906999 r2917680 646 646 $web_api = new ExtendaGo_Web_Api(); 647 647 $extendago_shops = $web_api->listShops(); 648 648 649 if ( ! isset( $extendago_shops ) || empty( $extendago_shops ) ) { 649 650 echo '<div class="alert alert-warning" role="alert">' . __('Extendago shops unavailable. Check connection!', 'extendago-wp-connection-plugin') . '</div>'; … … 721 722 public function display_extendago_tax_rates_element(){ 722 723 723 global $woocommerce;724 725 724 if ( class_exists( 'WooCommerce' ) ) { 726 725 $extendago_api_username = get_option( 'extendago_api_username' ); … … 738 737 $tax_classes = WC_Tax::get_tax_classes(); // Retrieve all tax classes. 739 738 if ( !in_array( '', $tax_classes ) ) { // Make sure "Standard rate" (empty class name) is present. 740 array_unshift( $tax_classes, '' ); 741 } 739 array_unshift( $tax_classes, 'null' ); 740 } 741 742 742 foreach ( $tax_classes as $tax_class ) { // For each tax class, get all rates. 743 $taxes = WC_Tax::get_rates_for_tax_class( $tax_class ); 743 $taxes = WC_Tax::get_rates_for_tax_class($tax_class); 744 745 // Check for default/standaard tax class 746 if ($tax_class == 'null'){ 747 $default_tax = '0'; 748 foreach ($taxes as $default_tax_rate) { 749 if ($default_tax_rate->tax_rate > $default_tax) { 750 $default_tax = (int)$default_tax_rate->tax_rate; 751 } 752 } 753 } 754 744 755 $wc_tax_rates = array_merge( $wc_tax_rates, $taxes ); 745 756 } … … 783 794 </table> 784 795 <div class="info"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> 785 <?php echo __('Leave blank if you want to use the default VAT rate of Woocommerce .', 'extendago-wp-connection-plugin'); ?>796 <?php echo __('Leave blank if you want to use the default VAT rate of Woocommerce: ', 'extendago-wp-connection-plugin') . $default_tax . '%'; ?> 786 797 </div> 787 798 <?php -
extendago-wp-connection/trunk/includes/api/class-extendago-web-api.php
r2906999 r2917680 29 29 $url = $this->extendago_api_url . $request; 30 30 } 31 32 // echo '<pre>';33 // print_r($url . ' | ' .$method);34 // echo '<pre>';35 31 36 32 curl_setopt($ch, CURLOPT_URL, $url); … … 236 232 } 237 233 238 public function listStockChanges( $params = array() ) { 239 $Offset = 0; 240 $Limit = 250; 241 $HasMore = true; 242 $StockChanges = array(); 243 while ($HasMore) { 244 $HasMore = false; 245 $Results = $this->CurlRequest("/stock_events", "GET", array("limit" => $Limit, "offset" => $Offset)); 246 foreach ($Results as $Result) { 247 if (isset($Result['id'])) { 248 $StockChanges[] = $Result; 249 } 250 } 251 if (count($Results) == $Limit) { 252 $HasMore = true; 253 $Offset += $Limit; 254 } 255 } 234 public function listStockChanges() { 235 236 $last_processed_time = get_option('last_processed_time'); 237 if( isset($last_processed_time) ){ 238 $StockChanges = $this->CurlRequest("/stock_events", "GET", array("filters" => json_encode(array(array('property' =>'timestamp', 'comparator' => '>', 'value' => $last_processed_time))))); 239 } 240 else{ 241 $StockChanges = $this->CurlRequest("/stock_events", "GET", array("filters" => json_encode(array(array('property' =>'timestamp', 'comparator' => '>', 'value' => time()))))); 242 } 243 256 244 return $StockChanges; 257 245 } -
extendago-wp-connection/trunk/includes/cronjob/class-extendago-cronjob-functions.php
r2913183 r2917680 580 580 require_once(__DIR__ . "/../api/class-extendago-web-api.php"); 581 581 $Extendago = new Extendago_Web_Api(); 582 583 // Reason code Count is needed for stock_events and the ID is different foreach client :( 584 $reason_code_id = get_option( "reason_code_id" ); 585 if( !isset($reason_code_id) || empty($reason_code_id) ) { 586 587 $reason_codes = $Extendago->CurlRequest('/reason_codes', 'GET'); 588 foreach( $reason_codes as $reason_code ){ 589 590 if( $reason_code['name'] == 'Count' ){ 591 update_option('reason_code_id', $reason_code['id']); 592 $reason_code_id = $reason_code['id']; 593 break; 594 } 595 } 596 } 582 597 583 598 $stock_location = get_option( "extendago_location_id" ); … … 830 845 } 831 846 847 $stock_value = array( 848 'type_id' => '102', // Production 849 'description' => 'extendago_connect', 850 'timestamp' => (string)time(), 851 'stock_location_id' => $stock_location, 852 'reason_code_id' => $reason_code_id, // Count 853 ); 854 832 855 // Set stock values 833 856 if( isset($product['variations']) && !empty($product['variations']) ) { 834 857 foreach ($ProductResponse['product_variants'] as $index => $product_variant) { 835 858 $variation = $product['variations'][$index]; 859 836 860 $Response = $Extendago->CurlRequest('/stock_values?filter-product_variant_id='.$product_variant['id'], 'GET'); 837 $stock_value = array( 838 'id' => 'stock_value-'.$product_variant['id'], 839 'quantity' => $variation->stock, 840 'product_id' => $product['id'], 841 'product_variant_id' => $product_variant['id'], 842 'stock_location_id' => $stock_location 843 ); 861 862 $stock_value['reference_id'] = 'UpdateStock - webshop'; 863 $stock_value['stock_event_lines'] = json_encode( array( array( 864 'current_quantity' => $variation->stock, 865 'product_id' => $product['id'], 866 'product_variant_id' => $product_variant['id'], 867 'name' => $product_variant['title'], 868 'sku' => $product_variant['sku'], 869 ) 870 )); 844 871 845 872 if( !isset($variation->stock) || empty($variation->stock) ) { 846 873 $this->logging->log_file_write('EXPORT | Product variation ID ' . $product_variant['id'] . ' has no stock value!'); 847 874 } 848 else{ 849 $this->logging->log_file_write('EXPORT | Product variation ID ' . $product_variant['id'] . ' updated to stock: ' . $variation->stock); 850 } 851 852 if( empty($Response) || isset($Response['error']) ){ 853 $Response = $Extendago->CurlRequest('/stock_values', 'POST', $stock_value, false, true); 854 update_post_meta( $variation->id, 'extendago_size_id', $product_variant['id']); 855 } 856 else{ 857 $Response = $Extendago->CurlRequest('/stock_values/' . $Response[0]['id'], 'PATCH', $stock_value, false, true); 875 else { 876 877 if( !empty($Response) ){ 878 if( isset($Response[0]['quantity']) && $Response[0]['quantity'] != $product['quantity'] ){ 879 $Response = $Extendago->CurlRequest('/count_stock', 'POST', $stock_value, false, true); 880 $this->logging->log_file_write('EXPORT | Product variation ID ' .$product_variant['id']. ' updated to stock: ' .$variation->stock); 881 } 882 } 883 else{ 884 $Response = $Extendago->CurlRequest('/count_stock', 'POST', $stock_value, false, true); 885 $this->logging->log_file_write('EXPORT | Product variation ID ' .$product_variant['id']. ' set stock: ' .$variation->stock); 886 } 858 887 } 859 888 } … … 861 890 else{ 862 891 $Response = $Extendago->CurlRequest('/stock_values?filter-product_id='.$product['id'], 'GET'); 863 $stock_value = array( 864 'id' => 'stock_value-'.$product['id'], 865 'quantity' => $product['quantity'], 866 'product_id' => $product['id'], 867 'stock_location_id' => $stock_location 868 ); 869 870 $this->logging->log_file_write('EXPORT | Product ID ' .$product['id']. ' updated to stock: ' .$product['quantity']); 871 872 if( empty($Response) || isset($Response['error']) ){ 873 $Response = $Extendago->CurlRequest('/stock_values', 'POST', $stock_value, false, true); 892 893 $stock_value['reference_id'] = 'UpdateStock - webshop'; 894 $stock_value['stock_event_lines'] = json_encode( array( array( 895 'current_quantity' => (string)$product['quantity'], 896 'product_id' => (string)$product['id'], 897 'product_variant_id' => null, 898 'name' => $product['title'], 899 'sku' => (string)$product['sku'], 900 ) 901 ) ); 902 903 if( !empty($Response) ){ 904 if( isset($Response[0]['quantity']) && $Response[0]['quantity'] != $product['quantity'] ){ 905 $Response = $Extendago->CurlRequest('/count_stock', 'POST', $stock_value, false, true); 906 $this->logging->log_file_write('EXPORT | Product ID ' .$product['id']. ' updated to stock: ' .$product['quantity']); 907 } 874 908 } 875 909 else{ 876 $Response = $Extendago->CurlRequest('/stock_values/' . $Response[0]['id'], 'PATCH', $stock_value, false, true); 910 $Response = $Extendago->CurlRequest('/count_stock', 'POST', $stock_value, false, true); 911 $this->logging->log_file_write('EXPORT | Product ID ' .$product['id']. ' set stock: ' .$product['quantity']); 877 912 } 878 913 } … … 882 917 883 918 update_post_meta($product['id'], 'extendago_product_id', $ProductResponse['id']); 919 update_post_meta( $product['id'], 'latest_update', date('Y-m-d h:i') ); 884 920 885 921 // Save changes to temp dir … … 1352 1388 foreach ( $stock_change['stock_event_lines'] as $stock_event_line ) { 1353 1389 1354 if( $stock_event_line[' stock_event_lines']['name'] == 'CountStock of product' ){1390 if( $stock_event_line['name'] == 'CountStock of product' || $stock_change['reference_id'] == 'UpdateStock - webshop' ){ 1355 1391 continue; 1356 1392 } … … 1363 1399 $api_functions->extendago_update_wc_product_stock($stock_event_line); 1364 1400 } 1401 update_option('last_processed_time', $stock_change['timestamp']); 1365 1402 1366 1403 // The correctly processed products should be removed from the synchronization tables 1367 $web_api->deleteStockChange($stock_change['id']);1368 } 1369 } 1370 1371 $this->logging->log_file_write( 'ExtendaGo | Synchronise stock changes completed with '.$total_sychronized_stock_changes. ' products.' );1404 //$web_api->deleteStockChange($stock_change['id']); 1405 } 1406 1407 $this->logging->log_file_write( 'ExtendaGo | Synchronise stock changes completed with '.$total_sychronized_stock_changes. ' products.' ); 1408 } 1372 1409 } 1373 1410 -
extendago-wp-connection/trunk/includes/woocommerce/class-extendago-woocommerce-functions.php
r2906999 r2917680 112 112 { 113 113 114 // Check for real/maula post update 115 if( !isset($_POST) || empty($_POST) ){ 116 return; 117 } 118 114 119 $post = get_post($product_id); 115 120 … … 131 136 132 137 $Extendago = new Extendago_Web_Api(); 138 139 if( $product->is_taxable() && empty($product->get_tax_class()) ){ 140 $product_tax_class = 'null'; 141 } 142 else{ 143 $product_tax_class = $product->get_tax_class(); 144 } 145 146 $vat_rate_id = ''; 133 147 $VatRates = $Extendago->CurlRequest("/vat_rates", "GET"); 134 $vat_rate_id = '';135 148 foreach ($VatRates as $VatRate){ 136 149 $value = get_option($VatRate['id']); 137 if( $value == $product ->get_tax_class()){150 if( $value == $product_tax_class ){ 138 151 $vat_rate_id = $VatRate['id']; 139 152 break; … … 153 166 $product_data['vat_rate_id'] = $vat_rate_id; 154 167 155 // Get Product Prices 156 $product_data['price'] = $product->get_price(); 157 $product_data['regular_price'] = $product->get_regular_price(); 158 $product_data['sale_price'] = $product->get_sale_price(); 168 $woocommerce_prices_include_tax = get_option('woocommerce_prices_include_tax'); 169 $woocommerce_calc_taxes = get_option('woocommerce_calc_taxes'); 170 171 if( $woocommerce_prices_include_tax == 'no' && $woocommerce_calc_taxes == 'yes' ){ 172 $default_tax = '0'; 173 $default_tax_rates = WC_Tax::get_rates_for_tax_class( $product_tax_class ); 174 foreach( $default_tax_rates as $default_tax_rate ){ 175 if( $default_tax_rate->tax_rate > $default_tax ){ 176 $default_tax = (int)$default_tax_rate->tax_rate; 177 } 178 } 179 180 // Get Product Prices 181 $product_data['price'] = ( $product->get_price() / 100 ) * ( $default_tax + 100 ); 182 183 $product_regular_price = $product->get_regular_price(); 184 if( isset($product_regular_price) && !empty($product_regular_price) ){ 185 $product_data['regular_price'] = ( $product_regular_price / 100 ) * ( $default_tax + 100 ); 186 } 187 else{ 188 $product_data['regular_price'] = $product_data['price']; 189 } 190 191 $product_sale_price = $product->get_sale_price(); 192 if( isset($product_sale_price) && !empty($product_sale_price) ){ 193 $product_data['sale_price'] = ( $product_sale_price / 100 ) * ( $default_tax + 100 ); 194 } 195 else { 196 $product_data['sale_price'] = ''; 197 } 198 } 199 else{ 200 // Get Product Prices 201 $product_data['price'] = $product->get_price(); 202 $product_data['regular_price'] = $product->get_regular_price(); 203 $product_data['sale_price'] = $product->get_sale_price(); 204 } 159 205 160 206 $product_attributes = $product->get_attributes(); -
extendago-wp-connection/trunk/readme.txt
r2913155 r2917680 5 5 Requires at least: 6.0 6 6 Tested up to: 6.1.1 7 Stable tag: 1.3. 17 Stable tag: 1.3.3 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 30 30 31 31 == Changelog == 32 33 = 1.3.3 = 34 * Stock flow improvements with stock events register 35 * VAT check for shops using prices withour VAT and processing inside Extenda with VAT 32 36 33 37 = 1.3.2 =
Note: See TracChangeset
for help on using the changeset viewer.