Search in sources :

Example 11 with ProductSpecification

use of com.salesmanager.shop.model.catalog.product.ProductSpecification 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)

Example 12 with ProductSpecification

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

the class ProductFacadeImpl method saveProduct.

@Override
public PersistableProduct saveProduct(MerchantStore store, PersistableProduct product, Language language) {
    String manufacturer = Manufacturer.DEFAULT_MANUFACTURER;
    if (product.getProductSpecifications() != null) {
        manufacturer = product.getProductSpecifications().getManufacturer();
    } else {
        ProductSpecification specifications = new ProductSpecification();
        specifications.setManufacturer(manufacturer);
    }
    Product target = null;
    if (product.getId() != null && product.getId().longValue() > 0) {
        target = productService.getById(product.getId());
    } else {
        target = new Product();
    }
    try {
        persistableProductPopulator.populate(product, target, store, language);
        if (target.getId() != null && target.getId() > 0) {
            productService.update(target);
        } else {
            productService.create(target);
            product.setId(target.getId());
        }
        return product;
    } catch (Exception e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

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