public List<CustomerAddress> getCustomerAddresses() { Customer customer = CustomerState.getCustomer(); return customerAddressService.readActiveCustomerAddressesByCustomerId(customer.getId()); }
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(); }
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(); }
if (!customer.isAnonymous() && shippingForm.isSaveAsDefault()) { Address address = addressService.saveAddress(shippingForm.getAddress()); CustomerAddress customerAddress = customerAddressService.create(); customerAddress.setAddress(address); customerAddress.setAddressName(shippingForm.getAddressName()); customerAddress.setCustomer(customer); customerAddress = customerAddressService.saveCustomerAddress(customerAddress); customerAddressService.makeCustomerAddressDefault(customerAddress.getId(), customer.getId());
/** * 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(); }
CustomerAddress customerAddress = customerAddressService.readCustomerAddressById(customerAddressId); if (customerAddress == null) { throw new IllegalArgumentException("Customer Address not found with the specified customerAddressId"); customerAddress = customerAddressService.saveCustomerAddress(customerAddress); if (form.getAddress().isDefault()) { customerAddressService.makeCustomerAddressDefault(customerAddress.getId(), customerAddress.getCustomer().getId());
/** * 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(); }
.map(stream -> stream .map(entry -> { CustomerAddress customerAddress = customerAddressService.create(); customerAddress.setAddressName(entry.getKey()); customerAddress.setAddress(addressConverter.createEntity(entry.getValue()));
public String viewCustomerAddress(HttpServletRequest request, Model model, Long customerAddressId) { CustomerAddress customerAddress = customerAddressService.readCustomerAddressById(customerAddressId); if (customerAddress == null) { throw new IllegalArgumentException("Customer Address not found with the specified customerAddressId"); } validateCustomerOwnedData(customerAddress); CustomerAddressForm form = new CustomerAddressForm(); form.setAddress(customerAddress.getAddress()); form.setAddressName(customerAddress.getAddressName()); form.setCustomerAddressId(customerAddress.getId()); model.addAttribute("customerAddressForm", form); return getCustomerAddressesView(); }
@Override public ShippingInfoForm prePopulateShippingInfoForm(ShippingInfoForm shippingInfoForm, Order cart) { FulfillmentGroup firstShippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart); if (firstShippableFulfillmentGroup != null) { //if the cart has already has fulfillment information if (firstShippableFulfillmentGroup.getAddress() != null) { shippingInfoForm.setAddress(firstShippableFulfillmentGroup.getAddress()); } else { //check for a default address for the customer CustomerAddress defaultAddress = customerAddressService.findDefaultCustomerAddress(CustomerState.getCustomer().getId()); if (defaultAddress != null) { shippingInfoForm.setAddress(defaultAddress.getAddress()); shippingInfoForm.setAddressName(defaultAddress.getAddressName()); } } FulfillmentOption fulfillmentOption = firstShippableFulfillmentGroup.getFulfillmentOption(); if (fulfillmentOption != null) { shippingInfoForm.setFulfillmentOption(fulfillmentOption); shippingInfoForm.setFulfillmentOptionId(fulfillmentOption.getId()); } } return shippingInfoForm; }
/** * Saves a customerAddress with state KY and country US. Requires that createCountry() and createState() have been called * @param customerAddress */ public CustomerAddress saveCustomerAddress(CustomerAddress customerAddress) { 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); return customerAddressService.saveCustomerAddress(customerAddress); }
protected List<CustomerAddress> populateCustomerAddresses() { return customerAddressService.readActiveCustomerAddressesByCustomerId(CustomerState.getCustomer().getId()); }
/** * TThis method only exists because so many other tests depend on it, but should be removed once tests are more isolated */ @Deprecated @Test(groups = "readCustomerAddress", dependsOnGroups = "createCustomerAddress") @Transactional public void readCustomerAddressByUserId() { List<CustomerAddress> customerAddressList = customerAddressService.readActiveCustomerAddressesByCustomerId(userId); for (CustomerAddress customerAddress : customerAddressList) { assert customerAddress != null; } }
/** * Renders the multiship page. This page is used by the user when shipping items * to different locations (or with different FulfillmentOptions) is desired. * * Note that the default Broadleaf implementation will require the user to input * an Address and FulfillmentOption for each quantity of each DiscreteOrderItem. * * @param request * @param response * @param model * @return the return path */ public String showMultiship(HttpServletRequest request, HttpServletResponse response, Model model) { Customer customer = CustomerState.getCustomer(); Order cart = CartState.getCart(); model.addAttribute("orderMultishipOptions", orderMultishipOptionService.getOrGenerateOrderMultishipOptions(cart)); model.addAttribute("customerAddresses", customerAddressService.readActiveCustomerAddressesByCustomerId(customer.getId())); model.addAttribute("fulfillmentOptions", fulfillmentOptionService.readAllFulfillmentOptions()); return getMultishipView(); }
@Test(groups = "testCustomerAddress") @Transactional public void readCustomerAddresses() { Customer customer = createCustomerWithAddresses(); List<CustomerAddress> customerAddressList = customerAddressService.readActiveCustomerAddressesByCustomerId(customer.getId()); for (CustomerAddress ca : customerAddressList) { assert ca != null; } }
@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(); } } }