Search in sources :

Example 6 with Delivery

use of com.salesmanager.core.model.common.Delivery in project shopizer by shopizer-ecommerce.

the class CustomerPopulator method populate.

/**
 * Creates a Customer entity ready to be saved
 */
@Override
public Customer populate(PersistableCustomer source, Customer target, MerchantStore store, Language language) throws ConversionException {
    try {
        if (source.getId() != null && source.getId() > 0) {
            target.setId(source.getId());
        }
        if (!StringUtils.isBlank(source.getPassword())) {
            target.setPassword(passwordEncoder.encode(source.getPassword()));
            target.setNick(source.getUserName());
            target.setAnonymous(false);
        }
        if (source.getBilling() != null) {
            target.setBilling(new Billing());
            if (!StringUtils.isEmpty(source.getFirstName())) {
                target.getBilling().setFirstName(source.getFirstName());
            }
            if (!StringUtils.isEmpty(source.getLastName())) {
                target.getBilling().setLastName(source.getLastName());
            }
        }
        if (!StringUtils.isBlank(source.getProvider())) {
            target.setProvider(source.getProvider());
        }
        if (!StringUtils.isBlank(source.getEmailAddress())) {
            target.setEmailAddress(source.getEmailAddress());
        }
        if (source.getGender() != null && target.getGender() == null) {
            target.setGender(com.salesmanager.core.model.customer.CustomerGender.valueOf(source.getGender()));
        }
        if (target.getGender() == null) {
            target.setGender(com.salesmanager.core.model.customer.CustomerGender.M);
        }
        Map<String, Country> countries = countryService.getCountriesMap(language);
        Map<String, Zone> zones = zoneService.getZones(language);
        target.setMerchantStore(store);
        Address sourceBilling = source.getBilling();
        if (sourceBilling != null) {
            Billing billing = target.getBilling();
            billing.setAddress(sourceBilling.getAddress());
            billing.setCity(sourceBilling.getCity());
            billing.setCompany(sourceBilling.getCompany());
            // billing.setCountry(country);
            if (!StringUtils.isEmpty(sourceBilling.getFirstName()))
                billing.setFirstName(sourceBilling.getFirstName());
            if (!StringUtils.isEmpty(sourceBilling.getLastName()))
                billing.setLastName(sourceBilling.getLastName());
            billing.setTelephone(sourceBilling.getPhone());
            billing.setPostalCode(sourceBilling.getPostalCode());
            billing.setState(sourceBilling.getStateProvince());
            Country billingCountry = null;
            if (!StringUtils.isBlank(sourceBilling.getCountry())) {
                billingCountry = countries.get(sourceBilling.getCountry());
                if (billingCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceBilling.getCountry());
                }
                billing.setCountry(billingCountry);
            }
            if (billingCountry != null && !StringUtils.isBlank(sourceBilling.getZone())) {
                Zone zone = zoneService.getByCode(sourceBilling.getZone());
                if (zone == null) {
                    throw new ConversionException("Unsuported zone code " + sourceBilling.getZone());
                }
                Zone zoneDescription = zones.get(zone.getCode());
                billing.setZone(zoneDescription);
            }
        // target.setBilling(billing);
        }
        if (target.getBilling() == null && source.getBilling() != null) {
            LOG.info("Setting default values for billing");
            Billing billing = new Billing();
            Country billingCountry = null;
            if (StringUtils.isNotBlank(source.getBilling().getCountry())) {
                billingCountry = countries.get(source.getBilling().getCountry());
                if (billingCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceBilling.getCountry());
                }
                billing.setCountry(billingCountry);
                target.setBilling(billing);
            }
        }
        Address sourceShipping = source.getDelivery();
        if (sourceShipping != null) {
            Delivery delivery = new Delivery();
            delivery.setAddress(sourceShipping.getAddress());
            delivery.setCity(sourceShipping.getCity());
            delivery.setCompany(sourceShipping.getCompany());
            delivery.setFirstName(sourceShipping.getFirstName());
            delivery.setLastName(sourceShipping.getLastName());
            delivery.setTelephone(sourceShipping.getPhone());
            delivery.setPostalCode(sourceShipping.getPostalCode());
            delivery.setState(sourceShipping.getStateProvince());
            Country deliveryCountry = null;
            if (!StringUtils.isBlank(sourceShipping.getCountry())) {
                deliveryCountry = countries.get(sourceShipping.getCountry());
                if (deliveryCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceShipping.getCountry());
                }
                delivery.setCountry(deliveryCountry);
            }
            if (deliveryCountry != null && !StringUtils.isBlank(sourceShipping.getZone())) {
                Zone zone = zoneService.getByCode(sourceShipping.getZone());
                if (zone == null) {
                    throw new ConversionException("Unsuported zone code " + sourceShipping.getZone());
                }
                Zone zoneDescription = zones.get(zone.getCode());
                delivery.setZone(zoneDescription);
            }
            target.setDelivery(delivery);
        }
        if (source.getRating() != null && source.getRating().doubleValue() > 0) {
            target.setCustomerReviewAvg(new BigDecimal(source.getRating().doubleValue()));
        }
        if (source.getRatingCount() > 0) {
            target.setCustomerReviewCount(source.getRatingCount());
        }
        if (target.getDelivery() == null && source.getDelivery() != null) {
            LOG.info("Setting default value for delivery");
            Delivery delivery = new Delivery();
            Country deliveryCountry = null;
            if (StringUtils.isNotBlank(source.getDelivery().getCountry())) {
                deliveryCountry = countries.get(source.getDelivery().getCountry());
                if (deliveryCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceShipping.getCountry());
                }
                delivery.setCountry(deliveryCountry);
                target.setDelivery(delivery);
            }
        }
        if (source.getAttributes() != null) {
            for (PersistableCustomerAttribute attr : source.getAttributes()) {
                CustomerOption customerOption = customerOptionService.getById(attr.getCustomerOption().getId());
                if (customerOption == null) {
                    throw new ConversionException("Customer option id " + attr.getCustomerOption().getId() + " does not exist");
                }
                CustomerOptionValue customerOptionValue = customerOptionValueService.getById(attr.getCustomerOptionValue().getId());
                if (customerOptionValue == null) {
                    throw new ConversionException("Customer option value id " + attr.getCustomerOptionValue().getId() + " does not exist");
                }
                if (customerOption.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Invalid customer option id ");
                }
                if (customerOptionValue.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Invalid customer option value id ");
                }
                CustomerAttribute attribute = new CustomerAttribute();
                attribute.setCustomer(target);
                attribute.setCustomerOption(customerOption);
                attribute.setCustomerOptionValue(customerOptionValue);
                attribute.setTextValue(attr.getTextValue());
                target.getAttributes().add(attribute);
            }
        }
        if (target.getDefaultLanguage() == null) {
            Language lang = source.getLanguage() == null ? language : languageService.getByCode(source.getLanguage());
            target.setDefaultLanguage(lang);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Address(com.salesmanager.shop.model.customer.address.Address) Zone(com.salesmanager.core.model.reference.zone.Zone) BigDecimal(java.math.BigDecimal) ConversionException(com.salesmanager.core.business.exception.ConversionException) CustomerOption(com.salesmanager.core.model.customer.attribute.CustomerOption) CustomerOptionValue(com.salesmanager.core.model.customer.attribute.CustomerOptionValue) Language(com.salesmanager.core.model.reference.language.Language) PersistableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.PersistableCustomerAttribute) CustomerAttribute(com.salesmanager.core.model.customer.attribute.CustomerAttribute) Billing(com.salesmanager.core.model.common.Billing) Country(com.salesmanager.core.model.reference.country.Country) Delivery(com.salesmanager.core.model.common.Delivery) PersistableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.PersistableCustomerAttribute)

Example 7 with Delivery

use of com.salesmanager.core.model.common.Delivery in project shopizer by shopizer-ecommerce.

the class PersistableCustomerShippingAddressPopulator method populate.

@Override
public Customer populate(Address source, Customer target, MerchantStore store, Language language) throws ConversionException {
    if (target.getDelivery() == null) {
        Delivery delivery = new Delivery();
        delivery.setFirstName(source.getFirstName());
        delivery.setLastName(source.getLastName());
        if (StringUtils.isNotBlank(source.getAddress())) {
            delivery.setAddress(source.getAddress());
        }
        if (StringUtils.isNotBlank(source.getCity())) {
            delivery.setCity(source.getCity());
        }
        if (StringUtils.isNotBlank(source.getCompany())) {
            delivery.setCompany(source.getCompany());
        }
        if (StringUtils.isNotBlank(source.getPhone())) {
            delivery.setTelephone(source.getPhone());
        }
        if (StringUtils.isNotBlank(source.getPostalCode())) {
            delivery.setPostalCode(source.getPostalCode());
        }
        if (StringUtils.isNotBlank(source.getStateProvince())) {
            delivery.setPostalCode(source.getStateProvince());
        }
        target.setDelivery(delivery);
    } else {
        target.getDelivery().setFirstName(source.getFirstName());
        target.getDelivery().setLastName(source.getLastName());
        if (StringUtils.isNotBlank(source.getAddress())) {
            target.getDelivery().setAddress(source.getAddress());
        }
        if (StringUtils.isNotBlank(source.getCity())) {
            target.getDelivery().setCity(source.getCity());
        }
        if (StringUtils.isNotBlank(source.getCompany())) {
            target.getDelivery().setCompany(source.getCompany());
        }
        if (StringUtils.isNotBlank(source.getPhone())) {
            target.getDelivery().setTelephone(source.getPhone());
        }
        if (StringUtils.isNotBlank(source.getPostalCode())) {
            target.getDelivery().setPostalCode(source.getPostalCode());
        }
        if (StringUtils.isNotBlank(source.getStateProvince())) {
            target.getDelivery().setPostalCode(source.getStateProvince());
        }
    }
    return target;
}
Also used : Delivery(com.salesmanager.core.model.common.Delivery)

Example 8 with Delivery

use of com.salesmanager.core.model.common.Delivery in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method getShippingQuote.

@Override
public ShippingQuote getShippingQuote(Customer customer, ShoppingCart cart, MerchantStore store, Language language) throws Exception {
    Validate.notNull(customer, "Customer cannot be null");
    Validate.notNull(cart, "cart cannot be null");
    // create shipping products
    List<ShippingProduct> shippingProducts = shoppingCartService.createShippingProduct(cart);
    if (CollectionUtils.isEmpty(shippingProducts)) {
        // products are virtual
        return null;
    }
    Delivery delivery = new Delivery();
    Billing billing = new Billing();
    // default value
    billing.setCountry(store.getCountry());
    // adjust shipping and billing
    if (customer.getDelivery() == null || StringUtils.isBlank(customer.getDelivery().getPostalCode())) {
        if (customer.getBilling() != null) {
            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 9 with Delivery

use of com.salesmanager.core.model.common.Delivery in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method getShippingQuote.

@Override
public ShippingQuote getShippingQuote(PersistableCustomer persistableCustomer, ShoppingCart cart, ShopOrder 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;
    }
    Customer customer = customerFacade.getCustomerModel(persistableCustomer, store, language);
    Delivery delivery = new Delivery();
    // adjust shipping and billing
    if (order.isShipToBillingAdress() && !order.isShipToDeliveryAddress()) {
        Billing billing = customer.getBilling();
        String postalCode = billing.getPostalCode();
        postalCode = validatePostalCode(postalCode);
        delivery.setAddress(billing.getAddress());
        delivery.setCompany(billing.getCompany());
        delivery.setCity(billing.getCity());
        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) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) Billing(com.salesmanager.core.model.common.Billing) ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) Delivery(com.salesmanager.core.model.common.Delivery)

Example 10 with Delivery

use of com.salesmanager.core.model.common.Delivery in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method initEmptyCustomer.

@Override
public Customer initEmptyCustomer(MerchantStore store) {
    Customer customer = new Customer();
    Billing billing = new Billing();
    billing.setCountry(store.getCountry());
    billing.setZone(store.getZone());
    billing.setState(store.getStorestateprovince());
    /**
     * empty postal code for initial quote *
     */
    // billing.setPostalCode(store.getStorepostalcode());
    customer.setBilling(billing);
    Delivery delivery = new Delivery();
    delivery.setCountry(store.getCountry());
    delivery.setZone(store.getZone());
    delivery.setState(store.getStorestateprovince());
    /**
     * empty postal code for initial quote *
     */
    // delivery.setPostalCode(store.getStorepostalcode());
    customer.setDelivery(delivery);
    return customer;
}
Also used : ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) Billing(com.salesmanager.core.model.common.Billing) Delivery(com.salesmanager.core.model.common.Delivery)

Aggregations

Delivery (com.salesmanager.core.model.common.Delivery)17 Billing (com.salesmanager.core.model.common.Billing)10 Country (com.salesmanager.core.model.reference.country.Country)10 ShippingQuote (com.salesmanager.core.model.shipping.ShippingQuote)9 Customer (com.salesmanager.core.model.customer.Customer)7 Zone (com.salesmanager.core.model.reference.zone.Zone)7 BigDecimal (java.math.BigDecimal)7 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)5 Language (com.salesmanager.core.model.reference.language.Language)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)4 PackageDetails (com.salesmanager.core.model.shipping.PackageDetails)3 ShippingConfiguration (com.salesmanager.core.model.shipping.ShippingConfiguration)3 ShippingOption (com.salesmanager.core.model.shipping.ShippingOption)3 ShippingProduct (com.salesmanager.core.model.shipping.ShippingProduct)3 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)3 ConversionException (com.salesmanager.core.business.exception.ConversionException)2 DataUtils (com.salesmanager.core.business.utils.DataUtils)2 Product (com.salesmanager.core.model.catalog.product.Product)2 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)2