Search in sources :

Example 6 with ShippingProduct

use of com.salesmanager.core.model.shipping.ShippingProduct in project shopizer by shopizer-ecommerce.

the class PackingBox method getItemPackagesDetails.

@Override
public List<PackageDetails> getItemPackagesDetails(List<ShippingProduct> products, MerchantStore store) throws ServiceException {
    List<PackageDetails> packages = new ArrayList<PackageDetails>();
    for (ShippingProduct shippingProduct : products) {
        Product product = shippingProduct.getProduct();
        if (product.isProductVirtual()) {
            continue;
        }
        // BigDecimal weight = product.getProductWeight();
        Set<ProductAttribute> attributes = product.getAttributes();
        // set attributes values
        BigDecimal w = product.getProductWeight();
        BigDecimal h = product.getProductHeight();
        BigDecimal l = product.getProductLength();
        BigDecimal wd = product.getProductWidth();
        if (w == null) {
            w = new BigDecimal(defaultWeight);
        }
        if (h == null) {
            h = new BigDecimal(defaultHeight);
        }
        if (l == null) {
            l = new BigDecimal(defaultLength);
        }
        if (wd == null) {
            wd = new BigDecimal(defaultWidth);
        }
        if (attributes != null && attributes.size() > 0) {
            for (ProductAttribute attribute : attributes) {
                if (attribute.getAttributeAdditionalWeight() != null && attribute.getProductAttributeWeight() != null) {
                    w = w.add(attribute.getProductAttributeWeight());
                }
            }
        }
        if (shippingProduct.getQuantity() == 1) {
            PackageDetails detail = new PackageDetails();
            detail.setShippingHeight(h.doubleValue());
            detail.setShippingLength(l.doubleValue());
            detail.setShippingWeight(w.doubleValue());
            detail.setShippingWidth(wd.doubleValue());
            detail.setShippingQuantity(shippingProduct.getQuantity());
            String description = "item";
            if (product.getDescriptions().size() > 0) {
                description = product.getDescriptions().iterator().next().getName();
            }
            detail.setItemName(description);
            packages.add(detail);
        } else if (shippingProduct.getQuantity() > 1) {
            for (int i = 0; i < shippingProduct.getQuantity(); i++) {
                PackageDetails detail = new PackageDetails();
                detail.setShippingHeight(h.doubleValue());
                detail.setShippingLength(l.doubleValue());
                detail.setShippingWeight(w.doubleValue());
                detail.setShippingWidth(wd.doubleValue());
                // issue seperate shipping
                detail.setShippingQuantity(1);
                String description = "item";
                if (product.getDescriptions().size() > 0) {
                    description = product.getDescriptions().iterator().next().getName();
                }
                detail.setItemName(description);
                packages.add(detail);
            }
        }
    }
    return packages;
}
Also used : ArrayList(java.util.ArrayList) ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) Product(com.salesmanager.core.model.catalog.product.Product) ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) PackageDetails(com.salesmanager.core.model.shipping.PackageDetails) BigDecimal(java.math.BigDecimal)

Example 7 with ShippingProduct

use of com.salesmanager.core.model.shipping.ShippingProduct in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method getShippingQuote.

@Override
public ShippingQuote getShippingQuote(Customer customer, ShoppingCart cart, com.salesmanager.shop.model.order.v0.PersistableOrder order, MerchantStore store, Language language) throws Exception {
    // create shipping products
    List<ShippingProduct> shippingProducts = shoppingCartService.createShippingProduct(cart);
    if (CollectionUtils.isEmpty(shippingProducts)) {
        // products are virtual
        return null;
    }
    Delivery delivery = new Delivery();
    // adjust shipping and billing
    if (order.isShipToBillingAdress()) {
        Billing billing = customer.getBilling();
        delivery.setAddress(billing.getAddress());
        delivery.setCity(billing.getCity());
        delivery.setCompany(billing.getCompany());
        delivery.setPostalCode(billing.getPostalCode());
        delivery.setState(billing.getState());
        delivery.setCountry(billing.getCountry());
        delivery.setZone(billing.getZone());
    } else {
        delivery = customer.getDelivery();
    }
    ShippingQuote quote = shippingService.getShippingQuote(cart.getId(), store, delivery, shippingProducts, language);
    return quote;
}
Also used : ShippingQuote(com.salesmanager.core.model.shipping.ShippingQuote) Billing(com.salesmanager.core.model.common.Billing) ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) Delivery(com.salesmanager.core.model.common.Delivery)

Example 8 with ShippingProduct

use of com.salesmanager.core.model.shipping.ShippingProduct in project shopizer by shopizer-ecommerce.

the class ShoppingCartServiceImpl method createShippingProduct.

@Override
public List<ShippingProduct> createShippingProduct(final ShoppingCart cart) throws ServiceException {
    /**
     * Determines if products are virtual
     */
    Set<ShoppingCartItem> items = cart.getLineItems();
    List<ShippingProduct> shippingProducts = null;
    for (ShoppingCartItem item : items) {
        Product product = item.getProduct();
        if (!product.isProductVirtual() && product.isProductShipeable()) {
            if (shippingProducts == null) {
                shippingProducts = new ArrayList<ShippingProduct>();
            }
            ShippingProduct shippingProduct = new ShippingProduct(product);
            shippingProduct.setQuantity(item.getQuantity());
            shippingProduct.setFinalPrice(item.getFinalPrice());
            shippingProducts.add(shippingProduct);
        }
    }
    return shippingProducts;
}
Also used : ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) Product(com.salesmanager.core.model.catalog.product.Product) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem)

Aggregations

ShippingProduct (com.salesmanager.core.model.shipping.ShippingProduct)8 Product (com.salesmanager.core.model.catalog.product.Product)4 Billing (com.salesmanager.core.model.common.Billing)4 Delivery (com.salesmanager.core.model.common.Delivery)4 ShippingQuote (com.salesmanager.core.model.shipping.ShippingQuote)4 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)3 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)2 Customer (com.salesmanager.core.model.customer.Customer)2 PackageDetails (com.salesmanager.core.model.shipping.PackageDetails)2 ShippingConfiguration (com.salesmanager.core.model.shipping.ShippingConfiguration)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)1 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)1 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)1 ProductPrice (com.salesmanager.core.model.catalog.product.price.ProductPrice)1 ProductPriceDescription (com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)1 ProductType (com.salesmanager.core.model.catalog.product.type.ProductType)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Country (com.salesmanager.core.model.reference.country.Country)1