Search in sources :

Example 51 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.

the class ProductOptionSetFacadeImpl method list.

@Override
public List<ReadableProductOptionSet> list(MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    try {
        List<ProductOptionSet> optionSets = productOptionSetService.listByStore(store, language);
        return optionSets.stream().map(opt -> this.convert(opt, store, language)).collect(Collectors.toList());
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while listing ProductOptionSet", e);
    }
}
Also used : OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductOptionSetFacade(com.salesmanager.shop.store.controller.product.facade.ProductOptionSetFacade) ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ProductOptionSetService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionSetService) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) List(java.util.List) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Validate(org.apache.commons.lang3.Validate) ReadableProductOptionSetMapper(com.salesmanager.shop.mapper.catalog.ReadableProductOptionSetMapper) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet) PersistableProductOptionSetMapper(com.salesmanager.shop.mapper.catalog.PersistableProductOptionSetMapper) ReadableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet) ProductTypeFacade(com.salesmanager.shop.store.controller.product.facade.ProductTypeFacade) ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) PersistableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet) ReadableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 52 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.

the class InitializationDatabaseImpl method createMerchant.

private void createMerchant() throws ServiceException {
    LOGGER.info(String.format("%s : Creating merchant ", name));
    Date date = new Date(System.currentTimeMillis());
    Language en = languageService.getByCode("en");
    Country ca = countryService.getByCode("CA");
    Currency currency = currencyService.getByCode("CAD");
    Zone qc = zoneService.getByCode("QC");
    List<Language> supportedLanguages = new ArrayList<Language>();
    supportedLanguages.add(en);
    // create a merchant
    MerchantStore store = new MerchantStore();
    store.setCountry(ca);
    store.setCurrency(currency);
    store.setDefaultLanguage(en);
    store.setInBusinessSince(date);
    store.setZone(qc);
    store.setStorename("Default store");
    store.setStorephone("888-888-8888");
    store.setCode(MerchantStore.DEFAULT_STORE);
    store.setStorecity("My city");
    store.setStoreaddress("1234 Street address");
    store.setStorepostalcode("H2H-2H2");
    store.setStoreEmailAddress("john@test.com");
    store.setDomainName("localhost:8080");
    store.setStoreTemplate("december");
    store.setRetailer(true);
    store.setLanguages(supportedLanguages);
    merchantService.create(store);
    TaxClass taxclass = new TaxClass(TaxClass.DEFAULT_TAX_CLASS);
    taxclass.setMerchantStore(store);
    taxClassService.create(taxclass);
    // create default manufacturer
    Manufacturer defaultManufacturer = new Manufacturer();
    defaultManufacturer.setCode("DEFAULT");
    defaultManufacturer.setMerchantStore(store);
    ManufacturerDescription manufacturerDescription = new ManufacturerDescription();
    manufacturerDescription.setLanguage(en);
    manufacturerDescription.setName("DEFAULT");
    manufacturerDescription.setManufacturer(defaultManufacturer);
    manufacturerDescription.setDescription("DEFAULT");
    defaultManufacturer.getDescriptions().add(manufacturerDescription);
    manufacturerService.create(defaultManufacturer);
    Optin newsletter = new Optin();
    newsletter.setCode(OptinType.NEWSLETTER.name());
    newsletter.setMerchant(store);
    newsletter.setOptinType(OptinType.NEWSLETTER);
    optinService.create(newsletter);
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) Optin(com.salesmanager.core.model.system.optin.Optin) Zone(com.salesmanager.core.model.reference.zone.Zone) Currency(com.salesmanager.core.model.reference.currency.Currency) ArrayList(java.util.ArrayList) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) Country(com.salesmanager.core.model.reference.country.Country) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Date(java.sql.Date)

Example 53 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.

the class LanguageUtils method getRESTLanguage.

/**
 * Should be used by rest web services
 *
 * @param request
 * @param store
 * @return
 * @throws Exception
 */
public Language getRESTLanguage(HttpServletRequest request, NativeWebRequest webRequest) {
    Validate.notNull(request, "HttpServletRequest must not be null");
    try {
        Language language = null;
        String lang = request.getParameter(Constants.LANG);
        if (StringUtils.isBlank(lang)) {
            if (language == null) {
                String storeValue = Optional.ofNullable(webRequest.getParameter(REQUEST_PARAMATER_STORE)).filter(StringUtils::isNotBlank).orElse(DEFAULT_STORE);
                if (!StringUtils.isBlank(storeValue)) {
                    try {
                        MerchantStore storeModel = storeFacade.get(storeValue);
                        language = storeModel.getDefaultLanguage();
                    } catch (Exception e) {
                        logger.warn("Cannot get store with code [" + storeValue + "]");
                    }
                } else {
                    language = languageService.defaultLanguage();
                }
            }
        } else {
            if (!ALL_LANGUALES.equals(lang)) {
                language = languageService.getByCode(lang);
                if (language == null) {
                    language = languageService.defaultLanguage();
                }
            }
        }
        // if language is null then underlying facade must load all languages
        return language;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ServiceException(com.salesmanager.core.business.exception.ServiceException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 54 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.

the class PersistableProductPopulator method populate.

@Override
public Product populate(PersistableProduct source, Product target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(target, "Product must not be null");
    try {
        target.setSku(source.getSku());
        target.setAvailable(source.isAvailable());
        target.setPreOrder(source.isPreOrder());
        target.setRefSku(source.getRefSku());
        if (source.getId() != null && source.getId().longValue() == 0) {
            target.setId(null);
        } else {
            target.setId(source.getId());
        }
        // PRODUCT TYPE
        if (!StringUtils.isBlank(source.getType())) {
            ProductType type = productTypeService.getByCode(source.getType(), store, language);
            if (type == null) {
                throw new ConversionException("Product type [" + source.getType() + "] does not exist");
            }
            target.setType(type);
        }
        if (source.getOwner() != null && source.getOwner().getId() != null) {
            com.salesmanager.core.model.customer.Customer owner = customerService.getById(source.getOwner().getId());
            target.setOwner(owner);
        }
        if (!StringUtils.isBlank(source.getDateAvailable())) {
            target.setDateAvailable(DateUtil.getDate(source.getDateAvailable()));
        }
        target.setMerchantStore(store);
        List<Language> languages = new ArrayList<Language>();
        Set<ProductDescription> descriptions = new HashSet<ProductDescription>();
        if (!CollectionUtils.isEmpty(source.getDescriptions())) {
            for (com.salesmanager.shop.model.catalog.product.ProductDescription description : source.getDescriptions()) {
                ProductDescription productDescription = new ProductDescription();
                Language lang = languageService.getByCode(description.getLanguage());
                if (lang == null) {
                    throw new ConversionException("Language code " + description.getLanguage() + " is invalid, use ISO code (en, fr ...)");
                }
                if (!CollectionUtils.isEmpty(target.getDescriptions())) {
                    for (ProductDescription desc : target.getDescriptions()) {
                        if (desc.getLanguage().getCode().equals(description.getLanguage())) {
                            productDescription = desc;
                            break;
                        }
                    }
                }
                productDescription.setProduct(target);
                productDescription.setDescription(description.getDescription());
                productDescription.setProductHighlight(description.getHighlights());
                productDescription.setName(description.getName());
                productDescription.setSeUrl(description.getFriendlyUrl());
                productDescription.setMetatagKeywords(description.getKeyWords());
                productDescription.setMetatagDescription(description.getMetaDescription());
                productDescription.setTitle(description.getTitle());
                languages.add(lang);
                productDescription.setLanguage(lang);
                descriptions.add(productDescription);
            }
        }
        if (descriptions.size() > 0) {
            target.setDescriptions(descriptions);
        }
        if (source.getProductSpecifications() != null) {
            target.setProductHeight(source.getProductSpecifications().getHeight());
            target.setProductLength(source.getProductSpecifications().getLength());
            target.setProductWeight(source.getProductSpecifications().getWeight());
            target.setProductWidth(source.getProductSpecifications().getWidth());
            if (source.getProductSpecifications().getManufacturer() != null) {
                Manufacturer manuf = null;
                if (!StringUtils.isBlank(source.getProductSpecifications().getManufacturer())) {
                    manuf = manufacturerService.getByCode(store, source.getProductSpecifications().getManufacturer());
                }
                if (manuf == null) {
                    throw new ConversionException("Invalid manufacturer id");
                }
                if (manuf != null) {
                    if (manuf.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                        throw new ConversionException("Invalid manufacturer id");
                    }
                    target.setManufacturer(manuf);
                }
            }
        }
        target.setSortOrder(source.getSortOrder());
        target.setProductVirtual(source.isProductVirtual());
        target.setProductShipeable(source.isProductShipeable());
        if (source.getRating() != null) {
            target.setProductReviewAvg(new BigDecimal(source.getRating()));
        }
        target.setProductReviewCount(source.getRatingCount());
        if (CollectionUtils.isNotEmpty(source.getProductPrices())) {
            // get product availability
            // create new ProductAvailability
            ProductAvailability productAvailability = new ProductAvailability(target, store);
            // todo now support for specific regions
            productAvailability.setRegion(Constants.ALL_REGIONS);
            productAvailability.setProductQuantity(source.getQuantity());
            productAvailability.setProductQuantityOrderMin(1);
            productAvailability.setProductQuantityOrderMax(1);
            productAvailability.setAvailable(Boolean.valueOf(target.isAvailable()));
            for (com.salesmanager.shop.model.catalog.product.PersistableProductPrice priceEntity : source.getProductPrices()) {
                ProductPrice price = new ProductPrice();
                price.setProductAvailability(productAvailability);
                price.setDefaultPrice(priceEntity.isDefaultPrice());
                price.setProductPriceAmount(priceEntity.getOriginalPrice());
                price.setCode(priceEntity.getCode());
                price.setProductPriceSpecialAmount(priceEntity.getDiscountedPrice());
                if (priceEntity.getDiscountStartDate() != null) {
                    Date startDate = DateUtil.getDate(priceEntity.getDiscountStartDate());
                    price.setProductPriceSpecialStartDate(startDate);
                }
                if (priceEntity.getDiscountEndDate() != null) {
                    Date endDate = DateUtil.getDate(priceEntity.getDiscountEndDate());
                    price.setProductPriceSpecialEndDate(endDate);
                }
                productAvailability.getPrices().add(price);
                target.getAvailabilities().add(productAvailability);
                for (Language lang : languages) {
                    ProductPriceDescription ppd = new ProductPriceDescription();
                    ppd.setProductPrice(price);
                    ppd.setLanguage(lang);
                    ppd.setName(ProductPriceDescription.DEFAULT_PRICE_DESCRIPTION);
                    // price appender
                    Optional<com.salesmanager.shop.model.catalog.product.ProductPriceDescription> description = priceEntity.getDescriptions().stream().filter(d -> d.getLanguage() != null && d.getLanguage().equals(lang.getCode())).findFirst();
                    if (description.isPresent()) {
                        ppd.setPriceAppender(description.get().getPriceAppender());
                    }
                    price.getDescriptions().add(ppd);
                }
            }
        } else {
            // create
            ProductAvailability productAvailability = null;
            ProductPrice defaultPrice = null;
            if (!CollectionUtils.isEmpty(target.getAvailabilities())) {
                for (ProductAvailability avail : target.getAvailabilities()) {
                    Set<ProductPrice> prices = avail.getPrices();
                    for (ProductPrice p : prices) {
                        if (p.isDefaultPrice()) {
                            if (productAvailability == null) {
                                productAvailability = avail;
                                defaultPrice = p;
                                break;
                            }
                            p.setDefaultPrice(false);
                        }
                    }
                }
            }
            if (productAvailability == null) {
                productAvailability = new ProductAvailability(target, store);
                target.getAvailabilities().add(productAvailability);
            }
            productAvailability.setProductQuantity(source.getQuantity());
            productAvailability.setProductQuantityOrderMin(1);
            productAvailability.setProductQuantityOrderMax(1);
            productAvailability.setRegion(Constants.ALL_REGIONS);
            productAvailability.setAvailable(Boolean.valueOf(target.isAvailable()));
            if (defaultPrice != null) {
                defaultPrice.setProductPriceAmount(source.getPrice());
            } else {
                defaultPrice = new ProductPrice();
                defaultPrice.setDefaultPrice(true);
                defaultPrice.setProductPriceAmount(source.getPrice());
                defaultPrice.setCode(ProductPriceEntity.DEFAULT_PRICE_CODE);
                defaultPrice.setProductAvailability(productAvailability);
                productAvailability.getPrices().add(defaultPrice);
                for (Language lang : languages) {
                    ProductPriceDescription ppd = new ProductPriceDescription();
                    ppd.setProductPrice(defaultPrice);
                    ppd.setLanguage(lang);
                    ppd.setName(ProductPriceDescription.DEFAULT_PRICE_DESCRIPTION);
                    defaultPrice.getDescriptions().add(ppd);
                }
            }
        }
        // image
        if (source.getImages() != null) {
            for (PersistableImage img : source.getImages()) {
                ProductImage productImage = new ProductImage();
                productImage.setImageType(img.getImageType());
                productImage.setDefaultImage(img.isDefaultImage());
                if (img.getImageType() == 1) {
                    productImage.setProductImageUrl(img.getImageUrl());
                    productImage.setImage(new ByteArrayInputStream(new byte[0]));
                } else {
                    ByteArrayInputStream in = new ByteArrayInputStream(img.getBytes());
                    productImage.setImage(in);
                }
                productImage.setProduct(target);
                productImage.setProductImage(img.getName());
                target.getImages().add(productImage);
            }
        }
        // attributes
        if (source.getAttributes() != null) {
            for (com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute attr : source.getAttributes()) {
                ProductAttribute attribute = persistableProductAttributeMapper.convert(attr, store, language);
                attribute.setProduct(target);
                target.getAttributes().add(attribute);
            }
        }
        // categories
        if (!CollectionUtils.isEmpty(source.getCategories())) {
            for (com.salesmanager.shop.model.catalog.category.Category categ : source.getCategories()) {
                Category c = null;
                if (!StringUtils.isBlank(categ.getCode())) {
                    c = categoryService.getByCode(store, categ.getCode());
                } else {
                    Validate.notNull(categ.getId(), "Category id nust not be null");
                    c = categoryService.getById(categ.getId(), store.getId());
                }
                if (c == null) {
                    throw new ConversionException("Category id " + categ.getId() + " does not exist");
                }
                if (c.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Invalid category id");
                }
                target.getCategories().add(c);
            }
        }
        return target;
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
Also used : ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) Date(java.util.Date) DateUtil(com.salesmanager.shop.utils.DateUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ProductOptionValueService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionValueService) TaxClassService(com.salesmanager.core.business.services.tax.TaxClassService) CollectionUtils(org.apache.commons.collections4.CollectionUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) BigDecimal(java.math.BigDecimal) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ByteArrayInputStream(java.io.ByteArrayInputStream) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) ManufacturerService(com.salesmanager.core.business.services.catalog.product.manufacturer.ManufacturerService) PersistableProductAttributeMapper(com.salesmanager.shop.mapper.catalog.PersistableProductAttributeMapper) Constants(com.salesmanager.core.business.constants.Constants) CustomerService(com.salesmanager.core.business.services.customer.CustomerService) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Product(com.salesmanager.core.model.catalog.product.Product) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) AbstractDataPopulator(com.salesmanager.core.business.utils.AbstractDataPopulator) Set(java.util.Set) Category(com.salesmanager.core.model.catalog.category.Category) List(java.util.List) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) Optional(java.util.Optional) ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) ProductOptionService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionService) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) PersistableImage(com.salesmanager.shop.model.catalog.product.PersistableImage) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) ProductTypeService(com.salesmanager.core.business.services.catalog.product.type.ProductTypeService) ProductPriceEntity(com.salesmanager.shop.model.catalog.product.ProductPriceEntity) Category(com.salesmanager.core.model.catalog.category.Category) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ArrayList(java.util.ArrayList) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Language(com.salesmanager.core.model.reference.language.Language) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) PersistableImage(com.salesmanager.shop.model.catalog.product.PersistableImage) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) HashSet(java.util.HashSet) ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) BigDecimal(java.math.BigDecimal) Date(java.util.Date) ConversionException(com.salesmanager.core.business.exception.ConversionException) ByteArrayInputStream(java.io.ByteArrayInputStream) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription)

Example 55 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.

the class ReadableProductDefinitionMapper method merge.

@Override
public ReadableProductDefinition merge(Product source, ReadableProductDefinition destination, MerchantStore store, Language language) {
    Validate.notNull(source, "Product cannot be null");
    Validate.notNull(destination, "Product destination cannot be null");
    ReadableProductDefinition returnDestination = destination;
    if (language == null) {
        returnDestination = new ReadableProductDefinitionFull();
    }
    List<com.salesmanager.shop.model.catalog.product.ProductDescription> fulldescriptions = new ArrayList<com.salesmanager.shop.model.catalog.product.ProductDescription>();
    returnDestination.setIdentifier(source.getSku());
    returnDestination.setId(source.getId());
    returnDestination.setVisible(source.isAvailable());
    returnDestination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
    ProductDescription description = null;
    if (source.getDescriptions() != null && source.getDescriptions().size() > 0) {
        for (ProductDescription desc : source.getDescriptions()) {
            if (language != null && desc.getLanguage() != null && desc.getLanguage().getId().intValue() == language.getId().intValue()) {
                description = desc;
                break;
            } else {
                fulldescriptions.add(populateDescription(desc));
            }
        }
    }
    if (description != null) {
        com.salesmanager.shop.model.catalog.product.ProductDescription tragetDescription = populateDescription(description);
        returnDestination.setDescription(tragetDescription);
    }
    if (source.getManufacturer() != null) {
        ReadableManufacturer manufacturer = readableManufacturerMapper.convert(source.getManufacturer(), store, language);
        returnDestination.setManufacturer(manufacturer);
    }
    if (!CollectionUtils.isEmpty(source.getCategories())) {
        List<ReadableCategory> categoryList = new ArrayList<ReadableCategory>();
        for (Category category : source.getCategories()) {
            ReadableCategory readableCategory = readableCategoryMapper.convert(category, store, language);
            categoryList.add(readableCategory);
        }
        returnDestination.setCategories(categoryList);
    }
    ProductSpecification specifications = new ProductSpecification();
    specifications.setHeight(source.getProductHeight());
    specifications.setLength(source.getProductLength());
    specifications.setWeight(source.getProductWeight());
    specifications.setWidth(source.getProductWidth());
    if (!StringUtils.isBlank(store.getSeizeunitcode())) {
        specifications.setDimensionUnitOfMeasure(DimensionUnitOfMeasure.valueOf(store.getSeizeunitcode().toLowerCase()));
    }
    if (!StringUtils.isBlank(store.getWeightunitcode())) {
        specifications.setWeightUnitOfMeasure(WeightUnitOfMeasure.valueOf(store.getWeightunitcode().toLowerCase()));
    }
    returnDestination.setProductSpecifications(specifications);
    if (source.getType() != null) {
        ReadableProductType readableType = readableProductTypeMapper.convert(source.getType(), store, language);
        returnDestination.setType(readableType);
    }
    returnDestination.setSortOrder(source.getSortOrder());
    // images
    Set<ProductImage> images = source.getImages();
    if (CollectionUtils.isNotEmpty(images)) {
        List<ReadableImage> imageList = images.stream().map(i -> this.convertImage(source, i, store)).collect(Collectors.toList());
        returnDestination.setImages(imageList);
    }
    // quantity
    ProductAvailability availability = null;
    for (ProductAvailability a : source.getAvailabilities()) {
        availability = a;
        returnDestination.setCanBePurchased(availability.getProductStatus());
        returnDestination.setQuantity(availability.getProductQuantity() == null ? 1 : availability.getProductQuantity());
    }
    FinalPrice price = null;
    try {
        price = pricingService.calculateProductPrice(source);
    } catch (ServiceException e) {
        throw new ConversionRuntimeException("Unable to get product price", e);
    }
    if (price != null) {
        returnDestination.setPrice(price.getStringPrice());
    }
    if (returnDestination instanceof ReadableProductDefinitionFull) {
        ((ReadableProductDefinitionFull) returnDestination).setDescriptions(fulldescriptions);
    }
    return returnDestination;
}
Also used : DateUtil(com.salesmanager.shop.utils.DateUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) ReadableCategoryMapper(com.salesmanager.shop.mapper.catalog.ReadableCategoryMapper) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ReadableProductDefinition(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinition) DimensionUnitOfMeasure(com.salesmanager.shop.model.references.DimensionUnitOfMeasure) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) ReadableProductDefinitionFull(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinitionFull) Mapper(com.salesmanager.shop.mapper.Mapper) Product(com.salesmanager.core.model.catalog.product.Product) ReadableManufacturerMapper(com.salesmanager.shop.mapper.catalog.ReadableManufacturerMapper) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) Set(java.util.Set) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Collectors(java.util.stream.Collectors) Category(com.salesmanager.core.model.catalog.category.Category) ReadableProductTypeMapper(com.salesmanager.shop.mapper.catalog.ReadableProductTypeMapper) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) List(java.util.List) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) WeightUnitOfMeasure(com.salesmanager.shop.model.references.WeightUnitOfMeasure) Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ArrayList(java.util.ArrayList) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableProductDefinition(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinition) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ReadableProductDefinitionFull(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinitionFull) ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType)

Aggregations

MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)171 Language (com.salesmanager.core.model.reference.language.Language)123 ServiceException (com.salesmanager.core.business.exception.ServiceException)72 List (java.util.List)65 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)62 ArrayList (java.util.ArrayList)61 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)60 Collectors (java.util.stream.Collectors)60 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)52 Autowired (org.springframework.beans.factory.annotation.Autowired)46 Product (com.salesmanager.core.model.catalog.product.Product)43 Service (org.springframework.stereotype.Service)37 Optional (java.util.Optional)35 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)35 Customer (com.salesmanager.core.model.customer.Customer)33 Logger (org.slf4j.Logger)33 LoggerFactory (org.slf4j.LoggerFactory)33 Inject (javax.inject.Inject)32 Validate (org.apache.commons.lang3.Validate)30 ConversionException (com.salesmanager.core.business.exception.ConversionException)27