Search in sources :

Example 1 with ManufacturerDescription

use of com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription 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 2 with ManufacturerDescription

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

the class ReadableProductPopulator method populate.

@Override
public ReadableProduct populate(Product source, ReadableProduct target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(pricingService, "Requires to set PricingService");
    Validate.notNull(imageUtils, "Requires to set imageUtils");
    try {
        List<com.salesmanager.shop.model.catalog.product.ProductDescription> fulldescriptions = new ArrayList<com.salesmanager.shop.model.catalog.product.ProductDescription>();
        if (language == null) {
            target = new ReadableProductFull();
        }
        if (target == null) {
            target = new ReadableProduct();
        }
        ProductDescription description = source.getProductDescription();
        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 (target instanceof ReadableProductFull) {
            ((ReadableProductFull) target).setDescriptions(fulldescriptions);
        }
        if (language == null) {
            language = store.getDefaultLanguage();
        }
        final Language lang = language;
        target.setId(source.getId());
        target.setAvailable(source.isAvailable());
        target.setProductShipeable(source.isProductShipeable());
        ProductSpecification specifications = new ProductSpecification();
        specifications.setHeight(source.getProductHeight());
        specifications.setLength(source.getProductLength());
        specifications.setWeight(source.getProductWeight());
        specifications.setWidth(source.getProductWidth());
        target.setProductSpecifications(specifications);
        target.setPreOrder(source.isPreOrder());
        target.setRefSku(source.getRefSku());
        target.setSortOrder(source.getSortOrder());
        if (source.getType() != null) {
            target.setType(this.type(source.getType(), language));
        }
        if (source.getOwner() != null) {
            RentalOwner owner = new RentalOwner();
            owner.setId(source.getOwner().getId());
            owner.setEmailAddress(source.getOwner().getEmailAddress());
            owner.setFirstName(source.getOwner().getBilling().getFirstName());
            owner.setLastName(source.getOwner().getBilling().getLastName());
            com.salesmanager.shop.model.customer.address.Address address = new com.salesmanager.shop.model.customer.address.Address();
            address.setAddress(source.getOwner().getBilling().getAddress());
            address.setBillingAddress(true);
            address.setCity(source.getOwner().getBilling().getCity());
            address.setCompany(source.getOwner().getBilling().getCompany());
            address.setCountry(source.getOwner().getBilling().getCountry().getIsoCode());
            address.setZone(source.getOwner().getBilling().getZone().getCode());
            address.setLatitude(source.getOwner().getBilling().getLatitude());
            address.setLongitude(source.getOwner().getBilling().getLongitude());
            address.setPhone(source.getOwner().getBilling().getTelephone());
            address.setPostalCode(source.getOwner().getBilling().getPostalCode());
            owner.setAddress(address);
            target.setOwner(owner);
        }
        if (source.getDateAvailable() != null) {
            target.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
        }
        if (source.getAuditSection() != null) {
            target.setCreationDate(DateUtil.formatDate(source.getAuditSection().getDateCreated()));
        }
        /*			if(source.getProductReviewAvg()!=null) {
				double avg = source.getProductReviewAvg().doubleValue();
				double rating = Math.round(avg * 2) / 2.0f;
				target.setRating(rating);
			}*/
        target.setProductVirtual(source.getProductVirtual());
        /*			if(source.getProductReviewCount()!=null) {
				target.setRatingCount(source.getProductReviewCount().intValue());
			}*/
        if (description != null) {
            com.salesmanager.shop.model.catalog.product.ProductDescription tragetDescription = populateDescription(description);
            target.setDescription(tragetDescription);
        }
        if (source.getManufacturer() != null) {
            ManufacturerDescription manufacturer = source.getManufacturer().getDescriptions().iterator().next();
            ReadableManufacturer manufacturerEntity = new ReadableManufacturer();
            com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription d = new com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription();
            d.setName(manufacturer.getName());
            manufacturerEntity.setDescription(d);
            manufacturerEntity.setId(source.getManufacturer().getId());
            manufacturerEntity.setOrder(source.getManufacturer().getOrder());
            manufacturerEntity.setCode(source.getManufacturer().getCode());
            target.setManufacturer(manufacturerEntity);
        }
        /*			if(source.getType() != null) {
			  ReadableProductType type = new ReadableProductType();
			  type.setId(source.getType().getId());
			  type.setCode(source.getType().getCode());
			  type.setName(source.getType().getCode());//need name
			  target.setType(type);
			}*/
        /**
         * TODO use ProductImageMapper
         */
        Set<ProductImage> images = source.getImages();
        if (images != null && images.size() > 0) {
            List<ReadableImage> imageList = new ArrayList<ReadableImage>();
            String contextPath = imageUtils.getContextPath();
            for (ProductImage img : images) {
                ReadableImage prdImage = new ReadableImage();
                prdImage.setImageName(img.getProductImage());
                prdImage.setDefaultImage(img.isDefaultImage());
                prdImage.setOrder(img.getSortOrder() != null ? img.getSortOrder().intValue() : 0);
                if (img.getImageType() == 1 && img.getProductImageUrl() != null) {
                    prdImage.setImageUrl(img.getProductImageUrl());
                } else {
                    StringBuilder imgPath = new StringBuilder();
                    imgPath.append(contextPath).append(imageUtils.buildProductImageUtils(store, source.getSku(), img.getProductImage()));
                    prdImage.setImageUrl(imgPath.toString());
                }
                prdImage.setId(img.getId());
                prdImage.setImageType(img.getImageType());
                if (img.getProductImageUrl() != null) {
                    prdImage.setExternalUrl(img.getProductImageUrl());
                }
                if (img.getImageType() == 1 && img.getProductImageUrl() != null) {
                    // video
                    prdImage.setVideoUrl(img.getProductImageUrl());
                }
                if (prdImage.isDefaultImage()) {
                    target.setImage(prdImage);
                }
                imageList.add(prdImage);
            }
            imageList = imageList.stream().sorted(Comparator.comparingInt(ReadableImage::getOrder)).collect(Collectors.toList());
            target.setImages(imageList);
        }
        if (!CollectionUtils.isEmpty(source.getCategories())) {
            ReadableCategoryPopulator categoryPopulator = new ReadableCategoryPopulator();
            List<ReadableCategory> categoryList = new ArrayList<ReadableCategory>();
            for (Category category : source.getCategories()) {
                ReadableCategory readableCategory = new ReadableCategory();
                categoryPopulator.populate(category, readableCategory, store, language);
                categoryList.add(readableCategory);
            }
            target.setCategories(categoryList);
        }
        if (!CollectionUtils.isEmpty(source.getAttributes())) {
            Set<ProductAttribute> attributes = source.getAttributes();
            // split read only and options
            // Map<Long,ReadableProductAttribute> readOnlyAttributes = null;
            Map<Long, ReadableProductProperty> properties = null;
            Map<Long, ReadableProductOption> selectableOptions = null;
            if (!CollectionUtils.isEmpty(attributes)) {
                for (ProductAttribute attribute : attributes) {
                    ReadableProductOption opt = null;
                    ReadableProductAttribute attr = null;
                    ReadableProductProperty property = null;
                    ReadableProductPropertyValue propertyValue = null;
                    ReadableProductOptionValueEntity optValue = new ReadableProductOptionValueEntity();
                    ReadableProductAttributeValue attrValue = new ReadableProductAttributeValue();
                    ProductOptionValue optionValue = attribute.getProductOptionValue();
                    if (attribute.getAttributeDisplayOnly()) {
                        // read only attribute = property
                        /*
								if(readOnlyAttributes==null) {
									readOnlyAttributes = new TreeMap<Long,ReadableProductAttribute>();
								}
								attr = readOnlyAttributes.get(attribute.getProductOption().getId());
								if(attr==null) {
									attr = createAttribute(attribute, language);
								}
								if(attr!=null) {
									readOnlyAttributes.put(attribute.getProductOption().getId(), attr);
								}


								attrValue.setDefaultValue(attribute.getAttributeDefault());
								if(attribute.getProductOptionValue()!=null) {
								  attrValue.setId(attribute.getProductOptionValue().getId());//id of the option value
								} else {
								  attrValue.setId(attribute.getId());
								}
								attrValue.setLang(language.getCode());


								attrValue.setSortOrder(0);
								if(attribute.getProductOptionSortOrder()!=null) {
									attrValue.setSortOrder(attribute.getProductOptionSortOrder().intValue());
								}

								List<ProductOptionValueDescription> podescriptions = optionValue.getDescriptionsSettoList();
								ProductOptionValueDescription podescription = null;
								if(podescriptions!=null && podescriptions.size()>0) {
									podescription = podescriptions.get(0);
									if(podescriptions.size()>1) {
										for(ProductOptionValueDescription optionValueDescription : podescriptions) {
											if(optionValueDescription.getLanguage().getId().intValue()==language.getId().intValue()) {
												podescription = optionValueDescription;
												break;
											}
										}
									}
								}
								attrValue.setName(podescription.getName());
								attrValue.setDescription(podescription.getDescription());

								if(attr!=null) {
									attr.getAttributeValues().add(attrValue);
								}
*/
                        // if(properties==null) {
                        // properties = new TreeMap<Long,ReadableProductProperty>();
                        // }
                        // property = properties.get(attribute.getProductOption().getId());
                        // if(property==null) {
                        property = createProperty(attribute, language);
                        // that is the property
                        ReadableProductOption readableOption = new ReadableProductOption();
                        ReadableProductPropertyValue readableOptionValue = new ReadableProductPropertyValue();
                        readableOption.setCode(attribute.getProductOption().getCode());
                        readableOption.setId(attribute.getProductOption().getId());
                        Set<ProductOptionDescription> podescriptions = attribute.getProductOption().getDescriptions();
                        if (podescriptions != null && podescriptions.size() > 0) {
                            for (ProductOptionDescription optionDescription : podescriptions) {
                                if (optionDescription.getLanguage().getCode().equals(language.getCode())) {
                                    readableOption.setName(optionDescription.getName());
                                }
                            }
                        }
                        property.setProperty(readableOption);
                        Set<ProductOptionValueDescription> povdescriptions = attribute.getProductOptionValue().getDescriptions();
                        readableOptionValue.setId(attribute.getProductOptionValue().getId());
                        if (povdescriptions != null && povdescriptions.size() > 0) {
                            for (ProductOptionValueDescription optionValueDescription : povdescriptions) {
                                if (optionValueDescription.getLanguage().getCode().equals(language.getCode())) {
                                    readableOptionValue.setName(optionValueDescription.getName());
                                }
                            }
                        }
                        property.setPropertyValue(readableOptionValue);
                        // } else{
                        // properties.put(attribute.getProductOption().getId(), property);
                        // }
                        /*								propertyValue.setCode(attribute.getProductOptionValue().getCode());
								propertyValue.setId(attribute.getProductOptionValue().getId());


								propertyValue.setSortOrder(0);
								if(attribute.getProductOptionSortOrder()!=null) {
									propertyValue.setSortOrder(attribute.getProductOptionSortOrder().intValue());
								}

								List<ProductOptionValueDescription> podescriptions = optionValue.getDescriptionsSettoList();
								if(podescriptions!=null && podescriptions.size()>0) {
									for(ProductOptionValueDescription optionValueDescription : podescriptions) {
										com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription desc = new com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription();
										desc.setId(optionValueDescription.getId());
										desc.setName(optionValueDescription.getName());
										propertyValue.getValues().add(desc);
									}
								}

								property.setPropertyValue(propertyValue);*/
                        // if(attr!=null) {
                        // attr.getAttributeValues().add(attrValue);
                        // }
                        target.getProperties().add(property);
                    } else {
                        if (selectableOptions == null) {
                            selectableOptions = new TreeMap<Long, ReadableProductOption>();
                        }
                        opt = selectableOptions.get(attribute.getProductOption().getId());
                        if (opt == null) {
                            opt = createOption(attribute, language);
                        }
                        if (opt != null) {
                            selectableOptions.put(attribute.getProductOption().getId(), opt);
                        }
                        optValue.setDefaultValue(attribute.getAttributeDefault());
                        // optValue.setId(attribute.getProductOptionValue().getId());
                        optValue.setId(attribute.getId());
                        optValue.setCode(attribute.getProductOptionValue().getCode());
                        com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription valueDescription = new com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription();
                        valueDescription.setLanguage(language.getCode());
                        // optValue.setLang(language.getCode());
                        if (attribute.getProductAttributePrice() != null && attribute.getProductAttributePrice().doubleValue() > 0) {
                            String formatedPrice = pricingService.getDisplayAmount(attribute.getProductAttributePrice(), store);
                            optValue.setPrice(formatedPrice);
                        }
                        if (!StringUtils.isBlank(attribute.getProductOptionValue().getProductOptionValueImage())) {
                            optValue.setImage(imageUtils.buildProductPropertyImageUtils(store, attribute.getProductOptionValue().getProductOptionValueImage()));
                        }
                        optValue.setSortOrder(0);
                        if (attribute.getProductOptionSortOrder() != null) {
                            optValue.setSortOrder(attribute.getProductOptionSortOrder().intValue());
                        }
                        List<ProductOptionValueDescription> podescriptions = optionValue.getDescriptionsSettoList();
                        ProductOptionValueDescription podescription = null;
                        if (podescriptions != null && podescriptions.size() > 0) {
                            podescription = podescriptions.get(0);
                            if (podescriptions.size() > 1) {
                                for (ProductOptionValueDescription optionValueDescription : podescriptions) {
                                    if (optionValueDescription.getLanguage().getId().intValue() == language.getId().intValue()) {
                                        podescription = optionValueDescription;
                                        break;
                                    }
                                }
                            }
                        }
                        valueDescription.setName(podescription.getName());
                        valueDescription.setDescription(podescription.getDescription());
                        optValue.setDescription(valueDescription);
                        if (opt != null) {
                            opt.getOptionValues().add(optValue);
                        }
                    }
                }
            }
            if (selectableOptions != null) {
                List<ReadableProductOption> options = new ArrayList<ReadableProductOption>(selectableOptions.values());
                target.setOptions(options);
            }
        }
        // remove products from invisible category -> set visible = false
        /*			Set<Category> categories = source.getCategories();
			boolean isVisible = true;
			if(!CollectionUtils.isEmpty(categories)) {
				for(Category c : categories) {
					if(c.isVisible()) {
						isVisible = true;
						break;
					} else {
						isVisible = false;
					}
				}
			}*/
        // target.setVisible(isVisible);
        // availability
        ProductAvailability availability = null;
        for (ProductAvailability a : source.getAvailabilities()) {
            // TODO validate region
            // if(availability.getRegion().equals(Constants.ALL_REGIONS)) {//TODO REL 2.1 accept a region
            availability = a;
            target.setQuantity(availability.getProductQuantity() == null ? 1 : availability.getProductQuantity());
            target.setQuantityOrderMaximum(availability.getProductQuantityOrderMax() == null ? 1 : availability.getProductQuantityOrderMax());
            target.setQuantityOrderMinimum(availability.getProductQuantityOrderMin() == null ? 1 : availability.getProductQuantityOrderMin());
            if (availability.getProductQuantity().intValue() > 0 && target.isAvailable()) {
                target.setCanBePurchased(true);
            }
        // }
        }
        target.setSku(source.getSku());
        FinalPrice price = pricingService.calculateProductPrice(source);
        if (price != null) {
            target.setFinalPrice(pricingService.getDisplayAmount(price.getFinalPrice(), store));
            target.setPrice(price.getFinalPrice());
            target.setOriginalPrice(pricingService.getDisplayAmount(price.getOriginalPrice(), store));
            if (price.isDiscounted()) {
                target.setDiscounted(true);
            }
            // price appender
            if (availability != null) {
                Set<ProductPrice> prices = availability.getPrices();
                if (!CollectionUtils.isEmpty(prices)) {
                    ReadableProductPrice readableProductPrice = new ReadableProductPrice();
                    readableProductPrice.setDiscounted(target.isDiscounted());
                    readableProductPrice.setFinalPrice(target.getFinalPrice());
                    readableProductPrice.setOriginalPrice(target.getOriginalPrice());
                    Optional<ProductPrice> pr = prices.stream().filter(p -> p.getCode().equals(ProductPrice.DEFAULT_PRICE_CODE)).findFirst();
                    target.setProductPrice(readableProductPrice);
                    if (pr.isPresent()) {
                        readableProductPrice.setId(pr.get().getId());
                        Optional<ProductPriceDescription> d = pr.get().getDescriptions().stream().filter(desc -> desc.getLanguage().getCode().equals(lang.getCode())).findFirst();
                        if (d.isPresent()) {
                            com.salesmanager.shop.model.catalog.product.ProductPriceDescription priceDescription = new com.salesmanager.shop.model.catalog.product.ProductPriceDescription();
                            priceDescription.setLanguage(language.getCode());
                            priceDescription.setId(d.get().getId());
                            priceDescription.setPriceAppender(d.get().getPriceAppender());
                            readableProductPrice.setDescription(priceDescription);
                        }
                    }
                }
            }
        }
        if (target instanceof ReadableProductFull) {
            ((ReadableProductFull) target).setDescriptions(fulldescriptions);
        }
        return target;
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
Also used : ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) RentalOwner(com.salesmanager.shop.model.catalog.product.RentalOwner) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) DateUtil(com.salesmanager.shop.utils.DateUtil) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableProductFull(com.salesmanager.shop.model.catalog.product.ReadableProductFull) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ReadableProductAttributeValue(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductAttributeValue) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) Map(java.util.Map) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) 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) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) Set(java.util.Set) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Collectors(java.util.stream.Collectors) Category(com.salesmanager.core.model.catalog.category.Category) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) List(java.util.List) Validate(org.apache.commons.lang3.Validate) TreeMap(java.util.TreeMap) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) Optional(java.util.Optional) ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ProductTypeDescription(com.salesmanager.shop.model.catalog.product.type.ProductTypeDescription) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Comparator(java.util.Comparator) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) ReadableProductPropertyValue(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductPropertyValue) ReadableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductAttribute) ReadableProductProperty(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductProperty) ReadableProductOption(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductOption) ArrayList(java.util.ArrayList) RentalOwner(com.salesmanager.shop.model.catalog.product.RentalOwner) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ReadableProductAttributeValue(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductAttributeValue) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableProductProperty(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductProperty) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ReadableProductFull(com.salesmanager.shop.model.catalog.product.ReadableProductFull) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ReadableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductAttribute) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) ReadableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductAttribute) Language(com.salesmanager.core.model.reference.language.Language) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ReadableProductPropertyValue(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductPropertyValue) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) ReadableProductOption(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductOption) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription)

Example 3 with ManufacturerDescription

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

the class OrderTest method getMerchantOrders.

@Test
public void getMerchantOrders() throws ServiceException {
    Currency currency = currencyService.getByCode(USD_CURRENCY_CODE);
    Country country = countryService.getByCode("US");
    Zone zone = zoneService.getByCode("VT");
    Language en = languageService.getByCode("en");
    MerchantStore merchant = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    /**
     * Create a customer *
     */
    Customer customer = new Customer();
    customer.setMerchantStore(merchant);
    customer.setDefaultLanguage(en);
    customer.setEmailAddress("email@email.com");
    customer.setPassword("-1999");
    customer.setNick("My New nick");
    customer.setCompany(" Apple");
    customer.setGender(CustomerGender.M);
    customer.setDateOfBirth(new Date());
    Billing billing = new Billing();
    billing.setAddress("Billing address");
    billing.setCity("Billing city");
    billing.setCompany("Billing company");
    billing.setCountry(country);
    billing.setFirstName("Carl");
    billing.setLastName("Samson");
    billing.setPostalCode("Billing postal code");
    billing.setState("Billing state");
    billing.setZone(zone);
    Delivery delivery = new Delivery();
    delivery.setAddress("Shipping address");
    delivery.setCountry(country);
    delivery.setZone(zone);
    customer.setBilling(billing);
    customer.setDelivery(delivery);
    customerService.create(customer);
    // create a product with attributes
    /**
     * CATALOG CREATION *
     */
    ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
    /**
     * Create the category
     */
    Category shirts = new Category();
    shirts.setMerchantStore(merchant);
    shirts.setCode("shirts");
    CategoryDescription shirtsEnglishDescription = new CategoryDescription();
    shirtsEnglishDescription.setName("Shirts");
    shirtsEnglishDescription.setCategory(shirts);
    shirtsEnglishDescription.setLanguage(en);
    Set<CategoryDescription> descriptions = new HashSet<CategoryDescription>();
    descriptions.add(shirtsEnglishDescription);
    shirts.setDescriptions(descriptions);
    categoryService.create(shirts);
    /**
     * Create a manufacturer
     */
    Manufacturer addidas = new Manufacturer();
    addidas.setMerchantStore(merchant);
    addidas.setCode("addidas");
    ManufacturerDescription addidasDesc = new ManufacturerDescription();
    addidasDesc.setLanguage(en);
    addidasDesc.setManufacturer(addidas);
    addidasDesc.setName("Addidas");
    addidas.getDescriptions().add(addidasDesc);
    manufacturerService.create(addidas);
    /**
     * Create an option
     */
    ProductOption option = new ProductOption();
    option.setMerchantStore(merchant);
    option.setCode("color");
    option.setProductOptionType(ProductOptionType.Radio.name());
    ProductOptionDescription optionDescription = new ProductOptionDescription();
    optionDescription.setLanguage(en);
    optionDescription.setName("Color");
    optionDescription.setDescription("Item color");
    optionDescription.setProductOption(option);
    option.getDescriptions().add(optionDescription);
    productOptionService.saveOrUpdate(option);
    /**
     * first option value *
     */
    ProductOptionValue white = new ProductOptionValue();
    white.setMerchantStore(merchant);
    white.setCode("white");
    ProductOptionValueDescription whiteDescription = new ProductOptionValueDescription();
    whiteDescription.setLanguage(en);
    whiteDescription.setName("White");
    whiteDescription.setDescription("White color");
    whiteDescription.setProductOptionValue(white);
    white.getDescriptions().add(whiteDescription);
    productOptionValueService.saveOrUpdate(white);
    ProductOptionValue black = new ProductOptionValue();
    black.setMerchantStore(merchant);
    black.setCode("black");
    /**
     * second option value *
     */
    ProductOptionValueDescription blackDesc = new ProductOptionValueDescription();
    blackDesc.setLanguage(en);
    blackDesc.setName("Black");
    blackDesc.setDescription("Black color");
    blackDesc.setProductOptionValue(black);
    black.getDescriptions().add(blackDesc);
    productOptionValueService.saveOrUpdate(black);
    /**
     * Create a complex product
     */
    Product product = new Product();
    product.setProductHeight(new BigDecimal(4));
    product.setProductLength(new BigDecimal(3));
    product.setProductWidth(new BigDecimal(1));
    product.setSku("TB12345");
    product.setManufacturer(addidas);
    product.setType(generalType);
    product.setMerchantStore(merchant);
    // Product description
    ProductDescription description = new ProductDescription();
    description.setName("Short sleeves shirt");
    description.setLanguage(en);
    description.setProduct(product);
    product.getDescriptions().add(description);
    product.getCategories().add(shirts);
    // availability
    ProductAvailability availability = new ProductAvailability();
    availability.setProductDateAvailable(new Date());
    availability.setProductQuantity(100);
    availability.setRegion("*");
    // associate with product
    availability.setProduct(product);
    // price
    ProductPrice dprice = new ProductPrice();
    dprice.setDefaultPrice(true);
    dprice.setProductPriceAmount(new BigDecimal(29.99));
    dprice.setProductAvailability(availability);
    ProductPriceDescription dpd = new ProductPriceDescription();
    dpd.setName("Base price");
    dpd.setProductPrice(dprice);
    dpd.setLanguage(en);
    dprice.getDescriptions().add(dpd);
    availability.getPrices().add(dprice);
    product.getAvailabilities().add(availability);
    // attributes
    // white
    ProductAttribute whiteAttribute = new ProductAttribute();
    whiteAttribute.setProduct(product);
    whiteAttribute.setProductOption(option);
    whiteAttribute.setAttributeDefault(true);
    // no price variation
    whiteAttribute.setProductAttributePrice(new BigDecimal(0));
    // no weight variation
    whiteAttribute.setProductAttributeWeight(new BigDecimal(0));
    whiteAttribute.setProductOption(option);
    whiteAttribute.setProductOptionValue(white);
    product.getAttributes().add(whiteAttribute);
    // black
    ProductAttribute blackAttribute = new ProductAttribute();
    blackAttribute.setProduct(product);
    blackAttribute.setProductOption(option);
    // 5 + dollars
    blackAttribute.setProductAttributePrice(new BigDecimal(5));
    // no weight variation
    blackAttribute.setProductAttributeWeight(new BigDecimal(0));
    blackAttribute.setProductOption(option);
    blackAttribute.setProductOptionValue(black);
    product.getAttributes().add(blackAttribute);
    productService.create(product);
    /**
     * Create an order *
     */
    Order order = new Order();
    /**
     * payment details *
     */
    CreditCard creditCard = new CreditCard();
    creditCard.setCardType(CreditCardType.VISA);
    creditCard.setCcCvv("123");
    creditCard.setCcExpires("12/30/2020");
    creditCard.setCcNumber("123456789");
    creditCard.setCcOwner("ccOwner");
    order.setCreditCard(creditCard);
    /**
     * order core attributes *
     */
    order.setDatePurchased(new Date());
    order.setCurrency(currency);
    order.setMerchant(merchant);
    order.setLastModified(new Date());
    // no price variation because of the currency
    order.setCurrencyValue(new BigDecimal(1));
    order.setCustomerId(1L);
    order.setDelivery(delivery);
    order.setIpAddress("ipAddress");
    order.setMerchant(merchant);
    order.setOrderDateFinished(new Date());
    order.setPaymentType(PaymentType.CREDITCARD);
    order.setPaymentModuleCode("payment Module Code");
    order.setShippingModuleCode("UPS");
    order.setStatus(OrderStatus.ORDERED);
    order.setCustomerAgreement(true);
    order.setConfirmedAddress(true);
    order.setTotal(dprice.getProductPriceAmount());
    order.setCustomerEmailAddress(customer.getEmailAddress());
    order.setBilling(billing);
    order.setDelivery(delivery);
    /**
     * ORDER PRODUCT *
     */
    // OrderProduct
    OrderProduct oproduct = new OrderProduct();
    oproduct.setDownloads(null);
    oproduct.setOneTimeCharge(dprice.getProductPriceAmount());
    oproduct.setOrder(order);
    oproduct.setProductName(description.getName());
    oproduct.setProductQuantity(1);
    oproduct.setSku(product.getSku());
    // set order product price
    OrderProductPrice orderProductPrice = new OrderProductPrice();
    // default price (same as default product price)
    orderProductPrice.setDefaultPrice(true);
    orderProductPrice.setOrderProduct(oproduct);
    orderProductPrice.setProductPrice(dprice.getProductPriceAmount());
    orderProductPrice.setProductPriceCode(ProductPriceType.ONE_TIME.name());
    oproduct.getPrices().add(orderProductPrice);
    // order product attribute
    OrderProductAttribute orderProductAttribute = new OrderProductAttribute();
    orderProductAttribute.setOrderProduct(oproduct);
    // no extra charge
    orderProductAttribute.setProductAttributePrice(new BigDecimal("0.00"));
    orderProductAttribute.setProductAttributeName(whiteDescription.getName());
    orderProductAttribute.setProductOptionId(option.getId());
    orderProductAttribute.setProductOptionValueId(white.getId());
    oproduct.getOrderAttributes().add(orderProductAttribute);
    order.getOrderProducts().add(oproduct);
    /**
     * ORDER TOTAL *
     */
    OrderTotal subTotal = new OrderTotal();
    subTotal.setOrder(order);
    subTotal.setOrderTotalCode(Constants.OT_SUBTOTAL_MODULE_CODE);
    subTotal.setSortOrder(0);
    subTotal.setTitle("Sub Total");
    subTotal.setValue(dprice.getProductPriceAmount());
    order.getOrderTotal().add(subTotal);
    OrderTotal total = new OrderTotal();
    total.setOrder(order);
    total.setOrderTotalCode(Constants.OT_TOTAL_MODULE_CODE);
    total.setSortOrder(1);
    total.setTitle("Total");
    total.setValue(dprice.getProductPriceAmount());
    order.getOrderTotal().add(total);
    /**
     * ORDER HISTORY *
     */
    // create a log entry in order history
    OrderStatusHistory history = new OrderStatusHistory();
    history.setOrder(order);
    history.setDateAdded(new Date());
    history.setStatus(OrderStatus.ORDERED);
    history.setComments("We received your order");
    order.getOrderHistory().add(history);
    /**
     * CREATE ORDER *
     */
    orderService.create(order);
    /**
     * SEARCH ORDERS *
     */
    OrderCriteria criteria = new OrderCriteria();
    criteria.setStartIndex(0);
    criteria.setMaxCount(10);
    OrderList ordserList = orderService.listByStore(merchant, criteria);
    Assert.assertNotNull(ordserList);
    Assert.assertNotNull("Merchant Orders are null.", ordserList.getOrders());
    Assert.assertTrue("Merchant Orders count is not one.", (ordserList.getOrders() != null && ordserList.getOrders().size() == 1));
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) Customer(com.salesmanager.core.model.customer.Customer) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) Product(com.salesmanager.core.model.catalog.product.Product) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) OrderProductPrice(com.salesmanager.core.model.order.orderproduct.OrderProductPrice) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) Language(com.salesmanager.core.model.reference.language.Language) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Currency(com.salesmanager.core.model.reference.currency.Currency) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) HashSet(java.util.HashSet) ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) Order(com.salesmanager.core.model.order.Order) Zone(com.salesmanager.core.model.reference.zone.Zone) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) OrderCriteria(com.salesmanager.core.model.order.OrderCriteria) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CreditCard(com.salesmanager.core.model.order.payment.CreditCard) Billing(com.salesmanager.core.model.common.Billing) OrderProductPrice(com.salesmanager.core.model.order.orderproduct.OrderProductPrice) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) Country(com.salesmanager.core.model.reference.country.Country) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) CategoryDescription(com.salesmanager.core.model.catalog.category.CategoryDescription) Delivery(com.salesmanager.core.model.common.Delivery) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) OrderList(com.salesmanager.core.model.order.OrderList) OrderTotal(com.salesmanager.core.model.order.OrderTotal) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) Test(org.junit.Test)

Example 4 with ManufacturerDescription

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

the class ManufacturerTest method testManufacturer.

/**
 * This method creates multiple products using multiple catalog APIs
 * @throws ServiceException
 */
@Test
public void testManufacturer() throws Exception {
    Language en = languageService.getByCode("en");
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    Manufacturer oreilley = new Manufacturer();
    oreilley.setMerchantStore(store);
    oreilley.setCode("oreilley2");
    ManufacturerDescription oreilleyd = new ManufacturerDescription();
    oreilleyd.setLanguage(en);
    oreilleyd.setName("O\'reilley");
    oreilleyd.setManufacturer(oreilley);
    oreilley.getDescriptions().add(oreilleyd);
    manufacturerService.create(oreilley);
    Manufacturer packed = new Manufacturer();
    packed.setMerchantStore(store);
    packed.setCode("packed2");
    ManufacturerDescription packedd = new ManufacturerDescription();
    packedd.setLanguage(en);
    packedd.setManufacturer(packed);
    packedd.setName("Packed publishing");
    packed.getDescriptions().add(packedd);
    manufacturerService.create(packed);
    Manufacturer novells = new Manufacturer();
    novells.setMerchantStore(store);
    novells.setCode("novells2");
    ManufacturerDescription novellsd = new ManufacturerDescription();
    novellsd.setLanguage(en);
    novellsd.setManufacturer(novells);
    novellsd.setName("Novells publishing");
    novells.getDescriptions().add(novellsd);
    manufacturerService.create(novells);
    // query pageable category
    Page<Manufacturer> pageable = manufacturerService.listByStore(store, en, 0, 5);
    Assert.isTrue(pageable.getSize() > 0, "4 manufacturers");
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Test(org.junit.Test)

Example 5 with ManufacturerDescription

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

the class ProductNextGenTest method testCreateProduct.

/**
 * This method creates single product with variants using multiple catalog APIs
 * @throws ServiceException
 */
@Test
public void testCreateProduct() throws Exception {
    Language en = languageService.getByCode("en");
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
    /**
     * Category
     */
    Category shoes = new Category();
    shoes.setMerchantStore(store);
    shoes.setCode("shoes");
    CategoryDescription shoesDescription = new CategoryDescription();
    shoesDescription.setName("Shoes");
    shoesDescription.setCategory(shoes);
    shoesDescription.setLanguage(en);
    Set<CategoryDescription> descriptions = new HashSet<CategoryDescription>();
    descriptions.add(shoesDescription);
    shoes.setDescriptions(descriptions);
    categoryService.create(shoes);
    // 
    /**
     * Manufacturer / Brand
     */
    Manufacturer brown = new Manufacturer();
    brown.setMerchantStore(store);
    brown.setCode("brown");
    ManufacturerDescription brownd = new ManufacturerDescription();
    brownd.setLanguage(en);
    brownd.setName("Brown's");
    brownd.setManufacturer(brown);
    brown.getDescriptions().add(brownd);
    manufacturerService.create(brown);
    // 
    // PRODUCT
    // -- non variable informations
    Product summerShoes = new Product();
    summerShoes.setProductHeight(new BigDecimal(3));
    // average
    summerShoes.setProductLength(new BigDecimal(9));
    summerShoes.setProductWidth(new BigDecimal(4));
    summerShoes.setSku("BR12345");
    summerShoes.setManufacturer(brown);
    summerShoes.setType(generalType);
    summerShoes.setMerchantStore(store);
    // is available
    summerShoes.setAvailable(true);
    // Product description
    ProductDescription description = new ProductDescription();
    description.setName("Summer shoes");
    description.setLanguage(en);
    description.setProduct(summerShoes);
    summerShoes.getDescriptions().add(description);
    // add product to shoes category
    summerShoes.getCategories().add(shoes);
    // -- end non variable informations
    // --- add attributes to the product (size)
    createOptions(summerShoes);
    // --- options set
    /**
     * Option Set facilitates product attributes creation for redundant product creation
     * it offers a list of possible options and options values administrator can create in order
     * to easily create attributes
     */
    createOptionsSet(store);
    // --- create attributes (available options)
    /**
     * Add options to product
     * Those are attributes
     */
    ProductAttribute size_nine = new ProductAttribute();
    size_nine.setProduct(summerShoes);
    size_nine.setProductOption(size);
    size_nine.setAttributeDefault(true);
    // no price variation
    size_nine.setProductAttributePrice(new BigDecimal(0));
    // no weight variation
    size_nine.setProductAttributeWeight(new BigDecimal(0));
    size_nine.setProductOptionValue(nine);
    summerShoes.getAttributes().add(size_nine);
    ProductAttribute size_nine_half = new ProductAttribute();
    size_nine_half.setProduct(summerShoes);
    size_nine_half.setProductOption(size);
    // no price variation
    size_nine_half.setProductAttributePrice(new BigDecimal(0));
    // weight variation
    size_nine_half.setProductAttributeWeight(new BigDecimal(0));
    size_nine_half.setProductOptionValue(nineHalf);
    summerShoes.getAttributes().add(size_nine_half);
    ProductAttribute size_ten = new ProductAttribute();
    size_ten.setProduct(summerShoes);
    size_ten.setProductOption(size);
    // no price variation
    size_ten.setProductAttributePrice(new BigDecimal(0));
    // weight variation
    size_ten.setProductAttributeWeight(new BigDecimal(0));
    size_ten.setProductOptionValue(ten);
    summerShoes.getAttributes().add(size_ten);
    // ---- variable informations - inventory - variants - prices
    ProductAvailability availability = createInventory(store, 100, new BigDecimal("99.99"));
    summerShoes.getAvailabilities().add(availability);
    // ---- add available sizes
    // DEFAULT (total quantity of 100 distributed)
    // TODO use pre 3.0 variation
    // 40 of 9
    /*	    ProductVariant size_nine_DEFAULT = new ProductVariant();
	    size_nine_DEFAULT.setAttribute(size_nine);
	    size_nine_DEFAULT.setProductQuantity(40);
	    size_nine_DEFAULT.setProductAvailability(availability);*/
    // availability.getVariants().add(size_nine_DEFAULT);
    // 30 of 9.5
    /*	    ProductVariant size_nine_half_DEFAULT = new ProductVariant();
	    size_nine_half_DEFAULT.setAttribute(size_nine_half);
	    size_nine_half_DEFAULT.setProductQuantity(30);
	    size_nine_half_DEFAULT.setProductAvailability(availability);*/
    // availability.getVariants().add(size_nine_half_DEFAULT);
    // 30 of ten
    /*	    ProductVariant size_ten_DEFAULT = new ProductVariant();
	    size_ten_DEFAULT.setAttribute(size_nine_half);
	    size_ten_DEFAULT.setProductQuantity(30);
	    size_ten_DEFAULT.setProductAvailability(availability);*/
    // availability.getVariants().add(size_ten_DEFAULT);
    // inventory for store DEFAULT and product summerShoes
    availability.setProduct(summerShoes);
    availability.setMerchantStore(store);
    /**
     * Create product
     */
    productService.create(summerShoes);
    // ObjectMapper mapper = new ObjectMapper();
    // Converting the Object to JSONString
    // String jsonString = mapper.writeValueAsString(summerShoes);
    // System.out.println(jsonString);
    Product p = productService.getById(summerShoes.getId());
    assertNotNull(p);
    // List<ProductAvailability> avs = p.getAvailabilities().stream().filter(a -> !a.getVariants().isEmpty()).collect(Collectors.toList());
    // assertThat(avs, not(empty()));
    // test product list service
    // list products per category
    // list 5 items
    ProductCriteria productCriteria = new ProductCriteria();
    productCriteria.setCategoryIds(Stream.of(shoes.getId()).collect(Collectors.toList()));
    Page<Product> listByCategory = productService.listByStore(store, en, productCriteria, 0, 5);
    List<Product> productsByCategory = listByCategory.getContent();
    assertThat(productsByCategory, not(empty()));
    // list products per color attribute
    Page<Product> listByOptionValue = productService.listByStore(store, en, productCriteria, 0, 5);
    productCriteria = new ProductCriteria();
    productCriteria.setOptionValueIds(Stream.of(nineHalf.getId()).collect(Collectors.toList()));
    List<Product> productsByOption = listByOptionValue.getContent();
    assertThat(productsByOption, not(empty()));
}
Also used : ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) Category(com.salesmanager.core.model.catalog.category.Category) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) Product(com.salesmanager.core.model.catalog.product.Product) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) BigDecimal(java.math.BigDecimal) Language(com.salesmanager.core.model.reference.language.Language) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) CategoryDescription(com.salesmanager.core.model.catalog.category.CategoryDescription) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ManufacturerDescription (com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription)8 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)7 Language (com.salesmanager.core.model.reference.language.Language)7 Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)6 Category (com.salesmanager.core.model.catalog.category.Category)5 Product (com.salesmanager.core.model.catalog.product.Product)5 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)5 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)5 ProductType (com.salesmanager.core.model.catalog.product.type.ProductType)5 Test (org.junit.Test)5 CategoryDescription (com.salesmanager.core.model.catalog.category.CategoryDescription)4 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)4 ProductPrice (com.salesmanager.core.model.catalog.product.price.ProductPrice)4 ProductPriceDescription (com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)4 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 ProductOptionDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription)3 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)3 ProductOptionValueDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)3