=== Connect for Mobilox ===
Contributors: naiches
Tags: mobilox, hexon, vehicles, inventory, sync
Requires at least: 7.0
Tested up to: 7.0
Requires PHP: 8.4
Stable tag: 1.1.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Sync your Mobilox/Hexon vehicle inventory to WordPress — real-time incremental sync and bulk XML import.

== Description ==

Connect for Mobilox syncs your vehicle inventory from the Mobilox/Hexon dealer management system to your WordPress site. Vehicles are stored as a configurable post type with full data available to your theme.

**Features:**

* Real-time sync — vehicles are added, updated, and removed automatically via the DV incremental XML feed.
* Configurable post type — sync to the built-in "Vehicle" post type or any existing custom post type in your theme.
* Full data storage — every field Mobilox sends is stored in a custom table as JSON, accessible via template helpers.
* Image management — diff-based: only new images are downloaded, unchanged images keep their attachment IDs, removed images are cleaned up.
* Endpoint security — protect your sync endpoint with a secret token or HTTP Basic Auth.
* Status dashboard — see synced vehicle count, errors, last sync time, and a full activity log.
* Read-only meta box — view all vehicle data grouped by category on the post editor.

**For theme developers:**

Access vehicle data in your templates:

    $vehicle = mobilox_get_vehicle();
    echo $vehicle->{'general.make.name'};
    echo $vehicle->{'powertrain.engine.power.pk'} . ' pk';

Or field by field:

    echo mobilox_get_field( 'body.colour.name_nl' );

== Installation ==

1. Upload the plugin to `/wp-content/plugins/` or install via Plugins → Add New.
2. Activate the plugin.
3. Go to **Mobilox → Settings** and select a post type.
4. Copy the endpoint URL from the **Mobilox → Dashboard** page into your DV management tool.
5. Vehicles will sync automatically as Mobilox pushes updates.

== Frequently Asked Questions ==

= Which post type should I choose? =

If your theme already has a vehicle/occasion post type, select that. Otherwise, use the built-in "Mobilox Vehicle" type. You can change this at any time — existing vehicles will continue to work.

= How do I access vehicle data in my theme? =

Use `mobilox_get_vehicle( $post_id )` to get the full data object, or `mobilox_get_field( 'field.name' )` for a single field. Field names match the Mobilox XML element names (e.g. `general.make.name`, `powertrain.engine.power.pk`).

= Is the sync endpoint secure? =

By default, the endpoint is open (for easy setup). Go to Settings to add a secret token or HTTP Basic Auth credentials.

== Screenshots ==

1. The Mobilox dashboard — vehicle count, sync status, endpoint URL, and activity log.
2. Settings — post type selector, endpoint security, and log retention.

== Changelog ==

= 1.1.3 =
* Fix: the consumer price was read from the wrong DV element (`verkoopprijs_particulier` → `prijs` → `bedrag`), but the DV schema places it directly at `verkoopprijs_particulier` → `bedrag`, so prices were stored as 0. The price is now read from the correct element, with a fallback for feeds that wrap it in a `<prijs>` node.
* New: the vehicle description (`opmerkingen`) is now saved to the post content, so themes that render `the_content()` show the full description.
* Fix: an "Undefined array key" notice when a vehicle had no `<titel>` element.

= 1.1.2 =
* Fix: incremental sync did not import vehicles from the standard DV ("Doorlinken Voorraad") feed. The XML parser now reads the flat `voertuig.xsd` (2.21) element names — `voertuignr_hexon`, `merk`, `model`, `tellerstand`, `verkoopprijs_particulier`, `afbeeldingen`, `verkocht` — so make, model, price, mileage, fuel, build year, sold status, and photos are stored correctly.
* Fix: the sync endpoint returned a JSON-quoted response (`"1"`), which the DV client rejected as "Answer unequal to '1'" — every push was reported as failed even when the vehicle was stored. The endpoint now returns a bare `1` / `0`.

= 1.1.1 =
* Fix: saving the Settings page could fail with "Cannot load mobilox-settings." — the Post Type field was named `post_type`, which shadows a reserved WordPress admin request variable used to resolve the current admin page, making the page-hook lookup fail on save. All settings fields are now plugin-prefixed so they can't collide with core request vars or other plugins.

= 1.1.0 =
* Complete rewrite — OOP architecture with namespaced classes.
* Custom database table for vehicle data (no postmeta bloat).
* Configurable post type — sync to any existing CPT or the built-in one.
* XML-only sync (v2.23+ compatible) — dropped legacy POST field support.
* Diff-based image handling — only downloads new/changed images.
* Secured REST endpoint with token and HTTP Basic Auth.
* Admin dashboard with stats, activity log, and endpoint URL.
* Read-only meta box showing all vehicle data grouped by category.
* Template helper functions for theme developers.
* Full uninstall cleanup (tables, posts, attachments, options).

= 1.0.0 =
* Initial version.
