use of com.salesmanager.shop.populator.manufacturer.PersistableManufacturerPopulator in project shopizer by shopizer-ecommerce.
the class ManufacturerFacadeImpl method saveOrUpdateManufacturer.
@Override
public void saveOrUpdateManufacturer(PersistableManufacturer manufacturer, MerchantStore store, Language language) throws Exception {
PersistableManufacturerPopulator populator = new PersistableManufacturerPopulator();
populator.setLanguageService(languageService);
Manufacturer manuf = new Manufacturer();
if (manufacturer.getId() != null && manufacturer.getId().longValue() > 0) {
manuf = manufacturerService.getById(manufacturer.getId());
if (manuf == null) {
throw new ResourceNotFoundException("Manufacturer with id [" + manufacturer.getId() + "] not found");
}
if (manuf.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ResourceNotFoundException("Manufacturer with id [" + manufacturer.getId() + "] not found for store [" + store.getId() + "]");
}
}
populator.populate(manufacturer, manuf, store, language);
manufacturerService.saveOrUpdate(manuf);
manufacturer.setId(manuf.getId());
}
use of com.salesmanager.shop.populator.manufacturer.PersistableManufacturerPopulator in project shopizer by shopizer-ecommerce.
the class ShopProductRESTController method createManufacturer.
/**
* Method for creating a manufacturer
* @param store
* @param manufacturer
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = "/private/{store}/manufacturer", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public PersistableManufacturer createManufacturer(@PathVariable final String store, @Valid @RequestBody PersistableManufacturer manufacturer, 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;
}
PersistableManufacturerPopulator populator = new PersistableManufacturerPopulator();
populator.setLanguageService(languageService);
com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer manuf = new com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer();
populator.populate(manufacturer, manuf, merchantStore, merchantStore.getDefaultLanguage());
manufacturerService.save(manuf);
manufacturer.setId(manuf.getId());
return manufacturer;
} catch (Exception e) {
LOGGER.error("Error while saving product", e);
try {
response.sendError(503, "Error while saving product " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
Aggregations