Changeset 3453301
- Timestamp:
- 02/03/2026 09:11:17 PM (8 weeks ago)
- Location:
- meliconnect/trunk
- Files:
-
- 6 edited
-
includes/Core/ApiManager.php (modified) (2 diffs)
-
includes/Core/CronManager.php (modified) (3 diffs)
-
includes/Core/Helpers/Helper.php (modified) (1 diff)
-
includes/Modules/Importer/Services/WooCommerceProductCreationService.php (modified) (5 diffs)
-
meliconnect.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
meliconnect/trunk/includes/Core/ApiManager.php
r3372090 r3453301 9 9 use Meliconnect\Meliconnect\Core\Helpers\Helper; 10 10 use Meliconnect\Meliconnect\Core\Models\UserConnection; 11 use Meliconnect\Meliconnect\Modules\Importer\Services\ProductDataFacade; 12 use Meliconnect\Meliconnect\Modules\Importer\Services\WooCommerceProductAdapter; 13 use Meliconnect\Meliconnect\Modules\Importer\Services\WooCommerceProductCreationService; 11 14 12 15 class ApiManager { … … 41 44 ) 42 45 ); 46 47 register_rest_route( 48 'meliconnect/v1', 49 '/sync/product', 50 array( 51 'methods' => 'POST', 52 'callback' => array( $this, 'meliconnect_sync_product_callback' ), 53 //'permission_callback' => [ ApiAuth::class, 'authorize' ], 54 'permission_callback' => '__return_true', 55 ) 56 ); 43 57 } 58 59 public static function meliconnect_sync_product_callback( $request ) 60 { 61 $meli_listing_id = sanitize_text_field( $request->get_param( 'meli_listing_id' ) ); 62 $seller_id = sanitize_text_field( $request->get_param( 'seller_id' ) ); 63 64 Helper::logData( 65 sprintf( 66 'Sync product request: listing=%s seller=%s', 67 $meli_listing_id, 68 $seller_id 69 ), 70 'sync_product_callback' 71 ); 72 73 if ( empty( $meli_listing_id ) || empty( $seller_id ) ) { 74 return new \WP_Error( 75 'invalid_payload', 76 'Missing parameters', 77 [ 'status' => 400 ] 78 ); 79 } 80 81 try { 82 83 /* ---- */ 84 $woo_product_id = Helper::meliconnect_find_product_by_listing_id( $meli_listing_id ); 85 86 if(! $woo_product_id ) { 87 Helper::logData( 'Product not found: ' . $meli_listing_id, 'sync_product_callback' ); 88 89 return new \WP_Error( 90 'product_not_found', 91 'Product not found', 92 [ 'status' => 404 ] 93 ); 94 } 95 96 Helper::logData( 'Product found: ' . $woo_product_id, 'sync_product_callback' ); 97 98 $template_id = get_post_meta($woo_product_id,'meliconnect_asoc_template_id',true ) ?? null; 99 100 if ( empty( $template_id ) ) { 101 Helper::logData( 102 'Template not found for product ' . $woo_product_id, 103 'sync_product_callback' 104 ); 105 } 106 107 $wooCommerceAdapter = new WooCommerceProductAdapter(); 108 $productCreationService = new WooCommerceProductCreationService(); 109 $productDataFacade = new ProductDataFacade( $wooCommerceAdapter, $productCreationService ); 110 111 112 // 2- Format items data to send, Send data to API server and Get response and process response creating or updating items in WooCommerce 113 $productDataFacade->importAndCreateProduct( $meli_listing_id, $seller_id, $template_id, $woo_product_id ); 114 /* ---- */ 115 116 return rest_ensure_response([ 117 'success' => true, 118 'meli_listing_id' => $meli_listing_id, 119 'woo_product_id' => $woo_product_id 120 ]); 121 122 } catch ( \Throwable $e ) { 123 124 125 Helper::logData( 'Sync product failed: ' . $e->getMessage() . ' On listing: ' . $meli_listing_id, 'sync_product_callback' ); 126 127 return new \WP_Error( 128 'sync_failed', 129 'Could not sync product', 130 [ 'status' => 500 ] 131 ); 132 } 133 } 44 134 45 135 // Callback del endpoint -
meliconnect/trunk/includes/Core/CronManager.php
r3439817 r3453301 240 240 $lock_acquired = false; 241 241 242 Helper::logData(242 /* Helper::logData( 243 243 'CUSTOM IMPORT CRON START PID ' . getmypid(), 244 244 'custom-import' 245 ); 245 ); */ 246 246 247 247 try { … … 267 267 268 268 if ( empty($items) ) { 269 Helper::logData('No pending items. Import finished.', 'custom-import');269 /* Helper::logData('No pending items. Import finished.', 'custom-import'); */ 270 270 return; 271 271 } … … 361 361 } 362 362 363 Helper::logData(363 /* Helper::logData( 364 364 'CUSTOM IMPORT CRON END', 365 365 'custom-import' 366 ); 366 ); */ 367 367 } 368 368 } -
meliconnect/trunk/includes/Core/Helpers/Helper.php
r3439817 r3453301 811 811 } 812 812 } 813 814 public static function meliconnect_find_product_by_listing_id( string $listingId ): ?int 815 { 816 global $wpdb; 817 818 $postId = $wpdb->get_var( 819 $wpdb->prepare( 820 " 821 SELECT post_id 822 FROM {$wpdb->postmeta} 823 WHERE meta_key = 'meliconnect_meli_listing_id' 824 AND meta_value = %s 825 LIMIT 1 826 ", 827 $listingId 828 ) 829 ); 830 831 return $postId ? (int) $postId : null; 832 } 833 834 public static function meliconnect_convert_weight_to_store_unit( $grams ) { 835 $unit = get_option( 'woocommerce_weight_unit', 'kg' ); 836 837 return match ( $unit ) { 838 'kg' => $grams / 1000, 839 'g' => $grams, 840 'lbs'=> $grams * 0.00220462, 841 'oz' => $grams * 0.035274, 842 default => $grams, 843 }; 844 } 845 846 public static function meliconnect_convert_dimension_to_store_unit( $cm ) { 847 $unit = get_option( 'woocommerce_dimension_unit', 'cm' ); 848 849 return match ( $unit ) { 850 'cm' => $cm, 851 'm' => $cm / 100, 852 'mm' => $cm * 10, 853 'in' => $cm * 0.393701, 854 default => $cm, 855 }; 856 } 813 857 } -
meliconnect/trunk/includes/Modules/Importer/Services/WooCommerceProductCreationService.php
r3439817 r3453301 195 195 // Dimensiones 196 196 if ( isset( $product_data['weight'] ) && $product_data['weight'] !== false ) { 197 $woo_product->set_weight( $product_data['weight'] ); 197 $woo_product->set_weight( 198 Helper::meliconnect_convert_weight_to_store_unit( $product_data['weight'] ) 199 ); 198 200 } else { 199 201 Helper::logData( 'Weight ignored by settings', 'custom-import' ); … … 201 203 202 204 if ( isset( $product_data['length'] ) && $product_data['length'] !== false ) { 203 $woo_product->set_length( $product_data['length'] ); 205 $woo_product->set_length( 206 Helper::meliconnect_convert_dimension_to_store_unit( $product_data['length'] ) 207 ); 204 208 } else { 205 209 Helper::logData( 'Length ignored by settings', 'custom-import' ); … … 207 211 208 212 if ( isset( $product_data['width'] ) && $product_data['width'] !== false ) { 209 $woo_product->set_width( $product_data['width'] ); 213 $woo_product->set_width( 214 Helper::meliconnect_convert_dimension_to_store_unit( $product_data['width'] ) 215 ); 210 216 } else { 211 217 Helper::logData( 'Width ignored by settings', 'custom-import' ); … … 213 219 214 220 if ( isset( $product_data['height'] ) && $product_data['height'] !== false ) { 215 $woo_product->set_height( $product_data['height'] ); 221 $woo_product->set_height( 222 Helper::meliconnect_convert_dimension_to_store_unit( $product_data['height'] ) 223 ); 216 224 } else { 217 225 Helper::logData( 'Height ignored by settings', 'custom-import' ); … … 594 602 $log_text .= "\n\n\n"; 595 603 596 / / Helper::logData($log_text, 'custom-import');604 /* Helper::logData($log_text, 'custom-import'); */ 597 605 598 606 return $productAttributes; -
meliconnect/trunk/meliconnect.php
r3439817 r3453301 4 4 Plugin URI: https://mercadolibre.meliconnect.com/ 5 5 Description: WooCommerce & Mercado Libre integration to import, export, and synchronize products between your WooCommerce store and Mercado Libre accounts. 6 Version: 1. 4.06 Version: 1.6.0 7 7 Author: meliconnect 8 8 Text Domain: meliconnect … … 26 26 * Define constantes del plugin 27 27 */ 28 define( 'MELICONNECT_VERSION', '1. 4.0' );28 define( 'MELICONNECT_VERSION', '1.6.0' ); 29 29 define( 'MELICONNECT_DATABASE_VERSION', '1.1.1' ); 30 30 define( 'MELICONNECT_TEXTDOMAIN', 'meliconnect' ); -
meliconnect/trunk/readme.txt
r3439817 r3453301 6 6 Requires PHP: 8.0 7 7 Tested up to: 6.9 8 Stable tag: 1. 4.08 Stable tag: 1.6.0 9 9 License: GPLv3 10 10 License URI: https://www.gnu.org/licenses/gpl-3.0.html
Note: See TracChangeset
for help on using the changeset viewer.