/** * Creates a country, state, and customer with the supplied customerAddress * @param customerAddress * @return customer created */ public CustomerAddress createCustomerWithAddress(CustomerAddress customerAddress) { createCountry(); createState(); Customer customer = createCustomer(); customer.setUsername(String.valueOf(customer.getId())); customerAddress.setCustomer(customer); return saveCustomerAddress(customerAddress); }
@Override public <G extends CustomerAddress> CreateResponse<G> createOrRetrieveCopyInstance(MultiTenantCopyContext context) throws CloneNotSupportedException { CreateResponse<G> createResponse = context.createOrRetrieveCopyInstance(this); if (createResponse.isAlreadyPopulated()) { return createResponse; } CustomerAddress cloned = createResponse.getClone(); cloned.setAddressName(addressName); // dont clone cloned.setCustomer(customer); cloned.setArchived(getArchived()); cloned.setAddress(address.createOrRetrieveCopyInstance(context).getClone()); return createResponse; } }
/** * 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(); }
for (CustomerAddress entry : customerAddresses) { CustomerAddress clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone(); clonedEntry.setCustomer(cloned); cloned.getCustomerAddresses().add(clonedEntry);
/** * This method only exists because so many other tests depend on it, but should be removed once tests are more isolated * @param customerAddress */ @Deprecated @Test(groups = "createCustomerAddress", dataProvider = "setupCustomerAddress", dataProviderClass = CustomerAddressDataProvider.class, dependsOnGroups = {"readCustomer", "createCountry", "createState"}) @Transactional @Rollback(false) public void createCustomerAddress(CustomerAddress customerAddress) { userName = "customer1"; Customer customer = customerService.readCustomerByUsername(userName); assert customerAddress.getId() == null; customerAddress.setCustomer(customer); State state = stateService.findStateByAbbreviation("KY"); customerAddress.getAddress().setState(state); Country country = countryService.findCountryByAbbreviation("US"); customerAddress.getAddress().setCountry(country); customerAddress.getAddress().setIsoCountrySubdivision("US-KY"); ISOCountry isoCountry = isoService.findISOCountryByAlpha2Code("US"); customerAddress.getAddress().setIsoCountryAlpha2(isoCountry); customerAddress = customerAddressService.saveCustomerAddress(customerAddress); assert customer.equals(customerAddress.getCustomer()); userId = customerAddress.getCustomer().getId(); }
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(); }
@Test(groups = "testCustomerAddress") @Transactional public void createNewDefaultAddress() { Customer customer = createCustomerWithAddresses(); CustomerAddress ca = new CustomerAddressImpl(); Address address = new AddressImpl(); address.setAddressLine1("123 Main"); address.setCity("Dallas"); address.setPostalCode("75201"); address.setDefault(true); ca.setAddress(address); ca.setCustomer(customer); ca.setAddressName("address3"); CustomerAddress savedAddress = saveCustomerAddress(ca); List<CustomerAddress> customerAddressList = customerAddressService.readActiveCustomerAddressesByCustomerId(customer.getId()); for (CustomerAddress customerAddress : customerAddressList) { if (customerAddress.getId().equals(savedAddress.getId())) { assert customerAddress.getAddress().isDefault(); } else { assert !customerAddress.getAddress().isDefault(); } } }
customerAddress.setAddress(address); customerAddress.setAddressName(shippingForm.getAddressName()); customerAddress.setCustomer(customer); customerAddress = customerAddressService.saveCustomerAddress(customerAddress); customerAddressService.makeCustomerAddressDefault(customerAddress.getId(), customer.getId());
ca2.setAddress(address2); ca2.setAddressName("address2"); ca2.setCustomer(customer); CustomerAddress addResult = saveCustomerAddress(ca2); assert addResult != null;
Customer cust = new Customer(); CustomerAddress custAddr = new CustomerAddress(); cust.setCustomerAddress( custAddr ); custAddr.setCustomer( cust );
customerAddress.setAddressName(entry.getKey()); customerAddress.setAddress(addressConverter.createEntity(entry.getValue())); customerAddress.setCustomer(customer); return customerAddress; })