Changeset 3377020
- Timestamp:
- 10/12/2025 04:10:46 PM (6 months ago)
- Location:
- multi-woo-manager/trunk
- Files:
-
- 3 edited
-
README.txt (modified) (2 diffs)
-
admin/class-multi-woo-manager-admin.php (modified) (2 diffs)
-
multi-woo-manager.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
multi-woo-manager/trunk/README.txt
r3361266 r3377020 6 6 Tested up to: 6.7.1 7 7 Requires PHP: 8.0 8 Stable tag: 1.2. 08 Stable tag: 1.2.1 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 57 57 == Changelog == 58 58 59 = 1.2.1 = 60 * Added Smart Image synchronization compatibility for ACF image fields, fixed product synchronization bugs & ACF repeater field Ai translations. 61 59 62 = 1.2.0 = 60 63 * Added Tag Mapping system & Tag editing functionality. Introduced Smart Image synchronization for faster product image updates across multiple stores. -
multi-woo-manager/trunk/admin/class-multi-woo-manager-admin.php
r3361266 r3377020 213 213 'methods' => 'POST', 214 214 'callback' => [$this, 'rest_mwm_sync_gallery'], 215 'permission_callback' => function () { 216 return current_user_can('edit_posts') && current_user_can('upload_files'); 217 }, 218 )); 219 220 // Sync ACF images from source with smart duplicate detection 221 register_rest_route('wc/v3', '/mwm-sync-acf-images/', array( 222 'methods' => 'POST', 223 'callback' => [$this, 'rest_mwm_sync_acf_images'], 215 224 'permission_callback' => function () { 216 225 return current_user_can('edit_posts') && current_user_can('upload_files'); … … 1641 1650 } 1642 1651 } 1652 1653 /** 1654 * Sync ACF image fields from source product 1655 * 1656 * @param WP_REST_Request $request 1657 * @return WP_REST_Response 1658 * @since 1.2.0 1659 */ 1660 function rest_mwm_sync_acf_images($request) { 1661 $params = $request->get_json_params(); 1662 1663 if (!isset($params['product_id']) || !isset($params['acf_image_fields'])) { 1664 return new WP_REST_Response([ 1665 'success' => false, 1666 'message' => 'Missing product_id or acf_image_fields' 1667 ], 400); 1668 } 1669 1670 // Check if ACF is available 1671 if (!class_exists('ACF') || !function_exists('get_field_object')) { 1672 return new WP_REST_Response([ 1673 'success' => false, 1674 'message' => 'ACF plugin is not active' 1675 ], 400); 1676 } 1677 1678 try { 1679 $product_id = intval($params['product_id']); 1680 $acf_image_fields = $params['acf_image_fields']; 1681 1682 $product = wc_get_product($product_id); 1683 1684 if (!$product) { 1685 return new WP_REST_Response([ 1686 'success' => false, 1687 'message' => 'Product not found' 1688 ], 404); 1689 } 1690 1691 $synced_fields = []; 1692 $uploaded_count = 0; 1693 $reused_count = 0; 1694 $errors = []; 1695 1696 // Process each ACF image field 1697 foreach ($acf_image_fields as $field_data) { 1698 try { 1699 $field_key = $field_data['field_key'] ?? ''; 1700 $source_attachment_id = $field_data['attachment_id'] ?? 0; 1701 $image_url = $field_data['url'] ?? ''; 1702 $filename = $field_data['filename'] ?? ''; 1703 1704 if (empty($field_key) || empty($image_url)) { 1705 $errors[] = "Field {$field_key}: Missing required data"; 1706 continue; 1707 } 1708 1709 // Check if image already exists by filename 1710 $existing_attachment = $this->find_existing_attachment($filename, $image_url); 1711 1712 if ($existing_attachment) { 1713 // Reuse existing attachment 1714 $new_attachment_id = $existing_attachment->ID; 1715 $reused_count++; 1716 } else { 1717 // Upload new image 1718 $new_attachment_id = $this->simple_create_attachment($image_url, $product_id, [ 1719 'alt' => $field_data['alt'] ?? '', 1720 'name' => $field_data['title'] ?? '' 1721 ]); 1722 1723 if (!$new_attachment_id) { 1724 $errors[] = "Field {$field_key}: Failed to upload image"; 1725 continue; 1726 } 1727 1728 $uploaded_count++; 1729 } 1730 1731 // Update product meta for ACF field 1732 // ACF stores image fields with 2 meta entries: 1733 // 1. {field_key} => attachment_id 1734 // 2. _{field_key} => field_key (reference) 1735 1736 update_post_meta($product_id, $field_key, $new_attachment_id); 1737 update_post_meta($product_id, '_' . $field_key, $field_key); 1738 1739 $synced_fields[] = [ 1740 'field_key' => $field_key, 1741 'old_attachment_id' => $source_attachment_id, 1742 'new_attachment_id' => $new_attachment_id, 1743 'url' => wp_get_attachment_url($new_attachment_id) 1744 ]; 1745 1746 } catch (Exception $e) { 1747 $errors[] = "Field {$field_key}: " . $e->getMessage(); 1748 } 1749 } 1750 1751 return new WP_REST_Response([ 1752 'success' => true, 1753 'message' => "ACF images synced successfully", 1754 'stats' => [ 1755 'total_fields' => count($acf_image_fields), 1756 'uploaded' => $uploaded_count, 1757 'reused' => $reused_count, 1758 'errors' => count($errors), 1759 'synced' => count($synced_fields) 1760 ], 1761 'synced_fields' => $synced_fields, 1762 'errors' => $errors 1763 ], 200); 1764 1765 } catch (Exception $e) { 1766 return new WP_REST_Response([ 1767 'success' => false, 1768 'message' => 'Error syncing ACF images: ' . $e->getMessage() 1769 ], 500); 1770 } 1771 } 1643 1772 } -
multi-woo-manager/trunk/multi-woo-manager.php
r3361266 r3377020 18 18 * Plugin URI: https://multiwoomanager.com 19 19 * Description: WooCommerce products management, the easy way. Plugin extends WooCommerce REST API in order to provide optimized API routes for product management. 20 * Version: 1.2. 020 * Version: 1.2.1 21 21 * Author: MultiWooManager 22 22 * Author URI: https://multiwoomanager.com/ … … 32 32 } 33 33 34 define( 'MULTI_WOO_MANAGER_VERSION', '1.2. 0' );34 define( 'MULTI_WOO_MANAGER_VERSION', '1.2.1' ); 35 35 36 36 /**
Note: See TracChangeset
for help on using the changeset viewer.