use of com.salesmanager.shop.populator.catalog.PersistableProductOptionPopulator in project shopizer by shopizer-ecommerce.
the class ShopProductRESTController method createProductOption.
@RequestMapping(value = "/private/{store}/product/option", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public PersistableProductOption createProductOption(@PathVariable final String store, @Valid @RequestBody PersistableProductOption option, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
if (merchantStore != null) {
if (!merchantStore.getCode().equals(store)) {
merchantStore = null;
}
}
if (merchantStore == null) {
merchantStore = merchantStoreService.getByCode(store);
}
if (merchantStore == null) {
LOGGER.error("Merchant store is null for code " + store);
response.sendError(503, "Merchant store is null for code " + store);
return null;
}
PersistableProductOptionPopulator populator = new PersistableProductOptionPopulator();
populator.setLanguageService(languageService);
com.salesmanager.core.model.catalog.product.attribute.ProductOption opt = new com.salesmanager.core.model.catalog.product.attribute.ProductOption();
populator.populate(option, opt, merchantStore, merchantStore.getDefaultLanguage());
productOptionService.save(opt);
option.setId(opt.getId());
return option;
} catch (Exception e) {
LOGGER.error("Error while saving product option", e);
try {
response.sendError(503, "Error while saving product option" + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
Aggregations