use of com.salesmanager.shop.model.catalog.product.type.PersistableProductType in project shopizer by shopizer-ecommerce.
the class ProductTypeFacadeImpl method save.
@Override
public Long save(PersistableProductType type, MerchantStore store, Language language) {
Validate.notNull(type, "ProductType cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(type.getCode(), "ProductType code cannot be empty");
try {
if (this.exists(type.getCode(), store, language)) {
throw new OperationNotAllowedException("Product type [" + type.getCode() + "] already exist for store [" + store.getCode() + "]");
}
ProductType model = persistableProductTypeMapper.convert(type, store, language);
model.setMerchantStore(store);
ProductType saved = productTypeService.saveOrUpdate(model);
return saved.getId();
} catch (Exception e) {
throw new ServiceRuntimeException("An exception occured while saving product type", e);
}
}
use of com.salesmanager.shop.model.catalog.product.type.PersistableProductType in project shopizer by shopizer-ecommerce.
the class ProductTypeFacadeImpl method update.
@Override
public void update(PersistableProductType type, Long id, MerchantStore store, Language language) {
Validate.notNull(type, "ProductType cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(id, "id cannot be empty");
try {
ProductType t = productTypeService.getById(id, store, language);
if (t == null) {
throw new ResourceNotFoundException("Product type [" + type.getCode() + "] does not exist for store [" + store.getCode() + "]");
}
type.setId(t.getId());
type.setCode(t.getCode());
ProductType model = persistableProductTypeMapper.merge(type, t, store, language);
model.setMerchantStore(store);
productTypeService.saveOrUpdate(model);
} catch (Exception e) {
throw new ServiceRuntimeException("An exception occured while saving product type", e);
}
}
use of com.salesmanager.shop.model.catalog.product.type.PersistableProductType in project shopizer by shopizer-ecommerce.
the class PersistableProductTypeMapper method type.
private ProductType type(PersistableProductType type, ProductType destination) throws ServiceException {
if (destination == null) {
destination = new ProductType();
}
destination.setCode(type.getCode());
destination.setId(type.getId());
destination.setAllowAddToCart(type.isAllowAddToCart());
destination.setVisible(type.isVisible());
// destination.set
List<com.salesmanager.core.model.catalog.product.type.ProductTypeDescription> descriptions = new ArrayList<com.salesmanager.core.model.catalog.product.type.ProductTypeDescription>();
if (!CollectionUtils.isEmpty(type.getDescriptions())) {
for (ProductTypeDescription d : type.getDescriptions()) {
com.salesmanager.core.model.catalog.product.type.ProductTypeDescription desc = typeDescription(d, destination, d.getLanguage());
descriptions.add(desc);
}
destination.setDescriptions(new HashSet<com.salesmanager.core.model.catalog.product.type.ProductTypeDescription>(descriptions));
}
return destination;
}
Aggregations