Search in sources :

Example 1 with OrderProduct

use of com.salesmanager.core.model.order.orderproduct.OrderProduct in project shopizer by shopizer-ecommerce.

the class OrderServiceImpl method hasDownloadFiles.

@Override
public boolean hasDownloadFiles(Order order) throws ServiceException {
    Validate.notNull(order, "Order cannot be null");
    Validate.notNull(order.getOrderProducts(), "Order products cannot be null");
    Validate.notEmpty(order.getOrderProducts(), "Order products cannot be empty");
    boolean hasDownloads = false;
    for (OrderProduct orderProduct : order.getOrderProducts()) {
        if (CollectionUtils.isNotEmpty(orderProduct.getDownloads())) {
            hasDownloads = true;
            break;
        }
    }
    return hasDownloads;
}
Also used : OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct)

Example 2 with OrderProduct

use of com.salesmanager.core.model.order.orderproduct.OrderProduct in project shopizer by shopizer-ecommerce.

the class OrderProductPopulator method populate.

/**
 * Converts a ShoppingCartItem carried in the ShoppingCart to an OrderProduct
 * that will be saved in the system
 */
@Override
public OrderProduct populate(ShoppingCartItem source, OrderProduct target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(productService, "productService must be set");
    Validate.notNull(digitalProductService, "digitalProductService must be set");
    Validate.notNull(productAttributeService, "productAttributeService must be set");
    try {
        Product modelProduct = productService.getById(source.getProductId());
        if (modelProduct == null) {
            throw new ConversionException("Cannot get product with id (productId) " + source.getProductId());
        }
        if (modelProduct.getMerchantStore().getId().intValue() != store.getId().intValue()) {
            throw new ConversionException("Invalid product id " + source.getProductId());
        }
        DigitalProduct digitalProduct = digitalProductService.getByProduct(store, modelProduct);
        if (digitalProduct != null) {
            OrderProductDownload orderProductDownload = new OrderProductDownload();
            orderProductDownload.setOrderProductFilename(digitalProduct.getProductFileName());
            orderProductDownload.setOrderProduct(target);
            orderProductDownload.setDownloadCount(0);
            orderProductDownload.setMaxdays(ApplicationConstants.MAX_DOWNLOAD_DAYS);
            target.getDownloads().add(orderProductDownload);
        }
        target.setOneTimeCharge(source.getItemPrice());
        target.setProductName(source.getProduct().getDescriptions().iterator().next().getName());
        target.setProductQuantity(source.getQuantity());
        target.setSku(source.getProduct().getSku());
        FinalPrice finalPrice = source.getFinalPrice();
        if (finalPrice == null) {
            throw new ConversionException("Object final price not populated in shoppingCartItem (source)");
        }
        // Default price
        OrderProductPrice orderProductPrice = orderProductPrice(finalPrice);
        orderProductPrice.setOrderProduct(target);
        Set<OrderProductPrice> prices = new HashSet<OrderProductPrice>();
        prices.add(orderProductPrice);
        // Other prices
        List<FinalPrice> otherPrices = finalPrice.getAdditionalPrices();
        if (otherPrices != null) {
            for (FinalPrice otherPrice : otherPrices) {
                OrderProductPrice other = orderProductPrice(otherPrice);
                other.setOrderProduct(target);
                prices.add(other);
            }
        }
        target.setPrices(prices);
        // OrderProductAttribute
        Set<ShoppingCartAttributeItem> attributeItems = source.getAttributes();
        if (!CollectionUtils.isEmpty(attributeItems)) {
            Set<OrderProductAttribute> attributes = new HashSet<OrderProductAttribute>();
            for (ShoppingCartAttributeItem attribute : attributeItems) {
                OrderProductAttribute orderProductAttribute = new OrderProductAttribute();
                orderProductAttribute.setOrderProduct(target);
                Long id = attribute.getProductAttributeId();
                ProductAttribute attr = productAttributeService.getById(id);
                if (attr == null) {
                    throw new ConversionException("Attribute id " + id + " does not exists");
                }
                if (attr.getProduct().getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Attribute id " + id + " invalid for this store");
                }
                orderProductAttribute.setProductAttributeIsFree(attr.getProductAttributeIsFree());
                orderProductAttribute.setProductAttributeName(attr.getProductOption().getDescriptionsSettoList().get(0).getName());
                orderProductAttribute.setProductAttributeValueName(attr.getProductOptionValue().getDescriptionsSettoList().get(0).getName());
                orderProductAttribute.setProductAttributePrice(attr.getProductAttributePrice());
                orderProductAttribute.setProductAttributeWeight(attr.getProductAttributeWeight());
                orderProductAttribute.setProductOptionId(attr.getProductOption().getId());
                orderProductAttribute.setProductOptionValueId(attr.getProductOptionValue().getId());
                attributes.add(orderProductAttribute);
            }
            target.setOrderAttributes(attributes);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Product(com.salesmanager.core.model.catalog.product.Product) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) DigitalProduct(com.salesmanager.core.model.catalog.product.file.DigitalProduct) ShoppingCartAttributeItem(com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) ConversionException(com.salesmanager.core.business.exception.ConversionException) OrderProductPrice(com.salesmanager.core.model.order.orderproduct.OrderProductPrice) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) OrderProductDownload(com.salesmanager.core.model.order.orderproduct.OrderProductDownload) DigitalProduct(com.salesmanager.core.model.catalog.product.file.DigitalProduct) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) HashSet(java.util.HashSet)

Example 3 with OrderProduct

use of com.salesmanager.core.model.order.orderproduct.OrderProduct in project shopizer by shopizer-ecommerce.

the class PersistableOrderPopulator method populate.

@Override
public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(productService, "productService must be set");
    Validate.notNull(digitalProductService, "digitalProductService must be set");
    Validate.notNull(productAttributeService, "productAttributeService must be set");
    Validate.notNull(customerService, "customerService must be set");
    Validate.notNull(countryService, "countryService must be set");
    Validate.notNull(zoneService, "zoneService must be set");
    Validate.notNull(currencyService, "currencyService must be set");
    try {
        Map<String, Country> countriesMap = countryService.getCountriesMap(language);
        Map<String, Zone> zonesMap = zoneService.getZones(language);
        /**
         * customer *
         */
        PersistableCustomer customer = source.getCustomer();
        if (customer != null) {
            if (customer.getId() != null && customer.getId() > 0) {
                Customer modelCustomer = customerService.getById(customer.getId());
                if (modelCustomer == null) {
                    throw new ConversionException("Customer id " + customer.getId() + " does not exists");
                }
                if (modelCustomer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Customer id " + customer.getId() + " does not exists for store " + store.getCode());
                }
                target.setCustomerId(modelCustomer.getId());
                target.setBilling(modelCustomer.getBilling());
                target.setDelivery(modelCustomer.getDelivery());
                target.setCustomerEmailAddress(source.getCustomer().getEmailAddress());
            }
        }
        target.setLocale(LocaleUtils.getLocale(store));
        CreditCard creditCard = source.getCreditCard();
        if (creditCard != null) {
            String maskedNumber = CreditCardUtils.maskCardNumber(creditCard.getCcNumber());
            creditCard.setCcNumber(maskedNumber);
            target.setCreditCard(creditCard);
        }
        Currency currency = null;
        try {
            currency = currencyService.getByCode(source.getCurrency());
        } catch (Exception e) {
            throw new ConversionException("Currency not found for code " + source.getCurrency());
        }
        if (currency == null) {
            throw new ConversionException("Currency not found for code " + source.getCurrency());
        }
        target.setCurrency(currency);
        target.setDatePurchased(source.getDatePurchased());
        // target.setCurrency(store.getCurrency());
        target.setCurrencyValue(new BigDecimal(0));
        target.setMerchant(store);
        target.setStatus(source.getOrderStatus());
        target.setPaymentModuleCode(source.getPaymentModule());
        target.setPaymentType(source.getPaymentType());
        target.setShippingModuleCode(source.getShippingModule());
        target.setCustomerAgreement(source.isCustomerAgreed());
        target.setConfirmedAddress(source.isConfirmedAddress());
        if (source.getPreviousOrderStatus() != null) {
            List<OrderStatus> orderStatusList = source.getPreviousOrderStatus();
            for (OrderStatus status : orderStatusList) {
                OrderStatusHistory statusHistory = new OrderStatusHistory();
                statusHistory.setStatus(status);
                statusHistory.setOrder(target);
                target.getOrderHistory().add(statusHistory);
            }
        }
        if (!StringUtils.isBlank(source.getComments())) {
            OrderStatusHistory statusHistory = new OrderStatusHistory();
            statusHistory.setStatus(null);
            statusHistory.setOrder(target);
            statusHistory.setComments(source.getComments());
            target.getOrderHistory().add(statusHistory);
        }
        List<PersistableOrderProduct> products = source.getOrderProductItems();
        if (CollectionUtils.isEmpty(products)) {
            throw new ConversionException("Requires at least 1 PersistableOrderProduct");
        }
        com.salesmanager.shop.populator.order.PersistableOrderProductPopulator orderProductPopulator = new PersistableOrderProductPopulator();
        orderProductPopulator.setProductAttributeService(productAttributeService);
        orderProductPopulator.setProductService(productService);
        orderProductPopulator.setDigitalProductService(digitalProductService);
        for (PersistableOrderProduct orderProduct : products) {
            OrderProduct modelOrderProduct = new OrderProduct();
            orderProductPopulator.populate(orderProduct, modelOrderProduct, store, language);
            target.getOrderProducts().add(modelOrderProduct);
        }
        List<OrderTotal> orderTotals = source.getTotals();
        if (CollectionUtils.isNotEmpty(orderTotals)) {
            for (OrderTotal total : orderTotals) {
                com.salesmanager.core.model.order.OrderTotal totalModel = new com.salesmanager.core.model.order.OrderTotal();
                totalModel.setModule(total.getModule());
                totalModel.setOrder(target);
                totalModel.setOrderTotalCode(total.getCode());
                totalModel.setTitle(total.getTitle());
                totalModel.setValue(total.getValue());
                target.getOrderTotal().add(totalModel);
            }
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) OrderStatus(com.salesmanager.core.model.order.orderstatus.OrderStatus) Currency(com.salesmanager.core.model.reference.currency.Currency) ConversionException(com.salesmanager.core.business.exception.ConversionException) Zone(com.salesmanager.core.model.reference.zone.Zone) CreditCard(com.salesmanager.core.model.order.payment.CreditCard) ConversionException(com.salesmanager.core.business.exception.ConversionException) BigDecimal(java.math.BigDecimal) Country(com.salesmanager.core.model.reference.country.Country) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) OrderTotal(com.salesmanager.shop.model.order.total.OrderTotal)

Example 4 with OrderProduct

use of com.salesmanager.core.model.order.orderproduct.OrderProduct in project shopizer by shopizer-ecommerce.

the class ReadableOrderProductMapper method merge.

@Override
public ReadableOrderProduct merge(OrderProduct source, ReadableOrderProduct target, MerchantStore store, Language language) {
    Validate.notNull(source, "OrderProduct cannot be null");
    Validate.notNull(target, "ReadableOrderProduct cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    target.setId(source.getId());
    target.setOrderedQuantity(source.getProductQuantity());
    try {
        target.setPrice(pricingService.getDisplayAmount(source.getOneTimeCharge(), store));
    } catch (Exception e) {
        throw new ConversionRuntimeException("Cannot convert price", e);
    }
    target.setProductName(source.getProductName());
    target.setSku(source.getSku());
    // subtotal = price * quantity
    BigDecimal subTotal = source.getOneTimeCharge();
    subTotal = subTotal.multiply(new BigDecimal(source.getProductQuantity()));
    try {
        String subTotalPrice = pricingService.getDisplayAmount(subTotal, store);
        target.setSubTotal(subTotalPrice);
    } catch (Exception e) {
        throw new ConversionRuntimeException("Cannot format price", e);
    }
    if (source.getOrderAttributes() != null) {
        List<ReadableOrderProductAttribute> attributes = new ArrayList<ReadableOrderProductAttribute>();
        for (OrderProductAttribute attr : source.getOrderAttributes()) {
            ReadableOrderProductAttribute readableAttribute = new ReadableOrderProductAttribute();
            try {
                String price = pricingService.getDisplayAmount(attr.getProductAttributePrice(), store);
                readableAttribute.setAttributePrice(price);
            } catch (ServiceException e) {
                throw new ConversionRuntimeException("Cannot format price", e);
            }
            readableAttribute.setAttributeName(attr.getProductAttributeName());
            readableAttribute.setAttributeValue(attr.getProductAttributeValueName());
            attributes.add(readableAttribute);
        }
        target.setAttributes(attributes);
    }
    String productSku = source.getSku();
    if (!StringUtils.isBlank(productSku)) {
        Product product = productService.getByCode(productSku, language);
        if (product != null) {
            // TODO autowired
            ReadableProductPopulator populator = new ReadableProductPopulator();
            populator.setPricingService(pricingService);
            populator.setimageUtils(imageUtils);
            ReadableProduct productProxy;
            try {
                productProxy = populator.populate(product, new ReadableProduct(), store, language);
                target.setProduct(productProxy);
            } catch (ConversionException e) {
                throw new ConversionRuntimeException("Cannot convert product", e);
            }
            Set<ProductImage> images = product.getImages();
            ProductImage defaultImage = null;
            if (images != null) {
                for (ProductImage image : images) {
                    if (defaultImage == null) {
                        defaultImage = image;
                    }
                    if (image.isDefaultImage()) {
                        defaultImage = image;
                    }
                }
            }
            if (defaultImage != null) {
                target.setImage(defaultImage.getProductImage());
            }
        }
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ReadableOrderProductAttribute(com.salesmanager.shop.model.order.ReadableOrderProductAttribute) ArrayList(java.util.ArrayList) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ServiceException(com.salesmanager.core.business.exception.ServiceException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) BigDecimal(java.math.BigDecimal) ServiceException(com.salesmanager.core.business.exception.ServiceException) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) ReadableOrderProductAttribute(com.salesmanager.shop.model.order.ReadableOrderProductAttribute) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 5 with OrderProduct

use of com.salesmanager.core.model.order.orderproduct.OrderProduct in project shopizer by shopizer-ecommerce.

the class ReadableOrderProductPopulator method populate.

@Override
public ReadableOrderProduct populate(OrderProduct source, ReadableOrderProduct target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(productService, "Requires ProductService");
    Validate.notNull(pricingService, "Requires PricingService");
    Validate.notNull(imageUtils, "Requires imageUtils");
    target.setId(source.getId());
    target.setOrderedQuantity(source.getProductQuantity());
    try {
        target.setPrice(pricingService.getDisplayAmount(source.getOneTimeCharge(), store));
    } catch (Exception e) {
        throw new ConversionException("Cannot convert price", e);
    }
    target.setProductName(source.getProductName());
    target.setSku(source.getSku());
    // subtotal = price * quantity
    BigDecimal subTotal = source.getOneTimeCharge();
    subTotal = subTotal.multiply(new BigDecimal(source.getProductQuantity()));
    try {
        String subTotalPrice = pricingService.getDisplayAmount(subTotal, store);
        target.setSubTotal(subTotalPrice);
    } catch (Exception e) {
        throw new ConversionException("Cannot format price", e);
    }
    if (source.getOrderAttributes() != null) {
        List<ReadableOrderProductAttribute> attributes = new ArrayList<ReadableOrderProductAttribute>();
        for (OrderProductAttribute attr : source.getOrderAttributes()) {
            ReadableOrderProductAttribute readableAttribute = new ReadableOrderProductAttribute();
            try {
                String price = pricingService.getDisplayAmount(attr.getProductAttributePrice(), store);
                readableAttribute.setAttributePrice(price);
            } catch (ServiceException e) {
                throw new ConversionException("Cannot format price", e);
            }
            readableAttribute.setAttributeName(attr.getProductAttributeName());
            readableAttribute.setAttributeValue(attr.getProductAttributeValueName());
            attributes.add(readableAttribute);
        }
        target.setAttributes(attributes);
    }
    String productSku = source.getSku();
    if (!StringUtils.isBlank(productSku)) {
        Product product = productService.getByCode(productSku, language);
        if (product != null) {
            ReadableProductPopulator populator = new ReadableProductPopulator();
            populator.setPricingService(pricingService);
            populator.setimageUtils(imageUtils);
            ReadableProduct productProxy = populator.populate(product, new ReadableProduct(), store, language);
            target.setProduct(productProxy);
            Set<ProductImage> images = product.getImages();
            ProductImage defaultImage = null;
            if (images != null) {
                for (ProductImage image : images) {
                    if (defaultImage == null) {
                        defaultImage = image;
                    }
                    if (image.isDefaultImage()) {
                        defaultImage = image;
                    }
                }
            }
            if (defaultImage != null) {
                target.setImage(defaultImage.getProductImage());
            }
        }
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ReadableOrderProductAttribute(com.salesmanager.shop.model.order.ReadableOrderProductAttribute) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ServiceException(com.salesmanager.core.business.exception.ServiceException) ConversionException(com.salesmanager.core.business.exception.ConversionException) BigDecimal(java.math.BigDecimal) ServiceException(com.salesmanager.core.business.exception.ServiceException) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) ReadableOrderProductAttribute(com.salesmanager.shop.model.order.ReadableOrderProductAttribute)

Aggregations

OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)13 ConversionException (com.salesmanager.core.business.exception.ConversionException)8 Product (com.salesmanager.core.model.catalog.product.Product)7 ServiceException (com.salesmanager.core.business.exception.ServiceException)6 PersistableOrderProduct (com.salesmanager.shop.model.order.PersistableOrderProduct)6 ReadableOrderProduct (com.salesmanager.shop.model.order.ReadableOrderProduct)6 OrderProductAttribute (com.salesmanager.core.model.order.orderproduct.OrderProductAttribute)5 BigDecimal (java.math.BigDecimal)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 Order (com.salesmanager.core.model.order.Order)4 OrderStatusHistory (com.salesmanager.core.model.order.orderstatus.OrderStatusHistory)4 ReadableOrderProductPopulator (com.salesmanager.shop.populator.order.ReadableOrderProductPopulator)4 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)3 OrderProductPrice (com.salesmanager.core.model.order.orderproduct.OrderProductPrice)3 CreditCard (com.salesmanager.core.model.order.payment.CreditCard)3 Country (com.salesmanager.core.model.reference.country.Country)3 Zone (com.salesmanager.core.model.reference.zone.Zone)3 ShopOrder (com.salesmanager.shop.model.order.ShopOrder)3 OrderTotal (com.salesmanager.shop.model.order.total.OrderTotal)3