Search in sources :

Example 6 with CustomerAddress

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 } };
}
Also used : CustomerAddressImpl(org.broadleafcommerce.profile.core.domain.CustomerAddressImpl) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Address(org.broadleafcommerce.profile.core.domain.Address) CustomerAddressImpl(org.broadleafcommerce.profile.core.domain.CustomerAddressImpl) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) DataProvider(org.testng.annotations.DataProvider)

Example 7 with CustomerAddress

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();
}
Also used : Address(org.broadleafcommerce.profile.core.domain.Address) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 8 with CustomerAddress

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();
}
Also used : CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 9 with CustomerAddress

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();
}
Also used : CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 10 with CustomerAddress

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);
    }
}
Also used : Status(org.broadleafcommerce.common.persistence.Status) Entity(org.broadleafcommerce.openadmin.dto.Entity) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Customer(org.broadleafcommerce.profile.core.domain.Customer) ServiceException(org.broadleafcommerce.common.exception.ServiceException) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Aggregations

CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)19 Customer (org.broadleafcommerce.profile.core.domain.Customer)8 Address (org.broadleafcommerce.profile.core.domain.Address)7 Transactional (org.springframework.transaction.annotation.Transactional)5 CustomerAddressImpl (org.broadleafcommerce.profile.core.domain.CustomerAddressImpl)4 Test (org.testng.annotations.Test)4 Order (org.broadleafcommerce.core.order.domain.Order)3 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)3 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)2 FulfillmentOption (org.broadleafcommerce.core.order.domain.FulfillmentOption)2 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)2 Query (javax.persistence.Query)1 TypedQuery (javax.persistence.TypedQuery)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1 Status (org.broadleafcommerce.common.persistence.Status)1 OrderPayment (org.broadleafcommerce.core.payment.domain.OrderPayment)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1