use of com.salesmanager.core.model.order.Order in project shopizer by shopizer-ecommerce.
the class PersistableTransactionPopulator method populate.
@Override
public Transaction populate(PersistableTransaction source, Transaction target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(source, "PersistableTransaction must not be null");
Validate.notNull(orderService, "OrderService must not be null");
Validate.notNull(pricingService, "OrderService must not be null");
if (target == null) {
target = new Transaction();
}
try {
target.setAmount(pricingService.getAmount(source.getAmount()));
target.setDetails(source.getDetails());
target.setPaymentType(PaymentType.valueOf(source.getPaymentType()));
target.setTransactionType(TransactionType.valueOf(source.getTransactionType()));
target.setTransactionDate(DateUtil.formatDate(source.getTransactionDate()));
if (source.getOrderId() != null && source.getOrderId().longValue() > 0) {
Order order = orderService.getById(source.getOrderId());
if (order == null) {
throw new ConversionException("Order with id " + source.getOrderId() + "does not exist");
}
target.setOrder(order);
}
return target;
} catch (Exception e) {
throw new ConversionException(e);
}
}
use of com.salesmanager.core.model.order.Order in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method populateOrderList.
private com.salesmanager.shop.model.order.v0.ReadableOrderList populateOrderList(final OrderList orderList, final MerchantStore store, final Language language) {
List<Order> orders = orderList.getOrders();
com.salesmanager.shop.model.order.v0.ReadableOrderList returnList = new com.salesmanager.shop.model.order.v0.ReadableOrderList();
if (CollectionUtils.isEmpty(orders)) {
LOGGER.info("Order list if empty..Returning empty list");
returnList.setRecordsTotal(0);
// returnList.setMessage("No results for store code " + store);
return returnList;
}
// ReadableOrderPopulator orderPopulator = new ReadableOrderPopulator();
Locale locale = LocaleUtils.getLocale(language);
readableOrderPopulator.setLocale(locale);
List<com.salesmanager.shop.model.order.v0.ReadableOrder> readableOrders = new ArrayList<com.salesmanager.shop.model.order.v0.ReadableOrder>();
for (Order order : orders) {
com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder = new com.salesmanager.shop.model.order.v0.ReadableOrder();
try {
readableOrderPopulator.populate(order, readableOrder, store, language);
setOrderProductList(order, locale, store, language, readableOrder);
} catch (ConversionException ex) {
LOGGER.error("Error while converting order to order data", ex);
}
readableOrders.add(readableOrder);
}
returnList.setOrders(readableOrders);
return returnList;
}
use of com.salesmanager.core.model.order.Order in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method getReadableOrderList.
@Override
public com.salesmanager.shop.model.order.v0.ReadableOrderList getReadableOrderList(OrderCriteria criteria, MerchantStore store) {
try {
criteria.setLegacyPagination(false);
OrderList orderList = orderService.getOrders(criteria, store);
List<Order> orders = orderList.getOrders();
com.salesmanager.shop.model.order.v0.ReadableOrderList returnList = new com.salesmanager.shop.model.order.v0.ReadableOrderList();
if (CollectionUtils.isEmpty(orders)) {
returnList.setRecordsTotal(0);
return returnList;
}
List<com.salesmanager.shop.model.order.v0.ReadableOrder> readableOrders = new ArrayList<com.salesmanager.shop.model.order.v0.ReadableOrder>();
for (Order order : orders) {
com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder = new com.salesmanager.shop.model.order.v0.ReadableOrder();
readableOrderPopulator.populate(order, readableOrder, null, null);
readableOrders.add(readableOrder);
}
returnList.setOrders(readableOrders);
returnList.setRecordsTotal(orderList.getTotalCount());
returnList.setTotalPages(orderList.getTotalPages());
returnList.setNumber(orderList.getOrders().size());
returnList.setRecordsFiltered(orderList.getOrders().size());
return returnList;
} catch (Exception e) {
throw new ServiceRuntimeException("Error while getting orders", e);
}
}
use of com.salesmanager.core.model.order.Order in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method getCapturableOrderList.
@Override
public com.salesmanager.shop.model.order.v0.ReadableOrderList getCapturableOrderList(MerchantStore store, Date startDate, Date endDate, Language language) throws Exception {
// get all transactions for the given date
List<Order> orders = orderService.getCapturableOrders(store, startDate, endDate);
// ReadableOrderPopulator orderPopulator = new ReadableOrderPopulator();
Locale locale = LocaleUtils.getLocale(language);
readableOrderPopulator.setLocale(locale);
com.salesmanager.shop.model.order.v0.ReadableOrderList returnList = new com.salesmanager.shop.model.order.v0.ReadableOrderList();
if (CollectionUtils.isEmpty(orders)) {
returnList.setRecordsTotal(0);
// returnList.setMessage("No results for store code " + store);
return null;
}
List<com.salesmanager.shop.model.order.v0.ReadableOrder> readableOrders = new ArrayList<com.salesmanager.shop.model.order.v0.ReadableOrder>();
for (Order order : orders) {
com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder = new com.salesmanager.shop.model.order.v0.ReadableOrder();
readableOrderPopulator.populate(order, readableOrder, store, language);
readableOrders.add(readableOrder);
}
returnList.setRecordsTotal(orders.size());
returnList.setOrders(readableOrders);
return returnList;
}
use of com.salesmanager.core.model.order.Order 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;
}
Aggregations