use of com.salesmanager.shop.populator.catalog.PersistableProductOptionValuePopulator in project shopizer by shopizer-ecommerce.
the class ShopProductRESTController method createProductOptionValue.
@RequestMapping(value = "/private/{store}/product/optionValue", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public PersistableProductOptionValue createProductOptionValue(@PathVariable final String store, @Valid @RequestBody PersistableProductOptionValue optionValue, 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;
}
PersistableProductOptionValuePopulator populator = new PersistableProductOptionValuePopulator();
populator.setLanguageService(languageService);
com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue optValue = new com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue();
populator.populate(optionValue, optValue, merchantStore, merchantStore.getDefaultLanguage());
productOptionValueService.save(optValue);
optionValue.setId(optValue.getId());
return optionValue;
} catch (Exception e) {
LOGGER.error("Error while saving product option value", e);
try {
response.sendError(503, "Error while saving product option value" + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
Aggregations