Skip to content

Commit 0e4516b

Browse files
committed
DEVX-813: adding toProductImport
1 parent 41bb560 commit 0e4516b

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

  • commercetools/commercetools-importapi-utils/src/main/java/com/commercetools/sdk

commercetools/commercetools-importapi-utils/src/main/java/com/commercetools/sdk/ProductUtil.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,29 @@ public ProductDraftImport toProductDraftImport(ProductProjection product) {
6666
}
6767

6868
public ProductImport toProductImport(ProductProjection product) {
69-
69+
var productImport = ProductImport.builder()
70+
.key(product.getKey())
71+
.productType(p -> p.key(keyResolverService.resolveKey(product.getProductType())))
72+
.name(l -> getLocalizedStringBuilder(product.getName()))
73+
.slug(l -> getLocalizedStringBuilder(product.getSlug()))
74+
.description(Optional.ofNullable(product.getDescription())
75+
.map(CommonImportUtil::getLocalizedStringBuilder)
76+
.map(LocalizedStringBuilder::build)
77+
.orElse(null))
78+
.categories(extractCategoryKeyReference(product))
79+
.metaTitle(Optional.ofNullable(product.getMetaTitle())
80+
.map(CommonImportUtil::getLocalizedStringBuilder)
81+
.map(LocalizedStringBuilder::build)
82+
.orElse(null))
83+
.metaDescription(
84+
(com.commercetools.importapi.models.common.LocalizedString) product.getMetaDescription())
85+
.metaKeywords((com.commercetools.importapi.models.common.LocalizedString) product.getMetaKeywords())
86+
.taxCategory(getTaxCategoryKeyReference(product))
87+
.state(getStateKeyReference(product))
88+
.priceMode(mapPriceModeToImportApi(product))
89+
.attributes(
90+
product.getAttributes().stream().map(ProductUtil::mapAttribute).collect(Collectors.toList()));
91+
return productImport.build();
7092
}
7193

7294
private com.commercetools.importapi.models.common.ProductPriceModeEnum mapPriceModeToImportApi(

0 commit comments

Comments
 (0)