Skip to content

Commit a9bf00d

Browse files
authored
Merge pull request #1233 from commercetools/SUPPORT-36587/customer-address-custom-type-resolution
SUPPORT-36587: support custom type resolution in customer's address
2 parents 317d55b + 2caa731 commit a9bf00d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/main/java/com/commercetools/sync/customers/utils/CustomerReferenceResolutionUtils.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private static CustomerDraft mapToCustomerDraft(
111111
.dateOfBirth(customer.getDateOfBirth())
112112
.isEmailVerified(customer.getIsEmailVerified())
113113
.vatId(customer.getVatId())
114-
.addresses(mapToAddressesDraft(customer.getAddresses()))
114+
.addresses(mapToAddressesDraft(customer.getAddresses(), referenceIdToKeyCache))
115115
.defaultBillingAddress(
116116
getAddressIndex(customer.getAddresses(), customer.getDefaultBillingAddressId()))
117117
.billingAddresses(
@@ -143,7 +143,9 @@ private static CustomerGroupResourceIdentifier mapToCustomerGroupResourceIdentif
143143
return null;
144144
}
145145

146-
private static List<BaseAddress> mapToAddressesDraft(@Nonnull List<Address> addresses) {
146+
private static List<BaseAddress> mapToAddressesDraft(
147+
@Nonnull List<Address> addresses,
148+
@Nonnull final ReferenceIdToKeyCache referenceIdToKeyCache) {
147149
if (addresses.isEmpty()) {
148150
return emptyList();
149151
}
@@ -178,8 +180,9 @@ private static List<BaseAddress> mapToAddressesDraft(@Nonnull List<Address> addr
178180
.externalId(address.getExternalId());
179181

180182
if (address.getCustom() != null) {
181-
builder.custom(
182-
CustomFieldsDraftBuilder.of().fields(address.getCustom().getFields()).build());
183+
CustomFieldsDraft draft =
184+
mapToCustomFieldsDraft(address.getCustom(), referenceIdToKeyCache);
185+
builder.custom(draft);
183186
}
184187
return builder.build();
185188
})

src/main/java/com/commercetools/sync/customers/utils/CustomerTransformUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static java.util.stream.Collectors.toSet;
44

55
import com.commercetools.api.client.ProjectApiRoot;
6+
import com.commercetools.api.models.common.Address;
67
import com.commercetools.api.models.common.Reference;
78
import com.commercetools.api.models.customer.Customer;
89
import com.commercetools.api.models.customer.CustomerDraft;
@@ -84,6 +85,17 @@ private CompletableFuture<Void> transformCustomTypeReference(
8485
.map(Reference::getId)
8586
.collect(toSet());
8687

88+
final Set<String> setOfAddressCustomTypeIds =
89+
customers.stream()
90+
.flatMap(c -> c.getAddresses().stream())
91+
.map(Address::getCustom)
92+
.filter(Objects::nonNull)
93+
.map(CustomFields::getType)
94+
.map(Reference::getId)
95+
.collect(toSet());
96+
97+
setOfTypeIds.addAll(setOfAddressCustomTypeIds);
98+
8799
return fetchAndFillReferenceIdToKeyCache(setOfTypeIds, GraphQlQueryResource.TYPES);
88100
}
89101

0 commit comments

Comments
 (0)