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>
This commit is contained in:
luklpz 2026-05-15 08:05:18 +02:00
parent 22c92a1ee2
commit aeec27f7af
4 changed files with 15 additions and 5 deletions

View File

@ -49,9 +49,10 @@ public class DolibarrClient {
* @param ref SKU value, e.g. "PROD-001" * @param ref SKU value, e.g. "PROD-001"
*/ */
public DolibarrProductDto getProductByRef(String ref) { public DolibarrProductDto getProductByRef(String ref) {
String filter = "(t.ref:=:'%s')".formatted(ref);
List<DolibarrProductDto> results = restClient.get() List<DolibarrProductDto> results = restClient.get()
.uri(u -> u.path("/products") .uri(u -> u.path("/products")
.queryParam("ref", ref) .queryParam("sqlfilters", filter)
.queryParam("limit", 1) .queryParam("limit", 1)
.build()) .build())
.retrieve() .retrieve()

View File

@ -68,12 +68,14 @@ public class PrestashopClient {
* @param reference SKU value, e.g. "PROD-001" * @param reference SKU value, e.g. "PROD-001"
*/ */
public Optional<PrestashopProductDto> getProductByReference(String reference) { public Optional<PrestashopProductDto> getProductByReference(String reference) {
// PS WebService requires [value] brackets for exact-match filtering
String exactRef = "[" + reference + "]";
PrestashopProductDto.ListResponse response = restClient.get() PrestashopProductDto.ListResponse response = restClient.get()
.uri(u -> u.path("/products") .uri(u -> u.path("/products")
.queryParam("ws_key", wsKey) .queryParam("ws_key", wsKey)
.queryParam("output_format", "JSON") .queryParam("output_format", "JSON")
.queryParam("display", "full") .queryParam("display", "full")
.queryParam("filter[reference]", reference) .queryParam("filter[reference]", exactRef)
.build()) .build())
.retrieve() .retrieve()
.body(PrestashopProductDto.ListResponse.class); .body(PrestashopProductDto.ListResponse.class);

View File

@ -147,8 +147,15 @@ public class OrderSyncService {
} }
private DolibarrThirdpartyDto resolveCustomer(PrestashopOrderDto psOrder) { private DolibarrThirdpartyDto resolveCustomer(PrestashopOrderDto psOrder) {
PrestashopCustomerDto psCustomer = prestashopClient.getCustomer( // Guest orders have id_customer=0 — skip getCustomer call to avoid 404
Integer.parseInt(psOrder.idCustomer())); boolean isGuest = psOrder.idCustomer() == null
|| psOrder.idCustomer().isBlank()
|| "0".equals(psOrder.idCustomer());
PrestashopCustomerDto psCustomer = null;
if (!isGuest) {
psCustomer = prestashopClient.getCustomer(Integer.parseInt(psOrder.idCustomer()));
}
String name = psCustomer != null String name = psCustomer != null
? (psCustomer.firstname() + " " + psCustomer.lastname()).trim() ? (psCustomer.firstname() + " " + psCustomer.lastname()).trim()

View File

@ -106,7 +106,7 @@ public class StockSyncService {
PrestashopStockAvailableDto current = stockOpt.get(); PrestashopStockAvailableDto current = stockOpt.get();
int targetQty = dolProduct.stockReel().intValue(); int targetQty = dolProduct.stockReel().intValue();
int currentQty = Integer.parseInt(current.quantity()); int currentQty = (int) Double.parseDouble(current.quantity());
if (targetQty == currentQty) { if (targetQty == currentQty) {
return false; return false;