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"
*/
public DolibarrProductDto getProductByRef(String ref) {
String filter = "(t.ref:=:'%s')".formatted(ref);
List<DolibarrProductDto> results = restClient.get()
.uri(u -> u.path("/products")
.queryParam("ref", ref)
.queryParam("sqlfilters", filter)
.queryParam("limit", 1)
.build())
.retrieve()

View File

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

View File

@ -147,8 +147,15 @@ public class OrderSyncService {
}
private DolibarrThirdpartyDto resolveCustomer(PrestashopOrderDto psOrder) {
PrestashopCustomerDto psCustomer = prestashopClient.getCustomer(
Integer.parseInt(psOrder.idCustomer()));
// Guest orders have id_customer=0 — skip getCustomer call to avoid 404
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
? (psCustomer.firstname() + " " + psCustomer.lastname()).trim()

View File

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