Search in sources :

Example 1 with PersistableProductOptionPopulator

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;
    }
}
Also used : PersistableProductOption(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOption) PersistableProductOptionPopulator(com.salesmanager.shop.populator.catalog.PersistableProductOptionPopulator) 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

MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 PersistableProductOption (com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOption)1 PersistableProductOptionPopulator (com.salesmanager.shop.populator.catalog.PersistableProductOptionPopulator)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