use of com.salesmanager.shop.model.catalog.product.PersistableProduct in project shopizer by shopizer-ecommerce.
the class SearchApiIntegrationTest method searchItem.
/**
* Add a product then search for it
* This tests is disabled since it requires Elastic search server started
*
* @throws Exception
*/
@Test
public void searchItem() throws Exception {
PersistableProduct product = super.product("TESTPRODUCT");
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));
SearchProductRequest searchRequest = new SearchProductRequest();
searchRequest.setQuery("TEST");
final HttpEntity<SearchProductRequest> searchEntity = new HttpEntity<>(searchRequest, getHeader());
final ResponseEntity<SearchProductList> searchResponse = testRestTemplate.postForEntity("/api/v1/search?store=" + Constants.DEFAULT_STORE, searchEntity, SearchProductList.class);
assertThat(searchResponse.getStatusCode(), is(CREATED));
}
use of com.salesmanager.shop.model.catalog.product.PersistableProduct 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);
}
}
Aggregations