Changeset 3242765
- Timestamp:
- 02/18/2025 04:26:40 PM (14 months ago)
- Location:
- multi-woo-manager/trunk
- Files:
-
- 3 edited
-
README.txt (modified) (3 diffs)
-
admin/class-multi-woo-manager-admin.php (modified) (6 diffs)
-
multi-woo-manager.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
multi-woo-manager/trunk/README.txt
r3240547 r3242765 6 6 Tested up to: 6.7.1 7 7 Requires PHP: 8.0 8 Stable tag: 1.1. 68 Stable tag: 1.1.7 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.1.7 = 60 * Fixed product's catalog visibility value synchronization 61 59 62 = 1.1.6 = 60 63 * Fixed a recursion bug where prefixes were lost in nested ACF group fields. … … 67 70 == Upgrade Notice == 68 71 72 = 1.1.7 = 73 * Recommended update to fix catalog_visibility during products synchronization. 74 69 75 = 1.1.6 = 70 76 * Recommended update to fix field prefix recursion for nested group fields. -
multi-woo-manager/trunk/admin/class-multi-woo-manager-admin.php
r3236761 r3242765 259 259 * @return mixed 260 260 */ 261 function get_woocommerce_products($paged = 1, $posts_per_page = 10, $sku = null): mixed 262 { 261 function get_woocommerce_products($paged = 1, $posts_per_page = 10, $sku = null): mixed { 263 262 global $wpdb; 264 263 … … 285 284 } 286 285 287 // Base query to fetch WooCommerce products excluding variations 286 // Build the query. 287 // We remove the old _visibility meta join and instead use taxonomy tables. 288 // Use GROUP_CONCAT() to get all product_visibility term slugs for each product. 288 289 $query = " 289 290 SELECT … … 293 294 p.post_status AS status, 294 295 p.post_title AS name, 295 COALESCE(pm_visibility.meta_value, 'visible') as catalog_visibility,296 GROUP_CONCAT(DISTINCT t_visibility.slug SEPARATOR ',') as visibility_terms, 296 297 COALESCE(pm_stock.meta_value, IFNULL(pm_stock_status.meta_value, 'outofstock')) as stock, 297 298 COALESCE(pm_manage_stock.meta_value, 'no') as manage_stock, … … 300 301 FROM {$wpdb->posts} vp 301 302 WHERE vp.post_parent = p.ID 302 AND vp.post_type = 'product_variation') as has_variations303 AND vp.post_type = 'product_variation') as has_variations 303 304 FROM {$wpdb->posts} p 304 LEFT JOIN {$wpdb->postmeta} pm_sku ON (p.ID = pm_sku.post_id AND pm_sku.meta_key = '_sku') 305 LEFT JOIN {$wpdb->postmeta} pm_visibility ON (p.ID = pm_visibility.post_id AND pm_visibility.meta_key = '_visibility') 306 LEFT JOIN {$wpdb->postmeta} pm_stock ON (p.ID = pm_stock.post_id AND pm_stock.meta_key = '_stock') 307 LEFT JOIN {$wpdb->postmeta} pm_stock_status ON (p.ID = pm_stock_status.post_id AND pm_stock_status.meta_key = '_stock_status') 308 LEFT JOIN {$wpdb->postmeta} pm_manage_stock ON (p.ID = pm_manage_stock.post_id AND pm_manage_stock.meta_key = '_manage_stock') 305 LEFT JOIN {$wpdb->postmeta} pm_sku 306 ON (p.ID = pm_sku.post_id AND pm_sku.meta_key = '_sku') 307 LEFT JOIN {$wpdb->term_relationships} tr_visibility 308 ON (p.ID = tr_visibility.object_id) 309 LEFT JOIN {$wpdb->term_taxonomy} tt_visibility 310 ON (tr_visibility.term_taxonomy_id = tt_visibility.term_taxonomy_id AND tt_visibility.taxonomy = 'product_visibility') 311 LEFT JOIN {$wpdb->terms} t_visibility 312 ON (tt_visibility.term_id = t_visibility.term_id) 313 LEFT JOIN {$wpdb->postmeta} pm_stock 314 ON (p.ID = pm_stock.post_id AND pm_stock.meta_key = '_stock') 315 LEFT JOIN {$wpdb->postmeta} pm_stock_status 316 ON (p.ID = pm_stock_status.post_id AND pm_stock_status.meta_key = '_stock_status') 317 LEFT JOIN {$wpdb->postmeta} pm_manage_stock 318 ON (p.ID = pm_manage_stock.post_id AND pm_manage_stock.meta_key = '_manage_stock') 309 319 WHERE p.post_type IN ($placeholders) 310 AND p.post_status NOT IN ('trash')"; 311 320 AND p.post_status NOT IN ('trash') 321 "; 322 323 // If SKU filter is provided, add it. Otherwise, apply LIMIT. 312 324 if ($sku) { 313 325 $query .= " AND pm_sku.meta_value = %s"; 314 326 $params = array_merge($product_types, [$sku]); 315 327 } else { 316 $query .= " LIMIT %d, %d";328 $query .= " GROUP BY p.ID LIMIT %d, %d"; 317 329 $params = array_merge($product_types, [$offset, $posts_per_page]); 318 330 } 319 331 320 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery -- Direct query needed for performance and systematic reasons. 332 // For performance reasons, we use a direct query. 333 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery 321 334 $products = $wpdb->get_results($wpdb->prepare($query, ...$params)); 322 335 323 // Cache the results 336 // Process each product to determine catalog_visibility based on your mapping. 337 foreach ($products as &$product) { 338 // Explode the comma-separated list (if any) into an array. 339 $terms = !empty($product->visibility_terms) ? explode(',', $product->visibility_terms) : []; 340 341 $has_exclude_from_search = in_array('exclude-from-search', $terms, true); 342 $has_exclude_from_catalog = in_array('exclude-from-catalog', $terms, true); 343 344 // Apply mapping: 345 if ($has_exclude_from_search && $has_exclude_from_catalog) { 346 // Hidden: excluded from both search and catalog 347 $product->catalog_visibility = 'hidden'; 348 } elseif ($has_exclude_from_catalog && !$has_exclude_from_search) { 349 // Only search: product is not in catalog 350 $product->catalog_visibility = 'search'; 351 } elseif ($has_exclude_from_search && !$has_exclude_from_catalog) { 352 // Only catalog: product is not in search 353 $product->catalog_visibility = 'catalog'; 354 } else { 355 // If neither term is applied, default to visible 356 $product->catalog_visibility = 'visible'; 357 } 358 359 // (Optional) Remove the raw visibility_terms property if not needed. 360 unset($product->visibility_terms); 361 } 362 unset($product); // break reference 363 364 // Cache the results for one minute. 324 365 wp_cache_set($cache_key, $products, 'woocommerce_products', MINUTE_IN_SECONDS); 325 366 … … 481 522 // Count total matching attachments 482 523 $count_query = "SELECT COUNT(*) FROM {$wpdb->posts} {$where_clause}"; 524 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery 483 525 $total = (int) $wpdb->get_var($count_query); 484 526 … … 495 537 } 496 538 539 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery 497 540 $attachments = $wpdb->get_results($query); 498 541 -
multi-woo-manager/trunk/multi-woo-manager.php
r3240547 r3242765 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.1. 620 * Version: 1.1.7 21 21 * Author: MultiWooManager 22 22 * Author URI: https://multiwoomanager.com/
Note: See TracChangeset
for help on using the changeset viewer.