use of com.salesmanager.shop.model.catalog.product.ReadableProductList 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;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProductList 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;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProductList in project shopizer by shopizer-ecommerce.
the class ShopProductRESTController method getProducts.
private ReadableProductList getProducts(final int start, final int max, final String store, final String language, final String category, final List<QueryFilter> filters, 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);
}
ProductCriteria productCriteria = new ProductCriteria();
productCriteria.setMaxCount(max);
productCriteria.setStartIndex(start);
// get the category by code
if (!StringUtils.isBlank(category)) {
Category cat = categoryService.getBySeUrl(merchantStore, category);
if (cat == null) {
LOGGER.error("Category " + category + " is null");
// TODO localized message
response.sendError(503, "Category is null");
return null;
}
String lineage = new StringBuilder().append(cat.getLineage()).append(cat.getId()).append("/").toString();
List<Category> categories = categoryService.getListByLineage(store, lineage);
List<Long> ids = new ArrayList<Long>();
if (categories != null && categories.size() > 0) {
for (Category c : categories) {
ids.add(c.getId());
}
}
ids.add(cat.getId());
productCriteria.setCategoryIds(ids);
}
if (filters != null) {
for (QueryFilter filter : filters) {
if (filter.getFilterType().name().equals(QueryFilterType.BRAND.name())) {
// the only filter implemented
productCriteria.setManufacturerId(filter.getFilterId());
}
}
}
com.salesmanager.core.model.catalog.product.ProductList products = productService.listByStore(merchantStore, lang, productCriteria);
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
ReadableProductList productList = new ReadableProductList();
for (Product product : products.getProducts()) {
// create new proxy product
ReadableProduct readProduct = populator.populate(product, new ReadableProduct(), merchantStore, lang);
productList.getProducts().add(readProduct);
}
productList.setTotalPages(Math.toIntExact(products.getTotalCount()));
return productList;
} catch (Exception e) {
LOGGER.error("Error while getting products", e);
response.sendError(503, "An error occured while retrieving products " + e.getMessage());
}
return null;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProductList in project shopizer by shopizer-ecommerce.
the class ProductGroupApi method addProductToGroup.
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/private/products/{productId}/group/{code}", method = RequestMethod.POST)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public ReadableProductList addProductToGroup(@PathVariable Long productId, @PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) {
Product product = null;
try {
// get the product
product = productService.getById(productId);
if (product == null) {
response.sendError(404, "Product not fount for id " + productId);
return null;
}
} catch (Exception e) {
LOGGER.error("Error while adding product to group", e);
try {
response.sendError(503, "Error while adding product to group " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
ReadableProductList list = productItemsFacade.addItemToGroup(product, code, merchantStore, language);
return list;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProductList in project shopizer by shopizer-ecommerce.
the class ProductGroupApi method removeProductFromGroup.
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/private/products/{productId}/group/{code}", method = RequestMethod.DELETE)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public ReadableProductList removeProductFromGroup(@PathVariable Long productId, @PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
try {
// get the product
Product product = productService.getById(productId);
if (product == null) {
response.sendError(404, "Product not fount for id " + productId);
return null;
}
ReadableProductList list = productItemsFacade.removeItemFromGroup(product, code, merchantStore, language);
return list;
} catch (Exception e) {
LOGGER.error("Error while removing product from category", e);
try {
response.sendError(503, "Error while removing product from category " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
Aggregations