Search in sources :

Example 1 with DigitalProduct

use of com.salesmanager.core.model.catalog.product.file.DigitalProduct 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 2 with DigitalProduct

use of com.salesmanager.core.model.catalog.product.file.DigitalProduct in project shopizer by shopizer-ecommerce.

the class PersistableOrderProductPopulator method populate.

/**
 * Converts a ShoppingCartItem carried in the ShoppingCart to an OrderProduct
 * that will be saved in the system
 */
@Override
public OrderProduct populate(PersistableOrderProduct 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.getProduct().getId());
        if (modelProduct == null) {
            throw new ConversionException("Cannot get product with id (productId) " + source.getProduct().getId());
        }
        if (modelProduct.getMerchantStore().getId().intValue() != store.getId().intValue()) {
            throw new ConversionException("Invalid product id " + source.getProduct().getId());
        }
        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.getPrice());
        target.setProductName(source.getProduct().getDescription().getName());
        target.setProductQuantity(source.getOrderedQuantity());
        target.setSku(source.getProduct().getSku());
        OrderProductPrice orderProductPrice = new OrderProductPrice();
        orderProductPrice.setDefaultPrice(true);
        orderProductPrice.setProductPrice(source.getPrice());
        orderProductPrice.setOrderProduct(target);
        Set<OrderProductPrice> prices = new HashSet<OrderProductPrice>();
        prices.add(orderProductPrice);
        /**
         * DO NOT SUPPORT MUTIPLE PRICES *
         */
        /*			//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
        List<ProductAttribute> attributeItems = source.getAttributes();
        if (!CollectionUtils.isEmpty(attributeItems)) {
            Set<OrderProductAttribute> attributes = new HashSet<OrderProductAttribute>();
            for (ProductAttribute attribute : attributeItems) {
                OrderProductAttribute orderProductAttribute = new OrderProductAttribute();
                orderProductAttribute.setOrderProduct(target);
                Long id = attribute.getId();
                com.salesmanager.core.model.catalog.product.attribute.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) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) DigitalProduct(com.salesmanager.core.model.catalog.product.file.DigitalProduct) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) ProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.ProductAttribute) 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) HashSet(java.util.HashSet)

Aggregations

ConversionException (com.salesmanager.core.business.exception.ConversionException)2 Product (com.salesmanager.core.model.catalog.product.Product)2 DigitalProduct (com.salesmanager.core.model.catalog.product.file.DigitalProduct)2 OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)2 OrderProductAttribute (com.salesmanager.core.model.order.orderproduct.OrderProductAttribute)2 OrderProductDownload (com.salesmanager.core.model.order.orderproduct.OrderProductDownload)2 OrderProductPrice (com.salesmanager.core.model.order.orderproduct.OrderProductPrice)2 HashSet (java.util.HashSet)2 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)1 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)1 ShoppingCartAttributeItem (com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem)1 ProductAttribute (com.salesmanager.shop.model.catalog.product.attribute.ProductAttribute)1 PersistableOrderProduct (com.salesmanager.shop.model.order.PersistableOrderProduct)1