Search in sources :

Example 1 with ManufacturerDescription

use of com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription 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;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ConversionException(com.salesmanager.core.business.exception.ConversionException) Language(com.salesmanager.core.model.reference.language.Language) ManufacturerDescription(com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription) HashSet(java.util.HashSet)

Example 2 with ManufacturerDescription

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

the class ServicesTestSupport method manufacturer.

protected PersistableManufacturer manufacturer(String code) {
    PersistableManufacturer m = new PersistableManufacturer();
    m.setCode(code);
    m.setOrder(0);
    ManufacturerDescription desc = new ManufacturerDescription();
    desc.setLanguage("en");
    desc.setName(code);
    m.getDescriptions().add(desc);
    return m;
}
Also used : PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ManufacturerDescription(com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription)

Aggregations

ManufacturerDescription (com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 Language (com.salesmanager.core.model.reference.language.Language)1 PersistableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer)1 HashSet (java.util.HashSet)1