Search in sources :

Example 6 with Order

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);
    }
}
Also used : Order(com.salesmanager.core.model.order.Order) ConversionException(com.salesmanager.core.business.exception.ConversionException) PersistableTransaction(com.salesmanager.shop.model.order.transaction.PersistableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 7 with Order

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;
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) Locale(java.util.Locale) ConversionException(com.salesmanager.core.business.exception.ConversionException) ArrayList(java.util.ArrayList)

Example 8 with Order

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);
    }
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ArrayList(java.util.ArrayList) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) OrderList(com.salesmanager.core.model.order.OrderList)

Example 9 with Order

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;
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) Locale(java.util.Locale) ArrayList(java.util.ArrayList)

Example 10 with Order

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

Aggregations

Order (com.salesmanager.core.model.order.Order)26 ShopOrder (com.salesmanager.shop.model.order.ShopOrder)15 ConversionException (com.salesmanager.core.business.exception.ConversionException)12 ServiceException (com.salesmanager.core.business.exception.ServiceException)12 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)11 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)11 ArrayList (java.util.ArrayList)11 Customer (com.salesmanager.core.model.customer.Customer)9 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)9 Language (com.salesmanager.core.model.reference.language.Language)7 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)7 OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)6 Transaction (com.salesmanager.core.model.payments.Transaction)6 OrderList (com.salesmanager.core.model.order.OrderList)5 OrderTotalSummary (com.salesmanager.core.model.order.OrderTotalSummary)5 OrderStatusHistory (com.salesmanager.core.model.order.orderstatus.OrderStatusHistory)5 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)5 ReadableOrderProduct (com.salesmanager.shop.model.order.ReadableOrderProduct)5 HashMap (java.util.HashMap)5 Product (com.salesmanager.core.model.catalog.product.Product)4