use of com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method saveAttribute.
@Override
public ReadableProductAttributeEntity saveAttribute(Long productId, PersistableProductAttribute attribute, MerchantStore store, Language language) {
Validate.notNull(productId, "Product id cannot be null");
Validate.notNull(attribute, "ProductAttribute cannot be null");
Validate.notNull(attribute.getOption(), "ProductAttribute option cannot be null");
Validate.notNull(attribute.getOptionValue(), "ProductAttribute option value cannot be null");
Validate.notNull(store, "Store cannot be null");
attribute.setProductId(productId);
ProductAttribute attr = new ProductAttribute();
if (attribute.getId() != null && attribute.getId().longValue() > 0) {
attr = productAttributeService.getById(attribute.getId());
if (attr == null) {
throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found");
}
if (productId != attr.getProduct().getId().longValue()) {
throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found for product [" + productId + "]");
}
}
attr = persistableProductAttributeMapper.merge(attribute, attr, store, language);
try {
productAttributeService.saveOrUpdate(attr);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while saving ProductAttribute", e);
}
// refresh
attr = productAttributeService.getById(attr.getId());
ReadableProductAttributeEntity readable = readableProductAttributeMapper.convert(attr, store, language);
return readable;
}
use of com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method getAttribute.
@Override
public ReadableProductAttributeEntity getAttribute(Long productId, Long attributeId, MerchantStore store, Language language) {
ProductAttribute attr = productAttributeService.getById(attributeId);
if (attr == null) {
throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and store [" + store.getCode() + "]");
}
if (attr.getProduct().getId().longValue() != productId) {
throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and product [" + productId + "]");
}
if (attr.getProduct().getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and product [" + productId + "] and store [" + store.getCode() + "]");
}
ReadableProductAttributeEntity readable = readableProductAttributeMapper.convert(attr, store, language);
return readable;
}
use of com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity 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.ReadableProductAttributeEntity in project shopizer by shopizer-ecommerce.
the class ProductAttributeOptionApi method createAttribute.
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = { "/private/product/{id}/attribute" }, method = RequestMethod.POST)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public Entity createAttribute(@PathVariable Long id, @Valid @RequestBody PersistableProductAttribute attribute, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
ReadableProductAttributeEntity attributeEntity = productOptionFacade.saveAttribute(id, attribute, merchantStore, language);
Entity entity = new Entity();
entity.setId(attributeEntity.getId());
return entity;
}
use of com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method getAttributesList.
@Override
public ReadableProductAttributeList getAttributesList(Long productId, MerchantStore store, Language language, int page, int count) {
try {
Product product = this.product(productId, store);
ReadableProductAttributeList attrList = new ReadableProductAttributeList();
Page<ProductAttribute> attr = null;
if (language != null) {
// all entry
// attributes = productAttributeService.getByProductId(store, product, language);
attr = productAttributeService.getByProductId(store, product, language, page, count);
attrList.setRecordsTotal(attr.getTotalElements());
attrList.setNumber(attr.getSize());
attrList.setTotalPages(attr.getTotalPages());
} else {
attr = productAttributeService.getByProductId(store, product, page, count);
attrList.setRecordsTotal(attr.getTotalElements());
attrList.setNumber(attr.getSize());
attrList.setTotalPages(attr.getTotalPages());
}
List<ReadableProductAttributeEntity> values = attr.getContent().stream().map(attribute -> readableProductAttributeMapper.convert(attribute, store, language)).collect(Collectors.toList());
attrList.setAttributes(values);
return attrList;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting attributes", e);
}
}
Aggregations