But in the response there is no id assigned.
I have added the following code in CatalogEndpoint:
Code: Select all
@RequestMapping(value = "product", method = RequestMethod.POST)
public ProductWrapper createProduct(HttpServletRequest request,
@RequestBody() ProductWrapper productWrapper) throws BroadleafWebServicesException {
Product product = catalogService.createProduct(ProductType.PRODUCT);
Sku defaultSku = catalogService.createSku();
defaultSku.setRetailPrice(new Money(0));
product.setDefaultSku(defaultSku);
product.setName("New product");
catalogService.saveProduct(product);
ProductWrapper wrapper;
wrapper = (ProductWrapper) context.getBean(ProductWrapper.class.getName());
wrapper.wrapDetails(product, request);
return wrapper;
}
It works well enough, in the sense that it returns the new product:
Code: Select all
{
"name": "New product",
"retailPrice": {
"amount": "0.00",
"currency": "USD"
},
"active": false
}
But the returned product is without an ID, which makes it a bit hard to work with afterwards.
From my previous experiences with Hibernate, this looks like a need to flush the session, so the ID can be assigned, but it has so far eluded me how to do this.
Any clues ?