Search in sources :

Example 6 with ProductSpecification

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

the class ReadableMinimalProductMapper method merge.

@Override
public ReadableMinimalProduct merge(Product source, ReadableMinimalProduct destination, MerchantStore store, Language language) {
    Validate.notNull(source, "Product cannot be null");
    Validate.notNull(destination, "ReadableMinimalProduct cannot be null");
    for (ProductDescription desc : source.getDescriptions()) {
        if (language != null && desc.getLanguage() != null && desc.getLanguage().getId().intValue() == language.getId().intValue()) {
            destination.setDescription(this.description(desc));
            break;
        }
    }
    destination.setId(source.getId());
    destination.setAvailable(source.isAvailable());
    destination.setProductShipeable(source.isProductShipeable());
    ProductSpecification specifications = new ProductSpecification();
    specifications.setHeight(source.getProductHeight());
    specifications.setLength(source.getProductLength());
    specifications.setWeight(source.getProductWeight());
    specifications.setWidth(source.getProductWidth());
    destination.setProductSpecifications(specifications);
    destination.setPreOrder(source.isPreOrder());
    destination.setRefSku(source.getRefSku());
    destination.setSortOrder(source.getSortOrder());
    destination.setSku(source.getSku());
    if (source.getDateAvailable() != null) {
        destination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
    }
    if (source.getProductReviewAvg() != null) {
        double avg = source.getProductReviewAvg().doubleValue();
        double rating = Math.round(avg * 2) / 2.0f;
        destination.setRating(rating);
    }
    destination.setProductVirtual(source.getProductVirtual());
    if (source.getProductReviewCount() != null) {
        destination.setRatingCount(source.getProductReviewCount().intValue());
    }
    try {
        FinalPrice price = pricingService.calculateProductPrice(source);
        if (price != null) {
            destination.setFinalPrice(pricingService.getDisplayAmount(price.getFinalPrice(), store));
            destination.setPrice(price.getFinalPrice());
            destination.setOriginalPrice(pricingService.getDisplayAmount(price.getOriginalPrice(), store));
        }
    } catch (ServiceException e) {
        throw new ConversionRuntimeException("An error occured during price calculation", e);
    }
    // image
    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());
            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()) {
                destination.setImage(prdImage);
            }
            imageList.add(prdImage);
        }
        destination.setImages(imageList);
    }
    return null;
}
Also used : ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ArrayList(java.util.ArrayList) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 7 with ProductSpecification

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

the class ReadableProductMapper method merge.

@Override
public ReadableProduct merge(Product source, ReadableProduct destination, MerchantStore store, Language language) {
    Validate.notNull(source, "Product cannot be null");
    Validate.notNull(destination, "Product destination cannot be null");
    destination.setSku(source.getSku());
    destination.setRefSku(source.getRefSku());
    destination.setId(source.getId());
    destination.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;
            }
        }
        destination.setId(source.getId());
        destination.setAvailable(source.isAvailable());
        destination.setProductShipeable(source.isProductShipeable());
        ProductSpecification specifications = new ProductSpecification();
        specifications.setHeight(source.getProductHeight());
        specifications.setLength(source.getProductLength());
        specifications.setWeight(source.getProductWeight());
        specifications.setWidth(source.getProductWidth());
        destination.setProductSpecifications(specifications);
        destination.setPreOrder(source.isPreOrder());
        destination.setRefSku(source.getRefSku());
        destination.setSortOrder(source.getSortOrder());
        if (source.getType() != null) {
            ReadableProductType readableType = readableProductTypeMapper.convert(source.getType(), store, language);
            destination.setType(readableType);
        }
        if (source.getDateAvailable() != null) {
            destination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
        }
        if (source.getAuditSection() != null) {
            destination.setCreationDate(DateUtil.formatDate(source.getAuditSection().getDateCreated()));
        }
        destination.setProductVirtual(source.getProductVirtual());
        if (source.getProductReviewCount() != null) {
            destination.setRatingCount(source.getProductReviewCount().intValue());
        }
        if (source.getManufacturer() != null) {
            ReadableManufacturer manufacturer = readableManufacturerMapper.convert(source.getManufacturer(), store, language);
            destination.setManufacturer(manufacturer);
        }
        // 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());
            destination.setImages(imageList);
        }
        // read only product values
        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();
                    // we need to set readonly attributes only
                    if (attribute.getAttributeDisplayOnly()) {
                        // read only attribute = property
                        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);
                        destination.getProperties().add(property);
                    }
                    if (selectableOptions != null) {
                        List<ReadableProductOption> options = new ArrayList<ReadableProductOption>(selectableOptions.values());
                        destination.setOptions(options);
                    }
                }
            }
        }
    }
    // 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;
        destination.setQuantity(availability.getProductQuantity() == null ? 1 : availability.getProductQuantity());
        destination.setQuantityOrderMaximum(availability.getProductQuantityOrderMax() == null ? 1 : availability.getProductQuantityOrderMax());
        destination.setQuantityOrderMinimum(availability.getProductQuantityOrderMin() == null ? 1 : availability.getProductQuantityOrderMin());
        if (availability.getProductQuantity().intValue() > 0 && destination.isAvailable()) {
            destination.setCanBePurchased(true);
        }
    // }
    }
    destination.setSku(source.getSku());
    try {
        FinalPrice price = pricingService.calculateProductPrice(source);
        if (price != null) {
            destination.setFinalPrice(pricingService.getDisplayAmount(price.getFinalPrice(), store));
            destination.setPrice(price.getFinalPrice());
            destination.setOriginalPrice(pricingService.getDisplayAmount(price.getOriginalPrice(), store));
            if (price.isDiscounted()) {
                destination.setDiscounted(true);
            }
            // price appender
            if (availability != null) {
                Set<ProductPrice> prices = availability.getPrices();
                if (!CollectionUtils.isEmpty(prices)) {
                    ReadableProductPrice readableProductPrice = new ReadableProductPrice();
                    readableProductPrice.setDiscounted(destination.isDiscounted());
                    readableProductPrice.setFinalPrice(destination.getFinalPrice());
                    readableProductPrice.setOriginalPrice(destination.getOriginalPrice());
                    Optional<ProductPrice> pr = prices.stream().filter(p -> p.getCode().equals(ProductPrice.DEFAULT_PRICE_CODE)).findFirst();
                    destination.setProductPrice(readableProductPrice);
                    if (pr.isPresent()) {
                        readableProductPrice.setId(pr.get().getId());
                        Optional<ProductPriceDescription> d = pr.get().getDescriptions().stream().filter(desc -> desc.getLanguage().getCode().equals(language.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);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new ConversionRuntimeException("An error while converting product price", e);
    }
    if (source.getProductReviewAvg() != null) {
        double avg = source.getProductReviewAvg().doubleValue();
        double rating = Math.round(avg * 2) / 2.0f;
        destination.setRating(rating);
    }
    if (source.getProductReviewCount() != null) {
        destination.setRatingCount(source.getProductReviewCount().intValue());
    }
    if (description != null) {
        com.salesmanager.shop.model.catalog.product.ProductDescription tragetDescription = populateDescription(description);
        destination.setDescription(tragetDescription);
    }
    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);
        }
        destination.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()));
    }
    destination.setProductSpecifications(specifications);
    destination.setSortOrder(source.getSortOrder());
    return destination;
}
Also used : ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) DateUtil(com.salesmanager.shop.utils.DateUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) 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) DimensionUnitOfMeasure(com.salesmanager.shop.model.references.DimensionUnitOfMeasure) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) 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) Mapper(com.salesmanager.shop.mapper.Mapper) Product(com.salesmanager.core.model.catalog.product.Product) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) 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) 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) Optional(java.util.Optional) 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) 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) WeightUnitOfMeasure(com.salesmanager.shop.model.references.WeightUnitOfMeasure) ReadableProductOption(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductOption) ArrayList(java.util.ArrayList) 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) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableProductProperty(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductProperty) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) ReadableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductAttribute) 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) 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) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ReadableProductPropertyValue(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductPropertyValue) ReadableProductOption(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductOption) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType)

Example 8 with ProductSpecification

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

the class CategoryManagementAPIIntegrationTest method manufacturerForItemsInCategory.

@Test
public void manufacturerForItemsInCategory() throws Exception {
    ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
    // create first manufacturer
    PersistableManufacturer m1 = super.manufacturer("BRAND1");
    String json = writer.writeValueAsString(m1);
    HttpEntity<String> entity = new HttpEntity<>(json, getHeader());
    @SuppressWarnings("rawtypes") ResponseEntity response = testRestTemplate.postForEntity("/api/v1/private/manufacturer", entity, PersistableManufacturer.class);
    assertThat(response.getStatusCode(), is(CREATED));
    // create second manufacturer
    PersistableManufacturer m2 = super.manufacturer("BRAND2");
    json = writer.writeValueAsString(m2);
    entity = new HttpEntity<>(json, getHeader());
    response = testRestTemplate.postForEntity("/api/v1/private/manufacturer", entity, PersistableManufacturer.class);
    assertThat(response.getStatusCode(), is(CREATED));
    // create category
    PersistableCategory category = super.category("TEST");
    // to be used in product
    Category cat = new Category();
    cat.setCode("TEST");
    json = writer.writeValueAsString(category);
    entity = new HttpEntity<>(json, getHeader());
    @SuppressWarnings("rawtypes") ResponseEntity categoryResponse = testRestTemplate.postForEntity("/api/v1/private/category", entity, PersistableCategory.class);
    assertThat(categoryResponse.getStatusCode(), is(CREATED));
    final PersistableCategory persistable = (PersistableCategory) categoryResponse.getBody();
    Long id = persistable.getId();
    // create first item
    PersistableProduct product1 = super.product("PRODUCT1");
    product1.getCategories().add(cat);
    ProductSpecification specifications = new ProductSpecification();
    specifications.setManufacturer("BRAND1");
    product1.setProductSpecifications(specifications);
    json = writer.writeValueAsString(product1);
    entity = new HttpEntity<>(json, getHeader());
    response = testRestTemplate.postForEntity("/api/v1/private/product?store=" + Constants.DEFAULT_STORE, entity, PersistableProduct.class);
    assertThat(response.getStatusCode(), is(CREATED));
    // create second item
    PersistableProduct product2 = super.product("PRODUCT2");
    product2.getCategories().add(cat);
    specifications = new ProductSpecification();
    specifications.setManufacturer("BRAND2");
    product2.setProductSpecifications(specifications);
    json = writer.writeValueAsString(product2);
    entity = new HttpEntity<>(json, getHeader());
    response = testRestTemplate.postForEntity("/api/v1/private/product?store=" + Constants.DEFAULT_STORE, entity, PersistableProduct.class);
    assertThat(response.getStatusCode(), is(CREATED));
    entity = new HttpEntity<>(getHeader());
    // get manufacturers in category
    @SuppressWarnings("rawtypes") ResponseEntity<List> manufacturers = testRestTemplate.exchange(String.format("/api/v1/category/" + id + "/manufacturers"), HttpMethod.GET, entity, List.class);
    assertThat(manufacturers.getStatusCode(), is(OK));
    @SuppressWarnings("unchecked") List<ReadableManufacturer> manufacturerList = manufacturers.getBody();
// assertFalse(manufacturerList.isEmpty());
}
Also used : PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) Category(com.salesmanager.shop.model.catalog.category.Category) HttpEntity(org.springframework.http.HttpEntity) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ResponseEntity(org.springframework.http.ResponseEntity) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ArrayList(java.util.ArrayList) ReadableCategoryList(com.salesmanager.shop.model.catalog.category.ReadableCategoryList) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with ProductSpecification

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

the class ProductManagementAPIIntegrationTest method postProduct.

@Test
@Ignore
public void postProduct() throws Exception {
    restTemplate = new RestTemplate();
    final PersistableProduct product = new PersistableProduct();
    final String code = "abcdef";
    // root category
    final String categoryCode = "ROOT";
    final Category category = new Category();
    category.setCode(categoryCode);
    final List<Category> categories = new ArrayList<>();
    categories.add(category);
    final String manufacturer = "temple";
    final Manufacturer collection = new Manufacturer();
    collection.setCode(manufacturer);
    // core properties
    product.setSku(code);
    // product.setManufacturer(collection); //no manufacturer assigned for
    // now
    // product.setCategories(categories); //no category assigned for now
    // set iterator as sort order
    product.setSortOrder(0);
    // force availability
    product.setAvailable(true);
    // force tangible good
    product.setProductVirtual(false);
    // force to 1 minimum when ordering
    product.setQuantityOrderMinimum(1);
    // all items are shipeable
    product.setProductShipeable(true);
    /**
     * images *
     */
    final String image = "/Users/carlsamson/Documents/csti/IMG_4626.jpg";
    // String image = "C:/personal/em/pictures-misc/IMG_2675.JPG";
    final File imgPath = new File(image);
    // PersistableImage persistableImage = new PersistableImage();
    // persistableImage.setBytes(this.extractBytes(imgPath));
    // persistableImage.setImageName(imgPath.getName());
    // List<PersistableImage> images = new ArrayList<PersistableImage>();
    // images.add(persistableImage);
    // product.setImages(images);
    ProductSpecification specifications = new ProductSpecification();
    specifications.setHeight(new BigDecimal(20));
    specifications.setLength(new BigDecimal(21));
    specifications.setWeight(new BigDecimal(22));
    specifications.setWidth(new BigDecimal(23));
    product.setProductSpecifications(specifications);
    product.setQuantity(5);
    product.setQuantityOrderMaximum(2);
    final PersistableProductPrice productPrice = new PersistableProductPrice();
    productPrice.setDefaultPrice(true);
    productPrice.setOriginalPrice(new BigDecimal(250));
    productPrice.setDiscountedPrice(new BigDecimal(125));
    final List<PersistableProductPrice> productPriceList = new ArrayList<>();
    productPriceList.add(productPrice);
    product.setProductPrices(productPriceList);
    final List<ProductDescription> descriptions = new ArrayList<>();
    // add english description
    ProductDescription description = new ProductDescription();
    description.setLanguage("en");
    description.setTitle("Buddha Head");
    description.setName("Buddha Head");
    description.setDescription("Buddha Head");
    description.setFriendlyUrl("buddha-head");
    // description.setHighlights(record.get("highlights_en"));
    descriptions.add(description);
    // add french description
    description = new ProductDescription();
    description.setLanguage("fr");
    description.setTitle("TĂȘte de Buddha");
    description.setName("TĂȘte de Buddha");
    description.setDescription(description.getName());
    description.setFriendlyUrl("tete-de-buddha");
    // 
    descriptions.add(description);
    product.setDescriptions(descriptions);
    // RENTAL
    final RentalOwner owner = new RentalOwner();
    // need to create a customer first
    owner.setId(1L);
    product.setOwner(owner);
    final ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
    final String json = writer.writeValueAsString(product);
    System.out.println(json);
    final HttpEntity<String> entity = new HttpEntity<>(json, getHeader());
    // post to create category web service
    final ResponseEntity response = restTemplate.postForEntity("http://localhost:8080/api/v1/product", entity, PersistableProduct.class);
    final PersistableProduct prod = (PersistableProduct) response.getBody();
    System.out.println("---------------------");
}
Also used : PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) Category(com.salesmanager.shop.model.catalog.category.Category) PersistableProductPrice(com.salesmanager.shop.model.catalog.product.PersistableProductPrice) HttpEntity(org.springframework.http.HttpEntity) ArrayList(java.util.ArrayList) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) RentalOwner(com.salesmanager.shop.model.catalog.product.RentalOwner) BigDecimal(java.math.BigDecimal) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ResponseEntity(org.springframework.http.ResponseEntity) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) RestTemplate(org.springframework.web.client.RestTemplate) Manufacturer(com.salesmanager.shop.model.catalog.manufacturer.Manufacturer) ProductDescription(com.salesmanager.shop.model.catalog.product.ProductDescription) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with ProductSpecification

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

the class ProductManagementAPIIntegrationTest method createProductWithCategory.

@Test
public void createProductWithCategory() throws Exception {
    final PersistableCategory newCategory = new PersistableCategory();
    newCategory.setCode("test-cat");
    newCategory.setSortOrder(1);
    newCategory.setVisible(true);
    newCategory.setDepth(4);
    final Category parent = new Category();
    newCategory.setParent(parent);
    final CategoryDescription description = new CategoryDescription();
    description.setLanguage("en");
    description.setName("test-cat");
    description.setFriendlyUrl("test-cat");
    description.setTitle("test-cat");
    final List<CategoryDescription> descriptions = new ArrayList<>();
    descriptions.add(description);
    newCategory.setDescriptions(descriptions);
    final HttpEntity<PersistableCategory> categoryEntity = new HttpEntity<>(newCategory, getHeader());
    final ResponseEntity<PersistableCategory> categoryResponse = testRestTemplate.postForEntity("/api/v1/private/category?store=" + Constants.DEFAULT_STORE, categoryEntity, PersistableCategory.class);
    final PersistableCategory cat = categoryResponse.getBody();
    assertThat(categoryResponse.getStatusCode(), is(CREATED));
    assertNotNull(cat.getId());
    final PersistableProduct product = new PersistableProduct();
    final ArrayList<Category> categories = new ArrayList<>();
    categories.add(cat);
    product.setCategories(categories);
    ProductSpecification specifications = new ProductSpecification();
    specifications.setManufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer.DEFAULT_MANUFACTURER);
    product.setProductSpecifications(specifications);
    product.setPrice(BigDecimal.TEN);
    product.setSku("123");
    final HttpEntity<PersistableProduct> entity = new HttpEntity<>(product, getHeader());
    final ResponseEntity<PersistableProduct> response = testRestTemplate.postForEntity("/api/v1/private/product?store=" + Constants.DEFAULT_STORE, entity, PersistableProduct.class);
    assertThat(response.getStatusCode(), is(CREATED));
}
Also used : PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) Category(com.salesmanager.shop.model.catalog.category.Category) HttpEntity(org.springframework.http.HttpEntity) ArrayList(java.util.ArrayList) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) CategoryDescription(com.salesmanager.shop.model.catalog.category.CategoryDescription) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProductSpecification (com.salesmanager.shop.model.catalog.product.ProductSpecification)12 ArrayList (java.util.ArrayList)10 PersistableProduct (com.salesmanager.shop.model.catalog.product.PersistableProduct)7 Product (com.salesmanager.core.model.catalog.product.Product)6 ServiceException (com.salesmanager.core.business.exception.ServiceException)5 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)5 ProductImage (com.salesmanager.core.model.catalog.product.image.ProductImage)5 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)5 Category (com.salesmanager.shop.model.catalog.category.Category)5 PersistableCategory (com.salesmanager.shop.model.catalog.category.PersistableCategory)5 ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)5 ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)5 ReadableImage (com.salesmanager.shop.model.catalog.product.ReadableImage)5 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)5 List (java.util.List)5 PricingService (com.salesmanager.core.business.services.catalog.product.PricingService)4 Category (com.salesmanager.core.model.catalog.category.Category)4 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)4 Language (com.salesmanager.core.model.reference.language.Language)4