=== AI Product Migrator ===
Contributors: arfarehman
Tags: woocommerce, product import, csv import, web scraping, ai
Requires at least: 6.2
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 2.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Discover, scrape, and import WooCommerce products from websites, CSV, or JSON APIs, with AI-assisted extraction, background processing, and optional scheduled auto-sync.

== Description ==

AI Product Migrator helps WordPress administrators build a WooCommerce catalog from outside sources. Point it at a website, a CSV file, or a JSON API, review the extracted products in a preview table, then import the ones you want straight into WooCommerce or export them as a WooCommerce-compatible CSV.

The plugin works best with WooCommerce sites, Shopify sites, and any page that publishes schema.org/Product structured data, but it also includes generic-site heuristics for stores that use neither platform.

This release merges what used to be two separate plugins (AI Product Migrator and AI Product Migrator Pro) into one. Every feature from both is now available here.

= Key features =

* Analyze an ecommerce website from the WordPress admin and detect its platform (WooCommerce, Shopify, schema.org/Product, or a generic storefront).
* Discover product URLs from WooCommerce product links, shop listing pages, and sitemaps.
* Discover Shopify products from the store's public JSON product feeds.
* Scrape product pages in AJAX batches (title, description, price, SKU, stock status, images, categories, tags, attributes, and variations). Once started, scraping continues in the background via WP-Cron even if you close the browser tab.
* Load products directly from a CSV URL or an uploaded CSV file.
* Load products from a JSON API endpoint, with pagination and optional Bearer-token or API-key-header authentication.
* Preview every discovered/scraped/loaded product before anything is written to your store, including local data-quality flags (missing price, invalid discount, no images, missing SKU, short title).
* Import selected products into WooCommerce, or export them as a WooCommerce-compatible CSV.
* Configurable duplicate handling: skip, update, or always create new products, matched by SKU or source URL.
* One-click rollback: trash every product a specific import created or touched.
* Retry failed items on a single import without re-running the whole thing.
* Persistent import history, a "what changed" view on updated products, and a diagnostic log, all in the plugin's own database tables.
* A Dashboard page summarizing totals and recent activity across every import.
* Optional Gemini AI assistance for detecting ecommerce platforms on sites where the built-in heuristics are inconclusive; on generic/custom sites, Gemini's suggested CSS selectors are also used directly to guide product discovery and field extraction.
* Optional AI content rewriting and AI category/tag mapping onto your existing store taxonomy (both off by default; each uses a Gemini call).
* Optional scheduled auto-sync (15 minutes up to weekly) per import that automatically creates newly discovered products and updates already-imported ones (price, stock, description, images) via WP-Cron. Available for WooCommerce/Shopify/generic website imports and CSV-via-URL imports.
* Optional "Protect Manual Edits" setting so auto-sync never overwrites a title, description, price, or stock status you changed by hand since the last sync.
* Optional email notifications when a background sync run finishes or stops early.
* Marketplace connector settings for Amazon, eBay, and AliExpress (scaffolding only — not yet implemented; no requests are made to these marketplaces).

= External services =

This plugin is a migration tool, so by its nature it talks to servers outside your own WordPress site. Here is exactly what it connects to and why:

* **The website, CSV URL, or JSON API you enter.** When you use the "Analyze Website," "Fetch Products," "Load CSV Products," or "Load JSON Products" actions, the plugin makes outbound HTTP(S) requests, from your server, to the URL(s) you supply, in order to read that page or feed's product data. No request is made anywhere until you actively start an import. The plugin blocks requests to private, loopback, and reserved IP ranges as a safety measure, but it cannot verify who owns or operates a public URL you choose to import from &#8212; you are responsible for only importing from sites and feeds you have the right to use.
* **The same source URL, again, on a schedule &#8212; but only if you turn on Auto-Sync for a specific import.** Auto-Sync is off by default and is enabled per-import, one click at a time, on the Import History screen. When it is on, WordPress's built-in WP-Cron system re-requests the source periodically (interval you choose), discovers new products, and updates already-imported ones, with no further action from you until you turn it back off.
* **Google's Gemini API** (`generativelanguage.googleapis.com`), only if you enter a Gemini API key on the Settings page. When a key is configured, it may be used for: (1) detecting an ecommerce platform when local detection is inconclusive, sending a cleaned copy of the target site's homepage HTML (scripts, styles, comments stripped); (2) optional AI content rewriting, sending a scraped product's title/description if you turn that setting on; (3) optional AI category mapping, sending scraped category/tag names and your store's existing term names if you turn that setting on. Your Gemini API key is stored in your site's options table, is never sent to your site's frontend or logged in plaintext, and is masked in the settings screen after saving. No data about your own WordPress site, its content, or its users is sent to Gemini beyond what's described above. See [Google's Gemini API Terms of Service](https://ai.google.dev/gemini-api/terms) and [Google's Privacy Policy](https://policies.google.com/privacy) for how Google handles this request.

No other outbound connections are made by this plugin.

== Installation ==

1. Upload the `ai-product-migrator` folder to `/wp-content/plugins/`, or install the plugin through the WordPress admin's "Add New Plugin" screen.
2. Make sure WooCommerce is installed and active. AI Product Migrator will not activate without it, and will deactivate itself automatically if WooCommerce is later deactivated.
3. Activate **AI Product Migrator** through the "Plugins" screen.
4. Open **AI Product Migrator** from the WordPress admin menu to start a new import.
5. Optional: visit **AI Product Migrator > Settings** to configure a Gemini API key, default product status, duplicate handling, notifications, and import limits before your first run.

== Frequently Asked Questions ==

= Does this plugin require WooCommerce? =

Yes. AI Product Migrator creates WooCommerce products, categories, tags, attributes, variations, and product images, so WooCommerce must be installed and active.

= Do I need a Gemini API key to use this plugin? =

No. The Gemini API key is entirely optional. Website analysis runs a built-in, local detector first (platform indicators, product URLs, structured data, add-to-cart buttons, price patterns, and listing cards). Gemini is only consulted as an assistant when that local detection is weak or the site looks like a generic/custom platform, and only if you have added a key. AI content rewriting and AI category mapping also require a key and are off by default.

= What happens to my Gemini API key? =

It is stored in your site's WordPress options and is never printed into the settings page HTML or any frontend script. Once saved, the settings field displays only a masked placeholder; entering a new value replaces the key, and clearing the field removes it.

= Can I import from Shopify stores? =

Yes. The plugin detects Shopify sites and can discover products from their public JSON product feeds in addition to WooCommerce and generic ecommerce sites.

= Am I allowed to scrape any website I want? =

The plugin does not check copyright or terms-of-service on your behalf. You are responsible for only importing product data from websites, CSV files, and APIs you have the legal right to use. Always review a source site's terms before importing its content.

= Where can I review what an import actually did? =

Go to **AI Product Migrator > Import History** for a per-run summary (source, platform, status, totals) and per-product results including a "what changed" view on updates, **AI Product Migrator > Dashboard** for aggregate totals across every import, or **AI Product Migrator > Logs** for detailed diagnostic events from analysis through import.

= What happens if I deactivate WooCommerce while this plugin is active? =

AI Product Migrator detects this, shows an admin notice, and deactivates itself automatically so it never runs without WooCommerce present.

= What is Auto-Sync and how do I turn it on? =

Auto-Sync automatically re-checks a source on a schedule, creates WooCommerce products for anything newly discovered, and updates already-imported products (price, stock, description, images) if the source has changed. It is off by default. Turn it on per-import from the "Import #ID" detail screen under **AI Product Migrator > Import History**, choose an interval (15 minutes up to weekly), and WordPress's built-in WP-Cron will handle the rest. It's available for website imports (WooCommerce/Shopify/generic detection) and CSV-via-URL imports; uploaded-file CSV imports and JSON API imports aren't eligible.

= Does Auto-Sync create new products? =

Yes — unlike a simple "refresh" sync, Auto-Sync both creates newly discovered products and updates products already imported from the same source, regardless of your global Duplicate Handling setting (which only affects manual imports).

= Can I stop Auto-Sync from overwriting a price or description I changed by hand? =

Yes. Turn on **Protect Manual Edits** in Settings. Once on, if a product's title, description, price, or stock status was changed since the plugin last wrote it, future syncs leave that field alone instead of overwriting it.

= What if extraction or import fails for some products? =

Failed rows stay visible in Import History with an error message. Use the **Retry Failed Items** button on that import's detail screen to re-attempt just the failed ones. If the import has Auto-Sync enabled, failures are also implicitly retried on the next scheduled run.

= Can I undo an import? =

Yes. Use **Rollback Import** on the import's detail screen to move every product it created or updated to the Trash. This is reversible from the standard WordPress Trash screen.

== Screenshots ==

1. New Import screen &#8212; choose a CSV, WooCommerce store URL, or JSON API source.
2. Website analysis and product discovery workflow with live progress.
3. Product preview table before import, with per-row status and data-quality flags.
4. Import History screen with persistent run summaries, Auto-Sync controls, rollback, and retry.
5. Dashboard screen with aggregate totals and recent activity.
6. Settings screen for Gemini API key, duplicate handling, notifications, and import limits.

== Changelog ==

= 2.0.0 =
* Merged AI Product Migrator and AI Product Migrator Pro into a single plugin. Every feature from both is now available here.
* Added background extraction: scraping continues via WP-Cron even if the browser tab is closed.
* Replaced the previous update-only Scheduled Sync with Auto-Sync: creates newly discovered products in addition to updating existing ones, with more interval choices (15 minutes up to weekly) and no fixed per-run product cap.
* Added one-click rollback and a manual "Retry Failed Items" action per import.
* Added email notifications for background sync runs.
* Added an optional "Protect Manual Edits" setting.
* Added optional AI content rewriting and AI category/tag mapping (both off by default).
* Added local data-quality flags on scraped products (no AI call).
* Added a Dashboard page and a "what changed" diff view on updated products.
* Added marketplace connector settings for Amazon, eBay, and AliExpress (scaffolding only).
* Extended auto-sync to CSV-via-URL sources.

= 1.1.0 =
* Added: Gemini's suggested CSS selectors (from AI-assisted site detection) are now used directly to guide product discovery and field extraction on generic/custom sites, instead of only being shown as hints.
* Added: optional Scheduled Sync, enabled per-import from the Import History screen, that automatically re-checks previously imported products via WP-Cron on an hourly/twice-daily/daily/weekly schedule and refreshes price, stock, and description.
* Added: import records now track recurring-sync state (enabled/frequency/next run/last run).

= 1.0.0 =
* Initial release: website analysis and ecommerce platform detection, WooCommerce/Shopify/generic product discovery, CSV and JSON API import, batched product scraping, product preview table, WooCommerce import, WooCommerce-compatible CSV export, optional Gemini AI detection assistance, persistent import history and logs.

== Upgrade Notice ==

= 2.0.0 =
Merges AI Product Migrator Pro's features into this plugin, including a more capable Auto-Sync that now creates products (not just updates them). If you had Scheduled Sync enabled on any import, re-check its settings under Import History after updating. If you were previously running AI Product Migrator Pro as a separate plugin, deactivate it before activating this update to avoid running both at once.

= 1.1.0 =
Adds optional scheduled product re-sync and AI-guided extraction. No manual action required after updating.

= 1.0.0 =
Initial release.
