Search in sources :

Example 1 with PersistableManufacturerPopulator

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());
}
Also used : PersistableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.PersistableManufacturerPopulator) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 2 with PersistableManufacturerPopulator

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;
    }
}
Also used : PersistableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.PersistableManufacturerPopulator) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

PersistableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer)2 PersistableManufacturerPopulator (com.salesmanager.shop.populator.manufacturer.PersistableManufacturerPopulator)2 Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)1 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1