feat: implement WooCommerce AJAX product search

This commit is contained in:
XShop
2026-09-13 20:01:15 +03:30
parent 00439fcea9
commit f5c283af25
14 changed files with 760 additions and 37 deletions
+13 -1
View File
@@ -41,7 +41,19 @@
- `System Status` reports: PHP/WP/WC versions, active plugins, asset sizes, transient hit rate.
- Lighthouse CI optional (not required for v1).
## 8. Anti-Patterns Forbidden
## 8. Search Performance (M3)
- **Debounce**: 250ms in `assets/js/search.js:debounce` (200–300ms target). Prevents request on every keystroke.
- **Min length**: 2 chars (handler returns empty without query). Input `data-min-length`.
- **Bounded**: `limit` default 6, max 20, validated; handler over-fetches `limit*2` for dedup then slices to `limit`; max 40 IDs scanned.
- **Stale protection**: `AbortController` cancels previous fetch + monotonic `seq` counter ignores stale JSON; rapid `iph → iphone` cannot overwrite newer.
- **Dedupe**: identical query (`lastQuery`) reopens dropdown without fetch.
- **Query**: `WP_Query` `s` + `_sku` LIKE, `post_status publish`, `no_found_rows`, `fields ids`, no N+1, `wc_get_product` only for returned IDs (≤6).
- **Asset**: `search.js` enqueued only on front-end where `data-xshop-search` exists (header on all front-end pages, guarded via `initAll`); `woo.css` global intentional.
- **Caching**: server `Cache-Control: public, max-age=60`; no client cache beyond in-memory `lastQuery` (no stale invalidation issues).
- **Payload**: minimal 6 items × 6 fields (~2KB JSON).
## 9. Anti-Patterns Forbidden
- Global `wp_enqueue_script` without condition.
- Querying all products to compute filters.