final MarketArea marketArea = requestData.getMarketArea();
final Retailer retailer = requestData.getMarketAreaRetailer();
final ProductMarketing productMarketing = productSku.getProductMarketing();
final ProductSkuViewBean productSkuViewBean = new ProductSkuViewBean();
productSkuViewBean.setCode(productSku.getCode());
productSkuViewBean.setName(productSku.getName());
productSkuViewBean.setI18nName(productSku.getI18nName(localizationCode));
productSkuViewBean.setDescription(productSku.getDescription());
productSkuViewBean.setDefault(productSku.isDefault());
productSkuViewBean.setSalable(productSku.isSalable(marketArea.getId()));
DateFormat dateFormat = requestUtil.getFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM);
if (productMarketing.getDateCreate() != null) {
productSkuViewBean.setDateCreate(dateFormat.format(productMarketing.getDateCreate()));
}
if (productMarketing.getDateUpdate() != null) {
productSkuViewBean.setDateUpdate(dateFormat.format(productMarketing.getDateUpdate()));
}
final ProductSkuPrice productSkuPrice = productSku.getPrice(marketArea.getId(), retailer.getId());
if(productSkuPrice != null){
productSkuViewBean.setCatalogPrice(productSkuPrice.getCatalogPrice().toString());
productSkuViewBean.setSalePrice(productSkuPrice.getSalePrice().toString());
productSkuViewBean.setPriceWithCurrencySign(productSkuPrice.getPriceWithStandardCurrencySign());
} else {
productSkuViewBean.setPriceWithCurrencySign("NA");
}
// ATTRIBUTES
List<ProductSkuAttribute> globalAttributes = productSku.getGlobalAttributes();
if(globalAttributes != null){
for (Iterator<ProductSkuAttribute> iterator = globalAttributes.iterator(); iterator.hasNext();) {
ProductSkuAttribute attribute = (ProductSkuAttribute) iterator.next();
productSkuViewBean.getGlobalAttributes().put(attribute.getAttributeDefinition().getCode(), buildViewBeanAttributeValue(requestData, attribute));
}
}
List<ProductSkuAttribute> marketAreaAttributes = productSku.getMarketAreaAttributes(marketArea.getId());
if(marketAreaAttributes != null){
for (Iterator<ProductSkuAttribute> iterator = marketAreaAttributes.iterator(); iterator.hasNext();) {
ProductSkuAttribute attribute = (ProductSkuAttribute) iterator.next();
productSkuViewBean.getMarketAreaAttributes().put(attribute.getAttributeDefinition().getCode(), buildViewBeanAttributeValue(requestData, attribute));
}
}
// ASSETS
final Asset defaultBackgroundImage = productSku.getDefaultBackgroundImage();
if (defaultBackgroundImage != null) {
String backgroundImage = engineSettingService.getProductSkuImageWebPath(defaultBackgroundImage);
productSkuViewBean.setBackgroundImage(backgroundImage);
} else {
productSkuViewBean.setBackgroundImage("");
}
final Asset defaultPackshotImage = productMarketing.getDefaultPackshotImage(ImageSize.HD.name());
if (defaultPackshotImage != null) {
String carouselImage = engineSettingService.getProductSkuImageWebPath(defaultPackshotImage);
productSkuViewBean.setCarouselImage(carouselImage);
} else {
productSkuViewBean.setCarouselImage("");
}
final Asset defaultIconImage = productSku.getDefaultThumbnailImage();
if (defaultIconImage != null) {
String iconImage = engineSettingService.getProductSkuImageWebPath(defaultIconImage);
productSkuViewBean.setIconImage(iconImage);
} else {
productSkuViewBean.setIconImage("");
}
productSkuViewBean.setProductMarketing(buildViewBeanProductMarketing(requestData, productMarketing));
return productSkuViewBean;
}