use of com.salesmanager.shop.model.catalog.product.type.ReadableProductType in project shopizer by shopizer-ecommerce.
the class ReadableProductDefinitionMapper method merge.
@Override
public ReadableProductDefinition merge(Product source, ReadableProductDefinition destination, MerchantStore store, Language language) {
Validate.notNull(source, "Product cannot be null");
Validate.notNull(destination, "Product destination cannot be null");
ReadableProductDefinition returnDestination = destination;
if (language == null) {
returnDestination = new ReadableProductDefinitionFull();
}
List<com.salesmanager.shop.model.catalog.product.ProductDescription> fulldescriptions = new ArrayList<com.salesmanager.shop.model.catalog.product.ProductDescription>();
returnDestination.setIdentifier(source.getSku());
returnDestination.setId(source.getId());
returnDestination.setVisible(source.isAvailable());
returnDestination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
ProductDescription description = null;
if (source.getDescriptions() != null && source.getDescriptions().size() > 0) {
for (ProductDescription desc : source.getDescriptions()) {
if (language != null && desc.getLanguage() != null && desc.getLanguage().getId().intValue() == language.getId().intValue()) {
description = desc;
break;
} else {
fulldescriptions.add(populateDescription(desc));
}
}
}
if (description != null) {
com.salesmanager.shop.model.catalog.product.ProductDescription tragetDescription = populateDescription(description);
returnDestination.setDescription(tragetDescription);
}
if (source.getManufacturer() != null) {
ReadableManufacturer manufacturer = readableManufacturerMapper.convert(source.getManufacturer(), store, language);
returnDestination.setManufacturer(manufacturer);
}
if (!CollectionUtils.isEmpty(source.getCategories())) {
List<ReadableCategory> categoryList = new ArrayList<ReadableCategory>();
for (Category category : source.getCategories()) {
ReadableCategory readableCategory = readableCategoryMapper.convert(category, store, language);
categoryList.add(readableCategory);
}
returnDestination.setCategories(categoryList);
}
ProductSpecification specifications = new ProductSpecification();
specifications.setHeight(source.getProductHeight());
specifications.setLength(source.getProductLength());
specifications.setWeight(source.getProductWeight());
specifications.setWidth(source.getProductWidth());
if (!StringUtils.isBlank(store.getSeizeunitcode())) {
specifications.setDimensionUnitOfMeasure(DimensionUnitOfMeasure.valueOf(store.getSeizeunitcode().toLowerCase()));
}
if (!StringUtils.isBlank(store.getWeightunitcode())) {
specifications.setWeightUnitOfMeasure(WeightUnitOfMeasure.valueOf(store.getWeightunitcode().toLowerCase()));
}
returnDestination.setProductSpecifications(specifications);
if (source.getType() != null) {
ReadableProductType readableType = readableProductTypeMapper.convert(source.getType(), store, language);
returnDestination.setType(readableType);
}
returnDestination.setSortOrder(source.getSortOrder());
// images
Set<ProductImage> images = source.getImages();
if (CollectionUtils.isNotEmpty(images)) {
List<ReadableImage> imageList = images.stream().map(i -> this.convertImage(source, i, store)).collect(Collectors.toList());
returnDestination.setImages(imageList);
}
// quantity
ProductAvailability availability = null;
for (ProductAvailability a : source.getAvailabilities()) {
availability = a;
returnDestination.setCanBePurchased(availability.getProductStatus());
returnDestination.setQuantity(availability.getProductQuantity() == null ? 1 : availability.getProductQuantity());
}
FinalPrice price = null;
try {
price = pricingService.calculateProductPrice(source);
} catch (ServiceException e) {
throw new ConversionRuntimeException("Unable to get product price", e);
}
if (price != null) {
returnDestination.setPrice(price.getStringPrice());
}
if (returnDestination instanceof ReadableProductDefinitionFull) {
((ReadableProductDefinitionFull) returnDestination).setDescriptions(fulldescriptions);
}
return returnDestination;
}
use of com.salesmanager.shop.model.catalog.product.type.ReadableProductType in project shopizer by shopizer-ecommerce.
the class ProductTypeFacadeImpl method get.
@Override
public ReadableProductType get(MerchantStore store, String code, Language language) {
ProductType t;
try {
t = productTypeService.getByCode(code, store, language);
} catch (ServiceException e) {
throw new RuntimeException("An exception occured while getting product type [" + code + "] for merchant store [" + store.getCode() + "]", e);
}
if (t == null) {
throw new ResourceNotFoundException("Product type [" + code + "] not found for merchant [" + store.getCode() + "]");
}
ReadableProductType readableType = readableProductTypeMapper.convert(t, store, language);
return readableType;
}
use of com.salesmanager.shop.model.catalog.product.type.ReadableProductType in project shopizer by shopizer-ecommerce.
the class ReadableProductPopulator method type.
private ReadableProductType type(ProductType type, Language language) {
ReadableProductType readableType = new ReadableProductType();
readableType.setCode(type.getCode());
readableType.setId(type.getId());
if (!CollectionUtils.isEmpty(type.getDescriptions())) {
Optional<ProductTypeDescription> desc = type.getDescriptions().stream().filter(t -> t.getLanguage().getCode().equals(language.getCode())).map(d -> typeDescription(d)).findFirst();
if (desc.isPresent()) {
readableType.setDescription(desc.get());
}
}
return readableType;
}
use of com.salesmanager.shop.model.catalog.product.type.ReadableProductType in project shopizer by shopizer-ecommerce.
the class ReadableProductTypeMapper method type.
private ReadableProductType type(ProductType type, Language language) {
ReadableProductType readableType = null;
if (language != null) {
readableType = new ReadableProductType();
if (!CollectionUtils.isEmpty(type.getDescriptions())) {
Optional<ProductTypeDescription> desc = type.getDescriptions().stream().filter(t -> t.getLanguage().getCode().equals(language.getCode())).map(d -> typeDescription(d)).findFirst();
if (desc.isPresent()) {
readableType.setDescription(desc.get());
}
}
} else {
readableType = new ReadableProductTypeFull();
List<ProductTypeDescription> descriptions = type.getDescriptions().stream().map(t -> this.typeDescription(t)).collect(Collectors.toList());
((ReadableProductTypeFull) readableType).setDescriptions(descriptions);
}
readableType.setCode(type.getCode());
readableType.setId(type.getId());
readableType.setVisible(type.getVisible() != null && type.getVisible().booleanValue() ? true : false);
readableType.setAllowAddToCart(type.getAllowAddToCart() != null && type.getAllowAddToCart().booleanValue() ? true : false);
return readableType;
}
use of com.salesmanager.shop.model.catalog.product.type.ReadableProductType in project shopizer by shopizer-ecommerce.
the class ReadableProductDefinitionMapper method merge.
@Override
public ReadableProductDefinition merge(Product source, ReadableProductDefinition destination, MerchantStore store, Language language) {
Validate.notNull(source, "Product cannot be null");
Validate.notNull(destination, "Product destination cannot be null");
ReadableProductDefinition returnDestination = destination;
if (language == null) {
returnDestination = new ReadableProductDefinitionFull();
}
List<com.salesmanager.shop.model.catalog.product.ProductDescription> fulldescriptions = new ArrayList<com.salesmanager.shop.model.catalog.product.ProductDescription>();
returnDestination.setIdentifier(source.getSku());
returnDestination.setId(source.getId());
returnDestination.setVisible(source.isAvailable());
returnDestination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
ProductDescription description = null;
if (source.getDescriptions() != null && source.getDescriptions().size() > 0) {
for (ProductDescription desc : source.getDescriptions()) {
if (language != null && desc.getLanguage() != null && desc.getLanguage().getId().intValue() == language.getId().intValue()) {
description = desc;
break;
} else {
fulldescriptions.add(populateDescription(desc));
}
}
}
if (description != null) {
com.salesmanager.shop.model.catalog.product.ProductDescription tragetDescription = populateDescription(description);
returnDestination.setDescription(tragetDescription);
}
if (source.getManufacturer() != null) {
ReadableManufacturer manufacturer = readableManufacturerMapper.convert(source.getManufacturer(), store, language);
returnDestination.setManufacturer(manufacturer);
}
if (!CollectionUtils.isEmpty(source.getCategories())) {
List<ReadableCategory> categoryList = new ArrayList<ReadableCategory>();
for (Category category : source.getCategories()) {
ReadableCategory readableCategory = readableCategoryMapper.convert(category, store, language);
categoryList.add(readableCategory);
}
returnDestination.setCategories(categoryList);
}
ProductSpecification specifications = new ProductSpecification();
specifications.setHeight(source.getProductHeight());
specifications.setLength(source.getProductLength());
specifications.setWeight(source.getProductWeight());
specifications.setWidth(source.getProductWidth());
if (!StringUtils.isBlank(store.getSeizeunitcode())) {
specifications.setDimensionUnitOfMeasure(DimensionUnitOfMeasure.valueOf(store.getSeizeunitcode().toLowerCase()));
}
if (!StringUtils.isBlank(store.getWeightunitcode())) {
specifications.setWeightUnitOfMeasure(WeightUnitOfMeasure.valueOf(store.getWeightunitcode().toLowerCase()));
}
returnDestination.setProductSpecifications(specifications);
if (source.getType() != null) {
ReadableProductType readableType = readableProductTypeMapper.convert(source.getType(), store, language);
returnDestination.setType(readableType);
}
returnDestination.setSortOrder(source.getSortOrder());
// images
Set<ProductImage> images = source.getImages();
if (CollectionUtils.isNotEmpty(images)) {
List<ReadableImage> imageList = images.stream().map(i -> this.convertImage(source, i, store)).collect(Collectors.toList());
returnDestination.setImages(imageList);
}
// quantity
ProductAvailability availability = null;
for (ProductAvailability a : source.getAvailabilities()) {
availability = a;
returnDestination.setCanBePurchased(availability.getProductStatus());
returnDestination.setQuantity(availability.getProductQuantity() == null ? 1 : availability.getProductQuantity());
}
FinalPrice price = null;
try {
price = pricingService.calculateProductPrice(source);
} catch (ServiceException e) {
throw new ConversionRuntimeException("Unable to get product price", e);
}
if (price != null) {
returnDestination.setPrice(price.getStringPrice());
}
if (returnDestination instanceof ReadableProductDefinitionFull) {
((ReadableProductDefinitionFull) returnDestination).setDescriptions(fulldescriptions);
}
return returnDestination;
}
Aggregations