Search in sources :

Example 1 with ProductOptionDescription

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

the class PersistableProductOptionPopulator method populate.

@Override
public ProductOption populate(PersistableProductOption source, ProductOption target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(languageService, "Requires to set LanguageService");
    try {
        target.setMerchantStore(store);
        target.setProductOptionSortOrder(source.getOrder());
        target.setCode(source.getCode());
        if (!CollectionUtils.isEmpty(source.getDescriptions())) {
            Set<com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription> descriptions = new HashSet<com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription>();
            for (ProductOptionDescription desc : source.getDescriptions()) {
                com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription description = new com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription();
                Language lang = languageService.getByCode(desc.getLanguage());
                if (lang == null) {
                    throw new ConversionException("Language is null for code " + description.getLanguage() + " use language ISO code [en, fr ...]");
                }
                description.setLanguage(lang);
                description.setName(desc.getName());
                description.setTitle(desc.getTitle());
                description.setProductOption(target);
                descriptions.add(description);
            }
            target.setDescriptions(descriptions);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductOptionDescription(com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription) Language(com.salesmanager.core.model.reference.language.Language) HashSet(java.util.HashSet)

Example 2 with ProductOptionDescription

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

the class ProductManagementAPIIntegrationTest method createOption.

/**
 * Creates a new ProductOption
 *
 * @throws Exception
 */
@Test
@Ignore
public void createOption() throws Exception {
    final ProductOptionDescription description = new ProductOptionDescription();
    description.setLanguage("en");
    description.setName("Color");
    final List<ProductOptionDescription> descriptions = new ArrayList<>();
    descriptions.add(description);
    final PersistableProductOption option = new PersistableProductOption();
    option.setOrder(1);
    option.setCode("color");
    option.setType(ProductOptionType.Select.name());
    option.setDescriptions(descriptions);
    final ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
    final String json = writer.writeValueAsString(option);
    System.out.println(json);
    /**
     * { "descriptions" : [ { "name" : "Color", "description" : null,
     * "friendlyUrl" : null, "keyWords" : null, "highlights" : null,
     * "metaDescription" : null, "title" : null, "language" : "en", "id" : 0
     * } ], "type" : SELECT, "order" : 1, "code" : "color", "id" : 0 }
     */
    restTemplate = new RestTemplate();
    final HttpEntity<String> entity = new HttpEntity<>(json, getHeader());
    final ResponseEntity response = restTemplate.postForEntity("http://localhost:8080/sm-shop/services/private/DEFAULT/product/option", entity, PersistableProductOption.class);
    final PersistableProductOption opt = (PersistableProductOption) response.getBody();
    System.out.println("New option ID : " + opt.getId());
}
Also used : ProductOptionDescription(com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription) ResponseEntity(org.springframework.http.ResponseEntity) HttpEntity(org.springframework.http.HttpEntity) PersistableProductOption(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOption) ArrayList(java.util.ArrayList) RestTemplate(org.springframework.web.client.RestTemplate) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with ProductOptionDescription

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

the class ProductV2ManagementAPIIntegrationTest method createProductWithCategory.

@Test
public void createProductWithCategory() throws Exception {
    /**
     * Create a category for product association
     */
    final PersistableCategory newCategory = new PersistableCategory();
    newCategory.setCode("test-catv2");
    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-catv2");
    description.setFriendlyUrl("test-catv2");
    description.setTitle("test-catv2");
    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();
    assertTrue(categoryResponse.getStatusCode() == 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/v2/private/product/definition?store=" + Constants.DEFAULT_STORE, entity, PersistableProduct.class);
    assertTrue(response.getStatusCode() == CREATED);
    // create options
    PersistableProductOption color = new PersistableProductOption();
    color.setCode("color");
    ProductOptionDescription colorEn = new ProductOptionDescription();
    colorEn.setName("Color");
    colorEn.setLanguage("en");
    color.getDescriptions().add(colorEn);
    final HttpEntity<PersistableProductOption> colorEntity = new HttpEntity<>(color, getHeader());
    final ResponseEntity<PersistableProductOption> colorResponse = testRestTemplate.postForEntity("/api/v1/private/product/option?store=" + Constants.DEFAULT_STORE, colorEntity, PersistableProductOption.class);
    assertTrue(colorResponse.getStatusCode() == CREATED);
    System.out.println(colorResponse.getBody().getId());
    PersistableProductOption size = new PersistableProductOption();
    size.setCode("size");
    ProductOptionDescription sizeEn = new ProductOptionDescription();
    sizeEn.setName("Size");
    sizeEn.setLanguage("en");
    size.getDescriptions().add(sizeEn);
    final HttpEntity<PersistableProductOption> sizeEntity = new HttpEntity<>(size, getHeader());
    final ResponseEntity<PersistableProductOption> sizeResponse = testRestTemplate.postForEntity("/api/v1/private/product/option?store=" + Constants.DEFAULT_STORE, sizeEntity, PersistableProductOption.class);
    assertTrue(sizeResponse.getStatusCode() == CREATED);
    System.out.println(colorResponse.getBody().getId());
    // opions values
    PersistableProductOptionValue white = new PersistableProductOptionValue();
    white.setCode("white");
    ProductOptionValueDescription whiteEn = new ProductOptionValueDescription();
    whiteEn.setName("White");
    whiteEn.setLanguage("en");
    white.getDescriptions().add(whiteEn);
    final HttpEntity<PersistableProductOptionValue> whiteEntity = new HttpEntity<>(white, getHeader());
    final ResponseEntity<PersistableProductOptionValue> whiteResponse = testRestTemplate.postForEntity("/api/v1/private/product/option?store=" + Constants.DEFAULT_STORE, whiteEntity, PersistableProductOptionValue.class);
    assertTrue(whiteResponse.getStatusCode() == CREATED);
    System.out.println(whiteResponse.getBody().getId());
    PersistableProductOptionValue medium = new PersistableProductOptionValue();
    medium.setCode("medium");
    ProductOptionValueDescription mediumEn = new ProductOptionValueDescription();
    mediumEn.setName("Medium");
    mediumEn.setLanguage("en");
    white.getDescriptions().add(mediumEn);
    // create variants - todo
    PersistableProductVariation whiteVariant = new PersistableProductVariation();
    // - todo
    PersistableProductVariation mediumVariant = new PersistableProductVariation();
// toto
// create instances
}
Also used : PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) 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) PersistableProductVariation(com.salesmanager.shop.model.catalog.product.variation.PersistableProductVariation) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ProductOptionDescription(com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) PersistableProductOption(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOption) CategoryDescription(com.salesmanager.shop.model.catalog.category.CategoryDescription) ProductOptionValueDescription(com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProductOptionDescription (com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription)3 PersistableProductOption (com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOption)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 HttpEntity (org.springframework.http.HttpEntity)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 Language (com.salesmanager.core.model.reference.language.Language)1 Category (com.salesmanager.shop.model.catalog.category.Category)1 CategoryDescription (com.salesmanager.shop.model.catalog.category.CategoryDescription)1 PersistableCategory (com.salesmanager.shop.model.catalog.category.PersistableCategory)1 PersistableProduct (com.salesmanager.shop.model.catalog.product.PersistableProduct)1 ProductSpecification (com.salesmanager.shop.model.catalog.product.ProductSpecification)1 PersistableProductOptionValue (com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue)1 ProductOptionValueDescription (com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription)1 PersistableProductVariation (com.salesmanager.shop.model.catalog.product.variation.PersistableProductVariation)1 HashSet (java.util.HashSet)1 Ignore (org.junit.Ignore)1