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;
}
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;
}
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;
}
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);
}
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;
}
}
Aggregations