Search in sources :

Example 71 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.

the class OrderRESTController method createOrder.

/**
 * This method is for adding order to the system. Generally used for the purpose of migration only
 * This method won't process any payment nor create transactions
 * @param store
 * @param order
 * @param request
 * @param response
 * @return
 * @throws Exception
 * Use v1 methods
 */
@RequestMapping(value = "/{store}/order", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
@Deprecated
public PersistableOrder createOrder(@PathVariable final String store, @Valid @RequestBody PersistableOrder order, HttpServletRequest request, HttpServletResponse response) throws Exception {
    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;
    }
    PersistableCustomer cust = order.getCustomer();
    if (cust != null) {
        Customer customer = new Customer();
        /*			CustomerPopulator populator = new CustomerPopulator();
			populator.setCountryService(countryService);
			populator.setCustomerOptionService(customerOptionService);
			populator.setCustomerOptionValueService(customerOptionValueService);
			populator.setLanguageService(languageService);
			populator.setZoneService(zoneService);
			populator.setGroupService(groupService);*/
        customerPopulator.populate(cust, customer, merchantStore, merchantStore.getDefaultLanguage());
        customerService.save(customer);
        cust.setId(customer.getId());
    }
    Order modelOrder = new Order();
    PersistableOrderPopulator populator = new PersistableOrderPopulator();
    populator.setDigitalProductService(digitalProductService);
    populator.setProductAttributeService(productAttributeService);
    populator.setProductService(productService);
    populator.populate(order, modelOrder, merchantStore, merchantStore.getDefaultLanguage());
    orderService.save(modelOrder);
    order.setId(modelOrder.getId());
    return order;
}
Also used : Order(com.salesmanager.core.model.order.Order) PersistableOrder(com.salesmanager.shop.model.order.v0.PersistableOrder) PersistableOrderPopulator(com.salesmanager.shop.populator.order.PersistableOrderPopulator) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore)

Example 72 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.

the class ProductItemsRESTController method getProductItemsByGroup.

/**
 * Query for a product group
 * public/products/{store code}/products/group/{id}?lang=fr|en
 * no lang it will take session lang or default store lang
 * @param store
 * @param language
 * @param groupCode
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/public/{store}/products/group/{code}")
@ResponseBody
public ReadableProductList getProductItemsByGroup(@PathVariable String store, @PathVariable final String code, HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {
        MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
        if (merchantStore != null) {
            if (!merchantStore.getCode().equals(store)) {
                // reset for the current request
                merchantStore = null;
            }
        }
        if (merchantStore == null) {
            merchantStore = merchantStoreService.getByCode(store);
        }
        if (merchantStore == null) {
            LOGGER.error("Merchant store is null for code " + store);
            // TODO localized message
            response.sendError(503, "Merchant store is null for code " + store);
            return null;
        }
        Language lang = languageUtils.getRequestLanguage(request, response);
        // get product group
        List<ProductRelationship> group = productRelationshipService.getByGroup(merchantStore, code, lang);
        if (group != null) {
            Date today = new Date();
            List<Long> ids = new ArrayList<Long>();
            for (ProductRelationship relationship : group) {
                Product product = relationship.getRelatedProduct();
                if (product.isAvailable() && DateUtil.dateBeforeEqualsDate(product.getDateAvailable(), today)) {
                    ids.add(product.getId());
                }
            }
            ReadableProductList list = productItemsFacade.listItemsByIds(merchantStore, lang, ids, 0, 0);
            return list;
        }
    } catch (Exception e) {
        LOGGER.error("Error while getting products", e);
        response.sendError(503, "An error occured while retrieving products " + e.getMessage());
    }
    return null;
}
Also used : ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) Language(com.salesmanager.core.model.reference.language.Language) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ArrayList(java.util.ArrayList) Product(com.salesmanager.core.model.catalog.product.Product) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 73 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.

the class ProductItemsRESTController method getProductItemsByManufacturer.

/**
 * Items for manufacturer
 * filter=BRAND&filter-value=123
 * @param start
 * @param max
 * @param store
 * @param language
 * @param category
 * @param filterType
 * @param filterValue
 * @param model
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
/**
 * fixed filter *
 */
@RequestMapping("/public/products/page/{start}/{max}/{store}/{language}/manufacturer/{id}")
@ResponseBody
public ReadableProductList getProductItemsByManufacturer(@PathVariable int start, @PathVariable int max, @PathVariable String store, @PathVariable final String language, @PathVariable final Long id, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {
        /**
         * How to Spring MVC Rest web service - ajax / jquery
         * http://codetutr.com/2013/04/09/spring-mvc-easy-rest-based-json-services-with-responsebody/
         */
        MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
        Map<String, Language> langs = languageService.getLanguagesMap();
        if (merchantStore != null) {
            if (!merchantStore.getCode().equals(store)) {
                // reset for the current request
                merchantStore = null;
            }
        }
        if (merchantStore == null) {
            merchantStore = merchantStoreService.getByCode(store);
        }
        if (merchantStore == null) {
            LOGGER.error("Merchant store is null for code " + store);
            // TODO localized message
            response.sendError(503, "Merchant store is null for code " + store);
            return null;
        }
        Language lang = langs.get(language);
        if (lang == null) {
            lang = langs.get(Constants.DEFAULT_LANGUAGE);
        }
        ReadableProductList list = productItemsFacade.listItemsByManufacturer(merchantStore, lang, id, start, max);
        return list;
    } catch (Exception e) {
        LOGGER.error("Error while getting products", e);
        response.sendError(503, "An error occured while retrieving products " + e.getMessage());
    }
    return null;
}
Also used : ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 74 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.

the class ShopProductRESTController method getProducts.

@RequestMapping("/public/products/{store}")
@ResponseBody
public ReadableProductList getProducts(@PathVariable String store, HttpServletRequest request, HttpServletResponse response) throws Exception {
    /**
     * default routine *
     */
    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;
    }
    Language l = merchantStore.getDefaultLanguage();
    String lang = l.getCode();
    if (!StringUtils.isBlank(request.getParameter(Constants.LANG))) {
        lang = request.getParameter(Constants.LANG);
    }
    return this.getProducts(0, 10000, store, lang, null, null, request, response);
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 75 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore 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)171 Language (com.salesmanager.core.model.reference.language.Language)123 ServiceException (com.salesmanager.core.business.exception.ServiceException)72 List (java.util.List)65 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)62 ArrayList (java.util.ArrayList)61 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)60 Collectors (java.util.stream.Collectors)60 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)52 Autowired (org.springframework.beans.factory.annotation.Autowired)46 Product (com.salesmanager.core.model.catalog.product.Product)43 Service (org.springframework.stereotype.Service)37 Optional (java.util.Optional)35 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)35 Customer (com.salesmanager.core.model.customer.Customer)33 Logger (org.slf4j.Logger)33 LoggerFactory (org.slf4j.LoggerFactory)33 Inject (javax.inject.Inject)32 Validate (org.apache.commons.lang3.Validate)30 ConversionException (com.salesmanager.core.business.exception.ConversionException)27