orderHeader = new OrderHeader();
}
Customer customer = shoppingCart.getCustomer();
if (customer != null) {
OrderAddress custAddress = null;
if (orderHeader.getCustAddress() != null) {
custAddress = orderHeader.getCustAddress();
}
else {
custAddress = new OrderAddress();
custAddress.setRecCreateBy(Constants.USERNAME_SYSTEM);
custAddress.setRecCreateDatetime(new Date());
}
CustomerAddress adddress = customer.getCustAddress();
custAddress.setCustUseAddress(Constants.CUST_ADDRESS_USE_OWN);
custAddress.setCustPrefix(adddress.getCustPrefix());
custAddress.setCustFirstName(adddress.getCustFirstName());
custAddress.setCustMiddleName(adddress.getCustMiddleName());
custAddress.setCustLastName(adddress.getCustLastName());
custAddress.setCustSuffix(adddress.getCustSuffix());
custAddress.setCustAddressLine1(adddress.getCustAddressLine1());
custAddress.setCustAddressLine2(adddress.getCustAddressLine2());
custAddress.setCustCityName(adddress.getCustCityName());
custAddress.setCustStateName(adddress.getCustStateName());
custAddress.setCustStateCode(adddress.getCustStateCode());
custAddress.setCustCountryName(adddress.getCustCountryName());
custAddress.setCustCountryCode(adddress.getCustCountryCode());
custAddress.setCustStateName(adddress.getCustStateName());
custAddress.setCustZipCode(adddress.getCustZipCode());
custAddress.setCustPhoneNum(adddress.getCustPhoneNum());
custAddress.setCustFaxNum(adddress.getCustFaxNum());
custAddress.setRecUpdateBy(Constants.USERNAME_SYSTEM);
custAddress.setRecUpdateDatetime(new Date());
Country country = CountryDAO.loadByCountryCode(siteId, adddress.getCustCountryCode());
custAddress.setCountry(country);
if (adddress.getCustStateCode() != null) {
State state = StateDAO.loadByStateCode(siteId, adddress.getCustStateCode());
custAddress.setState(state);
}
em.persist(custAddress);
orderHeader.setCustAddress(custAddress);
}
CustomerAddress billingAddress = shoppingCart.getBillingAddress();
if (billingAddress != null) {
OrderAddress address = null;
if (orderHeader.getBillingAddress() != null) {
address = orderHeader.getBillingAddress();
}
else {
address = new OrderAddress();
address.setRecCreateBy(Constants.USERNAME_SYSTEM);
address.setRecCreateDatetime(new Date());
}
address.setCustUseAddress(billingAddress.getCustUseAddress());
address.setCustPrefix(billingAddress.getCustPrefix());
address.setCustFirstName(billingAddress.getCustFirstName());
address.setCustMiddleName(billingAddress.getCustMiddleName());
address.setCustLastName(billingAddress.getCustLastName());
address.setCustSuffix(billingAddress.getCustSuffix());
address.setCustAddressLine1(billingAddress.getCustAddressLine1());
address.setCustAddressLine2(billingAddress.getCustAddressLine2());
address.setCustCityName(billingAddress.getCustCityName());
address.setCustStateName(billingAddress.getCustStateName());
address.setCustStateCode(billingAddress.getCustStateCode());
address.setCustCountryName(billingAddress.getCustCountryName());
address.setCustCountryCode(billingAddress.getCustCountryCode());
address.setCustStateName(billingAddress.getCustStateName());
address.setCustZipCode(billingAddress.getCustZipCode());
address.setCustPhoneNum(billingAddress.getCustPhoneNum());
address.setCustFaxNum(billingAddress.getCustFaxNum());
address.setRecUpdateBy(Constants.USERNAME_SYSTEM);
address.setRecUpdateDatetime(new Date());
Country country = CountryDAO.loadByCountryCode(siteId, billingAddress.getCustCountryCode());
address.setCountry(country);
if (billingAddress.getCustStateCode() != null) {
State state = StateDAO.loadByStateCode(siteId, billingAddress.getCustStateCode());
address.setState(state);
}
em.persist(address);
orderHeader.setBillingAddress(address);
}
CustomerAddress shippingAddress = shoppingCart.getShippingAddress();
if (shippingAddress != null) {
OrderAddress address = null;
if (orderHeader.getShippingAddress() != null) {
address = orderHeader.getShippingAddress();
}
else {
address = new OrderAddress();
address.setRecCreateBy(Constants.USERNAME_SYSTEM);
address.setRecCreateDatetime(new Date());
}
address.setCustUseAddress(shippingAddress.getCustUseAddress());
address.setCustPrefix(shippingAddress.getCustPrefix());
address.setCustFirstName(shippingAddress.getCustFirstName());
address.setCustMiddleName(shippingAddress.getCustMiddleName());
address.setCustLastName(shippingAddress.getCustLastName());
address.setCustSuffix(shippingAddress.getCustSuffix());
address.setCustAddressLine1(shippingAddress.getCustAddressLine1());
address.setCustAddressLine2(shippingAddress.getCustAddressLine2());
address.setCustCityName(shippingAddress.getCustCityName());
address.setCustStateName(shippingAddress.getCustStateName());
address.setCustStateCode(shippingAddress.getCustStateCode());
address.setCustCountryName(shippingAddress.getCustCountryName());
address.setCustCountryCode(shippingAddress.getCustCountryCode());
address.setCustStateName(shippingAddress.getCustStateName());
address.setCustZipCode(shippingAddress.getCustZipCode());
address.setCustPhoneNum(shippingAddress.getCustPhoneNum());
address.setCustFaxNum(shippingAddress.getCustFaxNum());
address.setRecUpdateBy(Constants.USERNAME_SYSTEM);
address.setRecUpdateDatetime(new Date());
Country country = CountryDAO.loadByCountryCode(siteId, shippingAddress.getCustCountryCode());
address.setCountry(country);
if (shippingAddress.getCustStateCode() != null) {
State state = StateDAO.loadByStateCode(siteId, shippingAddress.getCustStateCode());
address.setState(state);
}
em.persist(address);
orderHeader.setShippingAddress(address);
}
if (customer != null) {