use of com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity in project shopizer by shopizer-ecommerce.
the class ReadableProductAttributeMapper method merge.
@Override
public ReadableProductAttributeEntity merge(ProductAttribute source, ReadableProductAttributeEntity destination, MerchantStore store, Language language) {
ReadableProductAttributeEntity attr = new ReadableProductAttributeEntity();
if (destination != null) {
attr = destination;
}
try {
// attribute of the option
attr.setId(source.getId());
if (source.getProductAttributePrice() != null && source.getProductAttributePrice().doubleValue() > 0) {
String formatedPrice;
formatedPrice = pricingService.getDisplayAmount(source.getProductAttributePrice(), store);
attr.setProductAttributePrice(formatedPrice);
attr.setProductAttributeUnformattedPrice(pricingService.getStringAmount(source.getProductAttributePrice(), store));
}
attr.setProductAttributeWeight(source.getAttributeAdditionalWeight());
attr.setAttributeDisplayOnly(source.getAttributeDisplayOnly());
attr.setAttributeDefault(source.getAttributeDefault());
if (!StringUtils.isBlank(source.getAttributeSortOrder())) {
attr.setSortOrder(Integer.parseInt(source.getAttributeSortOrder()));
}
if (source.getProductOption() != null) {
ReadableProductOptionEntity option = readableProductOptionMapper.convert(source.getProductOption(), store, language);
attr.setOption(option);
}
if (source.getProductOptionValue() != null) {
ReadableProductOptionValueEntity optionValue = readableProductOptionValueMapper.convert(source.getProductOptionValue(), store, language);
attr.setOptionValue(optionValue);
}
} catch (Exception e) {
throw new ConversionRuntimeException("Exception while product attribute conversion", e);
}
return attr;
}
use of com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity in project shopizer by shopizer-ecommerce.
the class ReadableProductOptionMapper method merge.
@Override
public ReadableProductOptionEntity merge(ProductOption source, ReadableProductOptionEntity destination, MerchantStore store, Language language) {
ReadableProductOptionEntity readableProductOption = new ReadableProductOptionEntity();
if (language == null) {
readableProductOption = new ReadableProductOptionFull();
List<com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription> descriptions = new ArrayList<com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription>();
for (ProductOptionDescription desc : source.getDescriptions()) {
com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription d = this.description(desc);
descriptions.add(d);
}
((ReadableProductOptionFull) readableProductOption).setDescriptions(descriptions);
} else {
readableProductOption = new ReadableProductOptionEntity();
if (!CollectionUtils.isEmpty(source.getDescriptions())) {
for (ProductOptionDescription desc : source.getDescriptions()) {
if (desc != null && desc.getLanguage() != null && desc.getLanguage().getId() == language.getId()) {
com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription d = this.description(desc);
readableProductOption.setDescription(d);
}
}
}
}
readableProductOption.setCode(source.getCode());
readableProductOption.setId(source.getId());
readableProductOption.setType(source.getProductOptionType());
return readableProductOption;
}
use of com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method options.
@Override
public ReadableProductOptionList options(MerchantStore store, Language language, String name, int page, int count) {
Validate.notNull(store, "MerchantStore should not be null");
Page<ProductOption> options = productOptionService.getByMerchant(store, null, name, page, count);
ReadableProductOptionList valueList = new ReadableProductOptionList();
valueList.setTotalPages(options.getTotalPages());
valueList.setRecordsTotal(options.getTotalElements());
valueList.setNumber(options.getNumber());
List<ReadableProductOptionEntity> values = options.getContent().stream().map(option -> readableMapper.convert(option, store, null)).collect(Collectors.toList());
valueList.setOptions(values);
return valueList;
}
use of com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method saveOption.
@Override
public ReadableProductOptionEntity saveOption(PersistableProductOptionEntity option, MerchantStore store, Language language) {
Validate.notNull(option, "ProductOption cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
ProductOption optionModel = new ProductOption();
if (option.getId() != null && option.getId().longValue() > 0) {
optionModel = productOptionService.getById(store, option.getId());
if (optionModel == null) {
throw new ResourceNotFoundException("ProductOption not found for if [" + option.getId() + "] and store [" + store.getCode() + "]");
}
}
optionModel = persistableeMapper.merge(option, optionModel, store, language);
try {
productOptionService.saveOrUpdate(optionModel);
} catch (ServiceException e) {
throw new ServiceRuntimeException("An exception occured while saving ProductOption", e);
}
optionModel = productOptionService.getById(store, optionModel.getId());
ReadableProductOptionEntity readable = readableMapper.convert(optionModel, store, language);
return readable;
}
Aggregations