use of com.salesmanager.core.model.reference.language.Language 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.core.model.reference.language.Language 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.core.model.reference.language.Language 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.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class PersistableManufacturerPopulator method populate.
@Override
public Manufacturer populate(PersistableManufacturer source, Manufacturer target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(languageService, "Requires to set LanguageService");
try {
target.setMerchantStore(store);
target.setCode(source.getCode());
if (!CollectionUtils.isEmpty(source.getDescriptions())) {
Set<com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription> descriptions = new HashSet<com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription>();
for (ManufacturerDescription description : source.getDescriptions()) {
com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription desc = new com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription();
if (desc.getId() != null && desc.getId().longValue() > 0) {
desc.setId(description.getId());
}
if (target.getDescriptions() != null) {
for (com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription d : target.getDescriptions()) {
if (d.getLanguage().getCode().equals(description.getLanguage()) || desc.getId() != null && d.getId().longValue() == desc.getId().longValue()) {
desc = d;
}
}
}
desc.setManufacturer(target);
desc.setDescription(description.getDescription());
desc.setName(description.getName());
Language lang = languageService.getByCode(description.getLanguage());
if (lang == null) {
throw new ConversionException("Language is null for code " + description.getLanguage() + " use language ISO code [en, fr ...]");
}
desc.setLanguage(lang);
descriptions.add(desc);
}
target.setDescriptions(descriptions);
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ReadableProductInstanceMapper method merge.
@Override
public ReadableProductInstance merge(ProductInstance source, ReadableProductInstance destination, MerchantStore store, Language language) {
Validate.notNull(source, "Product instance cannot be null");
Validate.notNull(source.getProduct(), "Product cannot be null");
if (destination == null) {
destination = new ReadableProductInstance();
}
destination.setSortOrder(source.getSortOrder() != null ? source.getSortOrder().intValue() : 0);
destination.setAvailable(source.isAvailable());
destination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
destination.setId(source.getId());
destination.setDefaultSelection(source.isDefaultSelection());
destination.setProductId(source.getProduct().getId());
destination.setSku(source.getSku());
destination.setSortOrder(source.getSortOrder());
destination.setCode(source.getCode());
// get product
Product baseProduct = source.getProduct();
if (baseProduct == null) {
throw new ResourceNotFoundException("Product instances do not include the parent product [" + destination.getSku() + "]");
}
destination.setProductShipeable(baseProduct.isProductShipeable());
// destination.setStore(null);
destination.setStore(store.getCode());
destination.setVariant(readableProductVariationMapper.convert(source.getVariant(), store, language));
destination.setVariantValue(readableProductVariationMapper.convert(source.getVariantValue(), store, language));
if (source.getProductInstanceGroup() != null) {
Set<String> nameSet = new HashSet<>();
List<ReadableImage> instanceImages = source.getProductInstanceGroup().getImages().stream().map(i -> this.image(i, store, language)).filter(e -> nameSet.add(e.getImageUrl())).collect(Collectors.toList());
destination.setImages(instanceImages);
}
if (!CollectionUtils.isEmpty(source.getAvailabilities())) {
List<ReadableInventory> inventories = source.getAvailabilities().stream().map(i -> readableInventoryMapper.convert(i, store, language)).collect(Collectors.toList());
destination.setInventory(inventories);
}
return destination;
}
Aggregations