Search in sources :

Example 1 with ReadableOrderProductPopulator

use of com.salesmanager.shop.populator.order.ReadableOrderProductPopulator in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method setOrderProductList.

private void setOrderProductList(final Order order, final Locale locale, final MerchantStore store, final Language language, final com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder) throws ConversionException {
    List<ReadableOrderProduct> orderProducts = new ArrayList<ReadableOrderProduct>();
    for (OrderProduct p : order.getOrderProducts()) {
        ReadableOrderProductPopulator orderProductPopulator = new ReadableOrderProductPopulator();
        orderProductPopulator.setLocale(locale);
        orderProductPopulator.setProductService(productService);
        orderProductPopulator.setPricingService(pricingService);
        orderProductPopulator.setimageUtils(imageUtils);
        ReadableOrderProduct orderProduct = new ReadableOrderProduct();
        orderProductPopulator.populate(p, orderProduct, store, language);
        // image
        // attributes
        orderProducts.add(orderProduct);
    }
    readableOrder.setProducts(orderProducts);
}
Also used : OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) ReadableOrderProductPopulator(com.salesmanager.shop.populator.order.ReadableOrderProductPopulator) ArrayList(java.util.ArrayList) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct)

Example 2 with ReadableOrderProductPopulator

use of com.salesmanager.shop.populator.order.ReadableOrderProductPopulator in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method getReadableOrder.

@Override
public com.salesmanager.shop.model.order.v0.ReadableOrder getReadableOrder(Long orderId, MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Order modelOrder = orderService.getOrder(orderId, store);
    if (modelOrder == null) {
        throw new ResourceNotFoundException("Order not found with id " + orderId);
    }
    com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder = new com.salesmanager.shop.model.order.v0.ReadableOrder();
    Long customerId = modelOrder.getCustomerId();
    if (customerId != null) {
        ReadableCustomer readableCustomer = customerFacade.getCustomerById(customerId, store, language);
        if (readableCustomer == null) {
            LOGGER.warn("Customer id " + customerId + " not found in order " + orderId);
        } else {
            readableOrder.setCustomer(readableCustomer);
        }
    }
    try {
        readableOrderPopulator.populate(modelOrder, readableOrder, store, language);
        // order products
        List<ReadableOrderProduct> orderProducts = new ArrayList<ReadableOrderProduct>();
        for (OrderProduct p : modelOrder.getOrderProducts()) {
            ReadableOrderProductPopulator orderProductPopulator = new ReadableOrderProductPopulator();
            orderProductPopulator.setProductService(productService);
            orderProductPopulator.setPricingService(pricingService);
            orderProductPopulator.setimageUtils(imageUtils);
            ReadableOrderProduct orderProduct = new ReadableOrderProduct();
            orderProductPopulator.populate(p, orderProduct, store, language);
            orderProducts.add(orderProduct);
        }
        readableOrder.setProducts(orderProducts);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while getting order [" + orderId + "]");
    }
    return readableOrder;
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) ArrayList(java.util.ArrayList) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) 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) ReadableOrderProductPopulator(com.salesmanager.shop.populator.order.ReadableOrderProductPopulator) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Aggregations

OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)2 PersistableOrderProduct (com.salesmanager.shop.model.order.PersistableOrderProduct)2 ReadableOrderProduct (com.salesmanager.shop.model.order.ReadableOrderProduct)2 ReadableOrderProductPopulator (com.salesmanager.shop.populator.order.ReadableOrderProductPopulator)2 ArrayList (java.util.ArrayList)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Order (com.salesmanager.core.model.order.Order)1 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)1 ShopOrder (com.salesmanager.shop.model.order.ShopOrder)1 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)1 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)1