use of com.salesmanager.shop.model.catalog.product.PersistableProduct in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl 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);
}
}
use of com.salesmanager.shop.model.catalog.product.PersistableProduct 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());
}
use of com.salesmanager.shop.model.catalog.product.PersistableProduct 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("---------------------");
}
use of com.salesmanager.shop.model.catalog.product.PersistableProduct 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));
}
use of com.salesmanager.shop.model.catalog.product.PersistableProduct 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
}
Aggregations