Manejo de direcciones de cliente
This commit is contained in:
parent
51959292e0
commit
e2b6966cef
|
|
@ -238,6 +238,25 @@ public class PrestashopClient {
|
||||||
return response != null ? response.customer() : null;
|
return response != null ? response.customer() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PrestashopAddressDto getAddress(Integer id) {
|
||||||
|
try {
|
||||||
|
PrestashopAddressDto.SingleResponse response = restClient.get()
|
||||||
|
.uri(u -> u.path("/addresses/{id}")
|
||||||
|
.queryParam("ws_key", wsKey)
|
||||||
|
.queryParam("output_format", "JSON")
|
||||||
|
.build(id))
|
||||||
|
.retrieve()
|
||||||
|
.body(PrestashopAddressDto.SingleResponse.class);
|
||||||
|
return response != null ? response.address() : null;
|
||||||
|
} catch (PrestashopApiException e) {
|
||||||
|
if (e.getStatusCode() != null && e.getStatusCode().value() == 404) {
|
||||||
|
log.debug("PS address not found id={}", id);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── XML builders ──────────────────────────────────────────────────────
|
// ── XML builders ──────────────────────────────────────────────────────
|
||||||
// PS WebService requires XML body for writes; output_format=JSON only affects the response.
|
// PS WebService requires XML body for writes; output_format=JSON only affects the response.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.teterialosjuanjos.tfg.sync_service.integration.prestashop.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public record PrestashopAddressDto (
|
||||||
|
Integer id,
|
||||||
|
@JsonProperty("id_customer") String idCustomer,
|
||||||
|
@JsonProperty("id_country") String idCountry,
|
||||||
|
String firstname,
|
||||||
|
String lastname,
|
||||||
|
String address1,
|
||||||
|
String address2,
|
||||||
|
String city,
|
||||||
|
@JsonProperty("postcode") String postcode,
|
||||||
|
String phone,
|
||||||
|
String phone_mobile
|
||||||
|
){
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public record SingleResponse(PrestashopAddressDto address){}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import com.teterialosjuanjos.tfg.sync_service.integration.dolibarr.dto.DolibarrO
|
||||||
import com.teterialosjuanjos.tfg.sync_service.integration.dolibarr.dto.DolibarrThirdpartyDto;
|
import com.teterialosjuanjos.tfg.sync_service.integration.dolibarr.dto.DolibarrThirdpartyDto;
|
||||||
import com.teterialosjuanjos.tfg.sync_service.integration.dolibarr.exception.DolibarrApiException;
|
import com.teterialosjuanjos.tfg.sync_service.integration.dolibarr.exception.DolibarrApiException;
|
||||||
import com.teterialosjuanjos.tfg.sync_service.integration.prestashop.PrestashopClient;
|
import com.teterialosjuanjos.tfg.sync_service.integration.prestashop.PrestashopClient;
|
||||||
|
import com.teterialosjuanjos.tfg.sync_service.integration.prestashop.dto.PrestashopAddressDto;
|
||||||
import com.teterialosjuanjos.tfg.sync_service.integration.prestashop.dto.PrestashopCustomerDto;
|
import com.teterialosjuanjos.tfg.sync_service.integration.prestashop.dto.PrestashopCustomerDto;
|
||||||
import com.teterialosjuanjos.tfg.sync_service.integration.prestashop.dto.PrestashopOrderDto;
|
import com.teterialosjuanjos.tfg.sync_service.integration.prestashop.dto.PrestashopOrderDto;
|
||||||
import com.teterialosjuanjos.tfg.sync_service.integration.prestashop.exception.PrestashopApiException;
|
import com.teterialosjuanjos.tfg.sync_service.integration.prestashop.exception.PrestashopApiException;
|
||||||
|
|
@ -170,6 +171,23 @@ public class OrderSyncService {
|
||||||
String city = null;
|
String city = null;
|
||||||
String zip = null;
|
String zip = null;
|
||||||
|
|
||||||
|
if (psCustomer != null && psCustomer.idDefaultAddress() != null && !psCustomer.idDefaultAddress().isBlank()) {
|
||||||
|
try {
|
||||||
|
Integer addressId = Integer.parseInt(psCustomer.idDefaultAddress());
|
||||||
|
PrestashopAddressDto psAddress = prestashopClient.getAddress(addressId);
|
||||||
|
if (psAddress != null) {
|
||||||
|
address = psAddress.address1();
|
||||||
|
if (psAddress.address2() != null && !psAddress.address2().isBlank()) {
|
||||||
|
address = (address != null ? address + " " : "") + psAddress.address2();
|
||||||
|
}
|
||||||
|
city = psAddress.city();
|
||||||
|
zip = psAddress.postcode();
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
log.warn("Invalid address ID for customer {}: {}", psOrder.idCustomer(), psCustomer.idDefaultAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return dolibarrClient.getOrCreateThirdparty(email, name, address, city, zip);
|
return dolibarrClient.getOrCreateThirdparty(email, name, address, city, zip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue