Commit Graph

14 Commits

Author SHA1 Message Date
luklpz fa20b7cc91 fix: add out_of_stock to stock XML; remove invalid date_add order filter
- PrestashopClient.toStockAvailableXml: add out_of_stock=2 (use shop
  default) — PS 8.2.5 returns 400 code 41 without this field
- PrestashopClient.getOrdersSince: remove filter[date_add] — PS 8.2.5
  does not expose date_add as a filterable field for orders (400 code 32)
  Re-import prevention handled by OrderMapping.existsByPrestashopOrderId

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 08:10:00 +02:00
luklpz aeec27f7af fix: correct Dolibarr/PS filters and handle guest orders
- DolibarrClient.getProductByRef: use sqlfilters=(t.ref:=:'x') instead
  of unsupported ref query param (caused StockSync to push wrong stock)
- PrestashopClient.getProductByReference: wrap value in [x] for PS
  exact-match filter syntax (root cause of createProduct returning null)
- OrderSyncService.resolveCustomer: skip getCustomer when id_customer
  is 0 or null (guest orders returned 404 and failed import)
- StockSyncService: parse stock quantity as Double to handle "5.000"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 08:05:18 +02:00
luklpz 22c92a1ee2 fix: throw PrestashopApiException instead of NPE when createProduct returns null
If PS accepts the POST but the subsequent GET by reference finds nothing,
the null return from createProduct now throws PrestashopApiException, which
is caught by the per-item handler and recorded in SyncLog without aborting
the rest of the sync loop.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 23:51:36 +02:00
luklpz 4ae72e3e05 fix: add required depends_on_stock field to stock_available XML body
PS WebService PUT /stock_availables requires depends_on_stock even when
updating only the quantity. Hard-coded to 0 (does not depend on warehouse).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 23:35:22 +02:00
luklpz 96d75b324a fix: use plain String for PS multilingual fields; add Dolibarr diagnostic endpoint
PS WebService GET responses return name/description as plain strings, not
language-array objects. Using List<LangValue> caused Jackson to throw
HttpMessageConversionException on every getProductByReference call.

Also adds GET /api/sync/diagnostics/dolibarr to verify Dolibarr connectivity
and product count from the Railway environment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 23:26:28 +02:00
luklpz 806497b24d fix: fetch all Dolibarr products without tms sqlfilter
Incremental sync via t.tms filter breaks when products were created before
the service started running: their tms is older than lastSyncStart so they
are never returned. Since the sync is idempotent (ProductMapping handles
create-vs-update), always fetching all products is safe and simpler.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 21:04:09 +02:00
luklpz 359590b7d8 fix: discard PS POST response body, fetch created product via GET
PS WebService POST response uses a different JSON structure for multilingual
fields than GET responses, causing Jackson deserialization failures. Instead
of parsing the POST body, discard it with toBodilessEntity() and fetch the
created product via getProductByReference() which uses the stable GET format.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 20:46:17 +02:00
luklpz 961a1b8a8a ci: trigger Railway rebuild for JsonNode fix 2026-05-14 20:25:49 +02:00
luklpz 4469d7dd7e fix: parse createProduct response as JsonNode to avoid multilingual field mismatch
PS WebService POST response wraps multilingual fields as {"language":[...]}
while GET returns a flat array. Jackson fails parsing List<LangValue> from
the POST response. Fix: parse the full response as JsonNode and extract
only the id; reconstruct the DTO from the input fields.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 19:58:40 +02:00
luklpz 997ed99895 fix: use byte[] for PS XML body; catch HttpMessageConversionException
ByteArrayHttpMessageConverter reliably handles application/xml content
type via its */* support, avoiding potential StringHttpMessageConverter
selection issues. Also add HttpMessageConversionException to per-item
catches and widen outer infrastructure catch to RuntimeException, so
any response-parsing failure is recorded in SyncLog.errorDetails
instead of propagating as HTTP 500.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 19:50:03 +02:00
luklpz 121dc329f8 fix: catch RestClientException in all sync services
Per-item catch blocks only handled DolibarrApiException|PrestashopApiException,
letting network-level errors (RestClientException wrapping SSL, timeout, etc.)
propagate uncaught → HTTP 500. Also add outer catch for infrastructure failures
(e.g. getProducts() itself failing) so SyncLog always records the error in
errorDetails and the service returns a valid SyncResult instead of throwing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 19:28:49 +02:00
luklpz cfce84eb4d fix: send XML body on PS WebService write operations
PS WebService requires XML request body even when output_format=JSON.
Build XML manually in PrestashopClient for createProduct, updateProduct
and updateStockAvailable. Add link_rewrite slug generation and XML
character escaping. Response parsing (JSON) unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 19:14:16 +02:00
luklpz 588c1db5c3 fix: bypass SSL verification for loading.net self-signed cert
RestClient on Railway rejected the untrusted certificate on
prestashop.loading.net, causing SSLHandshakeException on every
HTTP call. Add SslConfig with a trust-all SimpleClientHttpRequestFactory
and inject it into both DolibarrClientConfig and PrestashopClientConfig.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 19:07:47 +02:00
luklpz 45b805a81a feat: add sync-service Spring Boot middleware
Dolibarr-PrestaShop integration service (Fases 0-5):
- HTTP clients for Dolibarr REST API and PrestaShop Webservice
- JPA entities + Flyway migrations (product_mapping, order_mapping, sync_log)
- Three sync flows: product push, stock push, order pull
- Configurable @Scheduled jobs (disabled in dev, enabled in prod)
- REST API with Basic Auth and Swagger UI

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 14:09:46 +02:00