Search in sources :

Example 1 with PersistableProductOptionValuePopulator

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