Search in sources :

Example 1 with PersistableCatalogCategoryEntry

use of com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry in project shopizer by shopizer-ecommerce.

the class PersistableCatalogCategoryEntryMapper method merge.

@Override
public CatalogCategoryEntry merge(PersistableCatalogCategoryEntry source, CatalogCategoryEntry destination, MerchantStore store, Language language) {
    Validate.notNull(source, "CatalogEntry must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    Validate.notNull(source.getProductCode(), "ProductCode must not be null");
    Validate.notNull(source.getCategoryCode(), "CategoryCode must not be null");
    Validate.notNull(source.getCatalog(), "Catalog must not be null");
    if (destination == null) {
        destination = new CatalogCategoryEntry();
    }
    destination.setId(source.getId());
    destination.setVisible(source.isVisible());
    try {
        String catalog = source.getCatalog();
        Catalog catalogModel = catalogFacade.getCatalog(catalog, store);
        if (catalogModel == null) {
            throw new ConversionRuntimeException("Error while converting CatalogEntry product [" + source.getCatalog() + "] not found");
        }
        destination.setCatalog(catalogModel);
        /*			Product productModel = productFacade.getProduct(source.getProductCode(), store);
			if(productModel == null) {
				throw new ConversionRuntimeException("Error while converting CatalogEntry product [" + source.getProductCode() + "] not found");
			}*/
        // destination.setProduct(productModel);
        Category categoryModel = categoryFacade.getByCode(source.getCategoryCode(), store);
        if (categoryModel == null) {
            throw new ConversionRuntimeException("Error while converting CatalogEntry category [" + source.getCategoryCode() + "] not found");
        }
        destination.setCategory(categoryModel);
    } catch (Exception e) {
        throw new ConversionRuntimeException("Error while converting CatalogEntry", e);
    }
    return destination;
}
Also used : CatalogCategoryEntry(com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry) PersistableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry) Category(com.salesmanager.core.model.catalog.category.Category) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 2 with PersistableCatalogCategoryEntry

use of com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry in project shopizer by shopizer-ecommerce.

the class CatalogFacadeImpl method addCatalogEntry.

@Override
public ReadableCatalogCategoryEntry addCatalogEntry(PersistableCatalogCategoryEntry entry, MerchantStore store, Language language) {
    Validate.notNull(entry, "PersistableCatalogEntry cannot be null");
    Validate.notNull(entry.getCatalog(), "CatalogEntry.catalog cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Catalog catalog = catalogService.getByCode(entry.getCatalog(), store).orElseThrow(() -> new ResourceNotFoundException("catalog [" + entry.getCatalog() + "] not found"));
    CatalogCategoryEntry catalogEntryModel = persistableCatalogEntryMapper.convert(entry, store, language);
    catalogEntryService.add(catalogEntryModel, catalog);
    return readableCatalogEntryMapper.convert(catalogEntryModel, store, language);
}
Also used : PersistableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry) ReadableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry) CatalogCategoryEntry(com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Aggregations

Catalog (com.salesmanager.core.model.catalog.catalog.Catalog)2 CatalogCategoryEntry (com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry)2 PersistableCatalogCategoryEntry (com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry)2 Category (com.salesmanager.core.model.catalog.category.Category)1 PersistableCatalog (com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)1 ReadableCatalog (com.salesmanager.shop.model.catalog.catalog.ReadableCatalog)1 ReadableCatalogCategoryEntry (com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry)1 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)1 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)1