Changeset 3222670
- Timestamp:
- 01/15/2025 08:13:47 AM (14 months ago)
- Location:
- litcommerce/trunk
- Files:
-
- 4 edited
-
changelog.txt (modified) (1 diff)
-
litcommerce.php (modified) (10 diffs)
-
readme.txt (modified) (1 diff)
-
steps/SendWooCommerceKeys.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
litcommerce/trunk/changelog.txt
r3135220 r3222670 14 14 15 15 *Add: "Allows retaining the order number in WooCommerce." 16 17 = 1.2.0 2024-12-12 = 18 19 *Update: "Menu Page" 20 21 = 1.2.1 2024-12-25 = 22 23 *Fixed: "Menu Page" 24 25 = 1.2.2 2025-01-13 = 26 27 *Fixed: "Menu Page" 28 29 = 1.2.3 2025-01-15 = 30 31 *Add: "Api Add/Delete Image For Product" -
litcommerce/trunk/litcommerce.php
r3211347 r3222670 3 3 Plugin Name: LitCommerce 4 4 Description: Helps you easily integrate your WooCommerce store with LitCommerce. 5 Version: 1.2. 05 Version: 1.2.3 6 6 Author: LitCommerce 7 7 Author URI: https://litcommerce.com 8 8 License: GPL2 9 9 Text Domain: litcommerce 10 Requires Plugins: woocommerce 10 11 */ 11 12 … … 51 52 52 53 function is_multy_app(){ 53 if (is_plugin_active('litcommerce _feed/litcommerce_feed.php')) {54 if (is_plugin_active('litcommerce-feed/litcommerce-feed.php')) { 54 55 return true; 55 56 } … … 197 198 add_action('admin_menu', [$litcommercePlugin, 'registerPluginHooks']); 198 199 add_filter('woocommerce_rest_product_object_query', function ( array $args, \WP_REST_Request $request ) { 199 $modified_after = $request->get_param('modified_after');200 $modified_after = get_litc_params('modified_after'); 200 201 201 202 if (!$modified_after) { … … 213 214 ]; 214 215 foreach ($fields as $field => $param) { 215 if ( $request->get_param($param)) {216 $args[$field] = $request->get_param($param);216 if (get_litc_params($param)) { 217 $args[$field] = get_litc_params($param); 217 218 } 218 219 } … … 224 225 }, 10, 2); 225 226 add_filter('woocommerce_rest_shop_order_object_query', function ( array $args, \WP_REST_Request $request ) { 226 $modified_after = $request->get_param('modified_after');227 $modified_after = get_litc_params('modified_after'); 227 228 228 229 if (!$modified_after) { … … 240 241 ]; 241 242 foreach ($fields as $field => $param) { 242 if ( $request->get_param($param)) {243 $args[$field] = $request->get_param($param);243 if (get_litc_params($param)) { 244 $args[$field] = get_litc_params($param); 244 245 } 245 246 } … … 370 371 add_filter('woocommerce_shop_order_search_fields', 'litc_shop_order_meta_search_fields', 10, 1); 371 372 function litc_woocommerce_rest_prepare_product_object( $response, $object, $request ) { 372 if ( $request->get_param("custom_currency") == 1) {373 if (get_litc_params("custom_currency") == 1) { 373 374 $meta = get_post_meta($object->get_id()); 374 375 foreach ($meta as $key => $value) { … … 379 380 } 380 381 381 if ( $request->get_param("get_terms")) {382 $terms = explode(',', $request->get_param("get_terms"));382 if (get_litc_params("get_terms")) { 383 $terms = explode(',', get_litc_params("get_terms")); 383 384 foreach ($terms as $term) { 384 385 $terms_data = wp_get_post_terms($object->get_id(), $term); … … 453 454 function get_litc_params($key) 454 455 { 455 if(isset($_GET[$key])) { 456 return $_GET[$key]; 457 } 458 return null; 456 $value = filter_input( INPUT_GET, $key, FILTER_SANITIZE_STRING ); 457 if(!$value){ 458 $value = null; 459 } 460 return $value; 459 461 } 460 462 … … 518 520 519 521 add_filter('woocommerce_rest_pre_insert_shop_order_object', 'litc_woocommerce_rest_pre_insert_shop_order_object', 10); 522 523 524 add_action('rest_api_init', function () { 525 register_rest_route('wc/v3/litc', '/products/(?P<id>\d+)/images', array( 526 'methods' => 'POST', 527 'callback' => 'litc_add_product_images', 528 'permission_callback' => function () { 529 return current_user_can('edit_products'); 530 }, 531 )); 532 register_rest_route('wc/v3/litc', '/products/(?P<product_id>\d+)/images/(?P<image_id>\d+)', array( 533 'methods' => 'DELETE', 534 'callback' => 'litc_delete_product_image', 535 'permission_callback' => function () { 536 return current_user_can('edit_products'); 537 }, 538 )); 539 }); 540 541 function litc_add_product_images($request) { 542 $product_id = $request['id']; 543 $images = $request->get_param('images'); 544 545 if (!is_array($images) || empty($images)) { 546 return new WP_Error('invalid_images', 'Invalid images array', array('status' => 400)); 547 } 548 549 if (!get_post($product_id) || get_post_type($product_id) !== 'product') { 550 return new WP_Error('invalid_product', 'Product not found', array('status' => 404)); 551 } 552 553 $uploaded_images = []; 554 555 foreach ($images as $image_url) { 556 $image_id = litc_upload_image_from_url($image_url); 557 558 if (is_wp_error($image_id)) { 559 return new WP_Error('image_upload_failed', 'Failed to upload image: ' . $image_url, array('status' => 500)); 560 } 561 562 $uploaded_images[] = $image_id; 563 } 564 565 $product = wc_get_product($product_id); 566 $existing_gallery = $product->get_gallery_image_ids(); 567 $updated_gallery = array_merge($existing_gallery, $uploaded_images); 568 $product->set_gallery_image_ids($updated_gallery); 569 $product->save(); 570 571 return rest_ensure_response([ 572 'success' => true, 573 'uploaded_images' => $uploaded_images, 574 ]); 575 } 576 577 function litc_upload_image_from_url($image_url) { 578 $upload_dir = wp_upload_dir(); 579 $image_data = file_get_contents($image_url); 580 581 if (!$image_data) { 582 return new WP_Error('image_fetch_failed', 'Could not fetch image from URL.'); 583 } 584 585 $filename = basename($image_url); 586 $file_path = $upload_dir['path'] . '/' . $filename; 587 588 file_put_contents($file_path, $image_data); 589 590 $filetype = wp_check_filetype($filename, null); 591 592 if (!$filetype['type']) { 593 return new WP_Error('invalid_image_type', 'Invalid image type.'); 594 } 595 596 $attachment_id = wp_insert_attachment( 597 [ 598 'guid' => $upload_dir['url'] . '/' . $filename, 599 'post_mime_type' => $filetype['type'], 600 'post_title' => sanitize_file_name($filename), 601 'post_content' => '', 602 'post_status' => 'inherit', 603 ], 604 $file_path 605 ); 606 607 require_once(ABSPATH . 'wp-admin/includes/image.php'); 608 $attach_data = wp_generate_attachment_metadata($attachment_id, $file_path); 609 wp_update_attachment_metadata($attachment_id, $attach_data); 610 611 return $attachment_id; 612 } 613 614 615 function litc_delete_product_image($request) { 616 $product_id = $request['product_id']; 617 $image_id = $request['image_id']; 618 $force = $request->get_param('force'); 619 if (!get_post($product_id) || get_post_type($product_id) !== 'product') { 620 return new WP_Error('invalid_product', 'Product not found', array('status' => 404)); 621 } 622 623 if (!get_post($image_id)) { 624 return new WP_Error('invalid_image', 'Image not found', array('status' => 404)); 625 } 626 627 $product = wc_get_product($product_id); 628 $gallery = $product->get_gallery_image_ids(); 629 630 if (!in_array($image_id, $gallery)) { 631 return new WP_Error('image_not_in_product', 'Image is not associated with this product.', array('status' => 400)); 632 } 633 634 $updated_gallery = array_diff($gallery, [$image_id]); 635 $product->set_gallery_image_ids($updated_gallery); 636 $product->save(); 637 638 if ($force === true || $force === 'true') { 639 wp_delete_attachment($image_id, true); 640 } 641 642 643 return rest_ensure_response([ 644 'success' => true, 645 'message' => 'Image removed from product successfully.', 646 'remaining_images' => $updated_gallery, 647 ]); 648 } -
litcommerce/trunk/readme.txt
r3194630 r3222670 3 3 Contributors: LitCommerce 4 4 Tags: WooCommerce, Amazon, eBay, Etsy, TikTok 5 Requires at least: 5.06 5 Tested up to: 6.7.1 7 Requires PHP: 5.6 8 Stable tag: 1.0.5 6 Stable tag: 1.2.3 9 7 License: GPL-2.0 10 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
litcommerce/trunk/steps/SendWooCommerceKeys.php
r3211347 r3222670 27 27 $url .= '&channel_url=' . urlencode( site_url() ); 28 28 $url .= '&from_app=marketplace'; 29 $url .= '&version_plugin=1.2.3'; 29 30 30 31 if(@$_GET['reconnect'] == 1){
Note: See TracChangeset
for help on using the changeset viewer.