use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.
the class CustomerAddressDataProvider method createCustomerAddress.
@DataProvider(name = "setupCustomerAddress")
public static Object[][] createCustomerAddress() {
CustomerAddress ca1 = new CustomerAddressImpl();
Address address1 = new AddressImpl();
address1.setAddressLine1("1234 Merit Drive");
address1.setCity("Bozeman");
address1.setPostalCode("75251");
ca1.setAddress(address1);
ca1.setAddressName("address4");
CustomerAddress ca2 = new CustomerAddressImpl();
Address address2 = new AddressImpl();
address2.setAddressLine1("12 Testing Drive");
address2.setCity("Portland");
address2.setPostalCode("75251");
ca2.setAddress(address2);
ca2.setAddressName("address5");
return new Object[][] { new Object[] { ca1 }, new Object[] { ca2 } };
}
use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafManageCustomerAddressesController method addCustomerAddress.
public String addCustomerAddress(HttpServletRequest request, Model model, CustomerAddressForm form, BindingResult result, RedirectAttributes redirectAttributes) throws ServiceException {
addressService.populateAddressISOCountrySub(form.getAddress());
customerAddressValidator.validate(form, result);
if (result.hasErrors()) {
return getCustomerAddressesView();
}
removeUnusedPhones(form);
Address address = addressService.saveAddress(form.getAddress());
CustomerAddress customerAddress = customerAddressService.create();
customerAddress.setAddress(address);
customerAddress.setAddressName(form.getAddressName());
customerAddress.setCustomer(CustomerState.getCustomer());
customerAddress = customerAddressService.saveCustomerAddress(customerAddress);
if (form.getAddress().isDefault()) {
customerAddressService.makeCustomerAddressDefault(customerAddress.getId(), customerAddress.getCustomer().getId());
}
form.setCustomerAddressId(customerAddress.getId());
if (!isAjaxRequest(request)) {
List<CustomerAddress> addresses = customerAddressService.readActiveCustomerAddressesByCustomerId(CustomerState.getCustomer().getId());
model.addAttribute("addresses", addresses);
}
redirectAttributes.addFlashAttribute("successMessage", getAddressAddedMessage());
return getCustomerAddressesRedirect();
}
use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafManageCustomerAddressesController method removeCustomerAddress.
public String removeCustomerAddress(HttpServletRequest request, Model model, Long customerAddressId, RedirectAttributes redirectAttributes) {
try {
CustomerAddress customerAddress = customerAddressService.readCustomerAddressById(customerAddressId);
// we don't care if the address is null on a remove
if (customerAddress != null) {
validateCustomerOwnedData(customerAddress);
customerAddressService.deleteCustomerAddressById(customerAddressId);
}
redirectAttributes.addFlashAttribute("successMessage", getAddressRemovedMessage());
} catch (DataIntegrityViolationException e) {
// This likely occurred because there is an order or cart in the system that is currently utilizing this
// address. Therefore, we're not able to remove it as it breaks a foreign key constraint
redirectAttributes.addFlashAttribute("errorMessage", getAddressRemovedErrorMessage());
}
return getCustomerAddressesRedirect();
}
use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafShippingInfoController method saveMultishipAddAddress.
/**
* Processes the requested add address from the multiship process.
* This method will create a CustomerAddress based on the requested Address
* and associate it with the current Customer in session.
*
* @param request
* @param response
* @param model
* @param addressForm
* @return the return path to the multiship page
* @throws ServiceException
*/
public String saveMultishipAddAddress(HttpServletRequest request, HttpServletResponse response, Model model, ShippingInfoForm addressForm, BindingResult result) throws ServiceException {
addressService.populateAddressISOCountrySub(addressForm.getAddress());
multishipAddAddressFormValidator.validate(addressForm, result);
if (result.hasErrors()) {
return showMultishipAddAddress(request, response, model);
}
removeUnusedPhones(addressForm);
CustomerAddress customerAddress = customerAddressService.create();
customerAddress.setAddressName(addressForm.getAddressName());
customerAddress.setAddress(addressForm.getAddress());
customerAddress.setCustomer(CustomerState.getCustomer());
customerAddressService.saveCustomerAddress(customerAddress);
// append current time to redirect to fix a problem with ajax caching in IE
return getMultishipAddAddressSuccessView() + "?_=" + System.currentTimeMillis();
}
use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.
the class CustomerCustomPersistenceHandler method remove.
@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
Long customerId = Long.parseLong(entity.findProperty("id").getValue());
Customer customer = customerService.readCustomerById(customerId);
if (Status.class.isAssignableFrom(customer.getClass())) {
((Status) customer).setArchived('Y');
// If the customer has a conditional weave on ArchiveStatus, nothing triggers the delete so other
// normally-cascaded deletes don't happen (like CustomerAddress)
List<CustomerAddress> addressList = customer.getCustomerAddresses();
for (CustomerAddress address : addressList) {
address.setArchived('Y');
}
customer = customerService.saveCustomer(customer);
return;
}
// Remove the customer roles for the customer since it's not cascaded
roleDao.removeCustomerRolesByCustomerId(customerId);
helper.getCompatibleModule(OperationType.BASIC).remove(persistencePackage);
} catch (Exception e) {
LOG.error("Unable to execute persistence activity", e);
throw new ServiceException("Unable to remove entity for " + entity.getType()[0], e);
}
}
Aggregations