Changeset 3451370
- Timestamp:
- 02/01/2026 12:48:20 PM (2 weeks ago)
- Location:
- philia-integration
- Files:
-
- 17 added
- 4 edited
-
tags/1.13 (added)
-
tags/1.13/assets (added)
-
tags/1.13/assets/philia-api-settings.js (added)
-
tags/1.13/assets/philia-api-sync.js (added)
-
tags/1.13/assets/philia-login-redirect.js (added)
-
tags/1.13/includes (added)
-
tags/1.13/includes/class-api-log.php (added)
-
tags/1.13/includes/class-api-settings.php (added)
-
tags/1.13/includes/class-core-api.php (added)
-
tags/1.13/includes/class-login-redirect.php (added)
-
tags/1.13/includes/class-philia-wallet.php (added)
-
tags/1.13/includes/class-webhook-sender.php (added)
-
tags/1.13/includes/templates (added)
-
tags/1.13/includes/templates/wc-endpoint-wallet.php (added)
-
tags/1.13/includes/templates/woo-wallet-partial-payment.php (added)
-
tags/1.13/philia-integration.php (added)
-
tags/1.13/readme.txt (added)
-
trunk/includes/class-api-settings.php (modified) (8 diffs)
-
trunk/includes/class-webhook-sender.php (modified) (6 diffs)
-
trunk/philia-integration.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
philia-integration/trunk/includes/class-api-settings.php
r3402346 r3451370 115 115 __('Phone Meta Key', 'philia-integration'), 116 116 array($this, 'phone_meta_field_callback'), 117 'philia-api-settings', 118 'philia_api_settings_section' 119 ); 120 121 // Order Status for Sync 122 add_settings_field( 123 'order_sync_status', 124 __('Order Status for Synchronization', 'philia-integration'), 125 array($this, 'order_sync_status_field_callback'), 117 126 'philia-api-settings', 118 127 'philia_api_settings_section' … … 179 188 if( isset( $settings['api_url'] ) && !empty( $settings['api_url'] ) && isset( $settings['api_key'] ) && !empty( $settings['api_key'] ) ) 180 189 { 181 $res = self::create_and_send_woocommerce_api_key( $settings['api_url'] , $settings['api_key'], $settings['phone_meta'], $settings['data_sync'] );190 $res = self::create_and_send_woocommerce_api_key( $settings['api_url'] , $settings['api_key'], $settings['phone_meta'], $settings['data_sync'], $settings['order_sync_status'] ); 182 191 if( wp_remote_retrieve_response_code( $res ) == 200 ) 183 192 { … … 293 302 294 303 /** 304 * Outputs the dropdown for order status synchronization. 305 * 306 * @return void 307 */ 308 public function order_sync_status_field_callback() 309 { 310 $settings = get_option('philia_api_settings'); 311 312 // Get the selected order status, default to 'completed' 313 $selected_status = isset($settings['order_sync_status']) ? $settings['order_sync_status'] : 'completed'; 314 315 // Get all available WooCommerce order statuses 316 $order_statuses = wc_get_order_statuses(); 317 318 echo '<select name="philia_api_settings[order_sync_status]" id="philia-order-sync-status">'; 319 foreach ($order_statuses as $status_key => $status_label) { 320 // Remove 'wc-' prefix from status key 321 $status_value = str_replace('wc-', '', $status_key); 322 $selected = selected($selected_status, $status_value, false); 323 echo '<option value="' . esc_attr($status_value) . '" ' . $selected . '>' . esc_html($status_label) . '</option>'; 324 } 325 echo '</select>'; 326 ?> 327 <p class="description"><?php echo esc_attr__('Select which order status should trigger synchronization with Philia. Only orders with this status will be sent.', 'philia-integration'); ?></p> 328 <?php 329 } 330 331 /** 295 332 * Checkbox field to show "Login to Philia" in My Account menu. 296 333 */ … … 466 503 } 467 504 505 // Sanitize order sync status 506 if (isset($input['order_sync_status'])) { 507 $sanitized_input['order_sync_status'] = sanitize_text_field($input['order_sync_status']); 508 } else { 509 // Default to 'completed' if not set 510 $sanitized_input['order_sync_status'] = 'completed'; 511 } 512 468 513 return $sanitized_input; 469 514 } … … 493 538 * @return array|WP_Error The response from the remote server or WP_Error on failure. 494 539 */ 495 public static function create_and_send_woocommerce_api_key($philia_url, $philia_key, $philia_phone_key, $philia_data_sync )540 public static function create_and_send_woocommerce_api_key($philia_url, $philia_key, $philia_phone_key, $philia_data_sync, $order_sync_status = NULL) 496 541 { 497 542 if (!class_exists('WooCommerce')) { … … 549 594 550 595 $body = json_encode([ 551 'philia_url' => $philia_url, 552 'url' => get_site_url(), 553 'key' => $consumer_key, 554 'secret' => $consumer_secret, 555 'type' => 'woocommerce', 556 'version' => $version, 557 'rest_prefix' => $rest_prefix, // Include the current REST API prefix, 558 'data_sync' => $philia_data_sync, 559 'extra_field_1' => $philia_phone_key 596 'philia_url' => $philia_url, 597 'url' => get_site_url(), 598 'key' => $consumer_key, 599 'secret' => $consumer_secret, 600 'type' => 'woocommerce', 601 'version' => $version, 602 'plugin_version' => PHILIA_PLUGIN_VERSION, 603 'order_sync_status' => ( isset( $order_sync_status ) && ! is_null( $order_sync_status ) ) ? sanitize_text_field( $order_sync_status ) : 'completed', 604 'rest_prefix' => $rest_prefix, // Include the current REST API prefix, 605 'data_sync' => $philia_data_sync, 606 'extra_field_1' => $philia_phone_key 560 607 ]); 561 608 … … 643 690 $response = wp_remote_post($philia_settings['api_url'].'/v1/api/integration/wordpress/connection-test', [ 644 691 'method' => 'GET', 645 'body' => $body,646 692 'headers' => [ 647 693 'Content-Type' => 'application/json', … … 808 854 } 809 855 856 /** 857 * Get the order status that should trigger synchronization. 858 * 859 * @return string The order status slug (e.g., 'completed', 'processing') 860 */ 861 public static function get_order_sync_status() 862 { 863 // Get the entire settings array from the database 864 $settings = get_option( 'philia_api_settings' ); 865 866 // Return the saved status or default to 'completed' 867 return isset( $settings['order_sync_status'] ) ? $settings['order_sync_status'] : 'completed'; 868 } 869 810 870 } 811 871 -
philia-integration/trunk/includes/class-webhook-sender.php
r3426712 r3451370 89 89 add_filter( 'woocommerce_rest_prepare_product_object', array( $this, 'add_philia_id_to_product_response' ), 10, 3 ); 90 90 add_filter( 'woocommerce_rest_prepare_product_variation_object', array( $this, 'add_philia_id_to_product_response' ), 10, 3 ); 91 add_filter( 'woocommerce_rest_pre_insert_shop_coupon_object', array($this, 'map_coupons_product_ids_before_insert'), 10, 3 ); 91 92 92 93 // order status completed … … 203 204 // Prepare event-specific data based on the triggered action, formatted as per WC REST API 204 205 $event_data = $this->prepare_event_data($current_action, $args); 205 error_log("CURRENT ACTION: " . $current_action);206 error_log("EVENT DATA: " . print_r($event_data, true ) );207 206 208 207 // If no relevant data could be prepared, log and exit … … 251 250 $response_code = wp_remote_retrieve_response_code($response); 252 251 $response_body = wp_remote_retrieve_body($response); 253 error_log("Philia_Webhook_Sender: RESPONSE for {$current_action} - Code: {$response_code}, Body: " . $response_body);252 //error_log("Philia_Webhook_Sender: RESPONSE for {$current_action} - Code: {$response_code}, Body: " . $response_body); 254 253 255 254 // Log if the webhook did not return a successful 2xx status code … … 630 629 $order = wc_get_order($order_id); 631 630 if ($order) { 632 // ONLY proceed if the order status is 'completed' 633 if ($order->get_status() !== 'completed') { 634 error_log("Philia_Webhook_Sender: Order ID {$order_id} status is '{$order->get_status()}', not 'completed'. Skipping webhook send."); 631 // Get the configured order status for synchronization (default: 'completed') 632 $sync_status = Philia_API_Settings::get_order_sync_status(); 633 634 // ONLY proceed if the order status matches the configured sync status 635 if ($order->get_status() !== $sync_status) { 636 error_log("Philia_Webhook_Sender: Order ID {$order_id} status is '{$order->get_status()}', not '{$sync_status}'. Skipping webhook send."); 635 637 return []; // Return empty data to prevent sending webhook 636 638 } … … 962 964 } 963 965 964 965 966 /** 966 967 * Add Philia Product ID to product REST API responses … … 1166 1167 return $coupon; 1167 1168 } 1169 1170 /** 1171 * Map coupon product IDs before inserting/updating via REST API. 1172 * Supports mapping by product ID, SKU, or Philia Product ID (_philia_product_id). 1173 * 1174 * @param WC_Coupon $coupon The coupon object being created or updated. 1175 * @param WP_REST_Request $request The REST API request object. 1176 * @param bool $creating Whether this is a create operation (true) or update (false). 1177 * @return WC_Coupon The modified coupon object. 1178 */ 1179 public function map_coupons_product_ids_before_insert($coupon, $request, $creating) 1180 { 1181 // Check for custom REST parameter to enable product ID rewriting 1182 $flag = $request->get_param( 'rewrite_product_ids' ); 1183 1184 if ( empty( $flag ) ) { 1185 return $coupon; 1186 } 1187 1188 // Get existing product_ids from request 1189 $product_ids = $request->get_param( 'product_ids' ); 1190 1191 if ( ! is_array( $product_ids ) ) { 1192 return $coupon; 1193 } 1194 1195 /** 1196 * Map incoming product IDs to actual WooCommerce product IDs 1197 * Supports three methods: 1198 * 1. Direct product ID (numeric) 1199 * 2. SKU lookup 1200 * 3. Philia Product ID (_philia_product_id meta field) 1201 */ 1202 $mapped_ids = []; 1203 1204 foreach ( $product_ids as $identifier ) 1205 { 1206 $found_id = null; 1207 1208 // Method 1: If input is numeric and a valid product, use it directly 1209 if ( is_numeric( $identifier ) && get_post_type( $identifier ) === 'product' ) { 1210 $found_id = (int) $identifier; 1211 } 1212 1213 // Method 2: Try to find by SKU 1214 elseif ( ! is_numeric( $identifier ) ) { 1215 $product_id = wc_get_product_id_by_sku( $identifier ); 1216 if ( $product_id ) { 1217 $found_id = (int) $product_id; 1218 } 1219 } 1220 1221 // Method 3: If not found yet, try to find by Philia Product ID 1222 if ( ! $found_id ) { 1223 $found_id = $this->get_product_id_by_philia_id( $identifier ); 1224 } 1225 1226 // Add to mapped IDs if found 1227 if ( $found_id ) { 1228 $mapped_ids[] = $found_id; 1229 } 1230 } 1231 1232 // Remove duplicates and invalid IDs 1233 $mapped_ids = array_values( array_unique( array_filter( $mapped_ids ) ) ); 1234 1235 // Overwrite coupon product_ids with mapped values 1236 $coupon->set_product_ids( $mapped_ids ); 1237 1238 return $coupon; 1239 } 1168 1240 1169 1241 /** -
philia-integration/trunk/philia-integration.php
r3426712 r3451370 3 3 * Plugin Name: Philia Integration with WooCommerce 4 4 * Description: Sending Users, Products, Categories and invoices from WooCommerce to Philia and Receive Coupons and Cashback from Philia 5 * Version: 1.1 25 * Version: 1.13 6 6 * Author: Philia 7 7 * Author URI: https://fa.philia.vip … … 17 17 18 18 // Define constants for plugin directory, URL, and table prefix. 19 define('PHILIA_PLUGIN_VERSION', '1.1 2');19 define('PHILIA_PLUGIN_VERSION', '1.13'); 20 20 define('PHILIA_PLUGIN_DIR', plugin_dir_path(__FILE__)); 21 21 define('PHILIA_PLUGIN_URL', plugin_dir_url(__FILE__)); -
philia-integration/trunk/readme.txt
r3426712 r3451370 4 4 Requires at least: 6.0 5 5 Tested up to: 6.9 6 Stable tag: 1.1 26 Stable tag: 1.13 7 7 License: GPL-2.0+ 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 45 45 46 46 == Changelog == 47 48 = 1.13 = 49 * Added Order Status for Synchronization 50 51 = 1.12.1 = 52 * Bugs fixes and improvements 47 53 48 54 = 1.12 =
Note: See TracChangeset
for help on using the changeset viewer.