use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class ResourcePurgeServiceImpl method purgeCustomers.
@Override
public void purgeCustomers(final Map<String, String> config) {
if (LOG.isDebugEnabled()) {
LOG.debug("Purging customers");
}
if (MapUtils.isEmpty(config)) {
throw new IllegalArgumentException("Cannot purge customers since there was no configuration provided. " + "In the absence of config params, all customers would be candidates for deletion.");
}
CustomerPurgeParams purgeParams = new CustomerPurgeParams(config).invoke();
int processedCount = 0, batchCount = 0;
synchronized (customerPurgeErrors) {
Set<Long> failedCustomerIds = getCustomersInErrorToIgnore(purgeParams);
batchCount = getCustomersToPurgeLength(purgeParams, new ArrayList<Long>(failedCustomerIds)).intValue();
List<Customer> customers = getCustomersToPurge(purgeParams, 0, batchCount, new ArrayList<Long>(failedCustomerIds));
for (Customer customer : customers) {
TransactionStatus status = TransactionUtils.createTransaction("Customer Purge", TransactionDefinition.PROPAGATION_REQUIRED, transactionManager, false);
try {
deleteCustomer(customer);
TransactionUtils.finalizeTransaction(status, transactionManager, false);
processedCount++;
} catch (Exception e) {
if (!status.isCompleted()) {
TransactionUtils.finalizeTransaction(status, transactionManager, true);
}
LOG.error(String.format("Not able to purge Customer ID: %d", customer.getId()), e);
customerPurgeErrors.add(customer.getId());
}
}
}
LOG.info(String.format("Customer purge batch processed. Purged %d from total batch size of %d, %d failures cached", processedCount, batchCount, customerPurgeErrors.size()));
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafShippingInfoController method saveSingleShip.
/**
* Processes the request to save a single shipping address. Allows modules to add module specific shipping logic.
*
* Note: the default Broadleaf implementation creates an order
* with a single fulfillment group. In the case of shipping to multiple addresses,
* the multiship methods should be used.
*
* @param request
* @param response
* @param model
* @param shippingForm
* @return the return path
* @throws org.broadleafcommerce.common.exception.ServiceException
*/
public String saveSingleShip(HttpServletRequest request, HttpServletResponse response, Model model, ShippingInfoForm shippingForm, BindingResult result) throws PricingException, ServiceException {
Order cart = CartState.getCart();
if (shippingForm.shouldUseBillingAddress()) {
copyBillingAddressToShippingAddress(cart, shippingForm);
}
addressService.populateAddressISOCountrySub(shippingForm.getAddress());
shippingInfoFormValidator.validate(shippingForm, result);
if (result.hasErrors()) {
return getCheckoutView();
}
if ((shippingForm.getAddress().getPhonePrimary() != null) && (StringUtils.isEmpty(shippingForm.getAddress().getPhonePrimary().getPhoneNumber()))) {
shippingForm.getAddress().setPhonePrimary(null);
}
if ((shippingForm.getAddress().getPhoneSecondary() != null) && (StringUtils.isEmpty(shippingForm.getAddress().getPhoneSecondary().getPhoneNumber()))) {
shippingForm.getAddress().setPhoneSecondary(null);
}
if ((shippingForm.getAddress().getPhoneFax() != null) && (StringUtils.isEmpty(shippingForm.getAddress().getPhoneFax().getPhoneNumber()))) {
shippingForm.getAddress().setPhoneFax(null);
}
Customer customer = CustomerState.getCustomer();
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());
}
FulfillmentGroup shippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart);
if (shippableFulfillmentGroup != null) {
shippableFulfillmentGroup.setAddress(shippingForm.getAddress());
shippableFulfillmentGroup.setPersonalMessage(shippingForm.getPersonalMessage());
shippableFulfillmentGroup.setDeliveryInstruction(shippingForm.getDeliveryMessage());
FulfillmentOption fulfillmentOption = fulfillmentOptionService.readFulfillmentOptionById(shippingForm.getFulfillmentOptionId());
shippableFulfillmentGroup.setFulfillmentOption(fulfillmentOption);
cart = orderService.save(cart, true);
}
// Add module specific logic
checkoutControllerExtensionManager.getProxy().performAdditionalShippingAction();
if (isAjaxRequest(request)) {
// Add module specific model variables
checkoutControllerExtensionManager.getProxy().addAdditionalModelVariables(model);
return getCheckoutView();
} else {
return getCheckoutPageRedirect();
}
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafShippingInfoController method showMultiship.
/**
* 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();
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafManageCustomerPaymentsController method addCustomerPayment.
public String addCustomerPayment(HttpServletRequest request, Model model, PaymentInfoForm paymentInfoForm, BindingResult bindingResult) {
Customer customer = CustomerState.getCustomer();
addressService.populateAddressISOCountrySub(paymentInfoForm.getAddress());
paymentInfoFormValidator.validate(paymentInfoForm, bindingResult);
if (!bindingResult.hasErrors()) {
if ((paymentInfoForm.getAddress().getPhonePrimary() != null) && (StringUtils.isEmpty(paymentInfoForm.getAddress().getPhonePrimary().getPhoneNumber()))) {
paymentInfoForm.getAddress().setPhonePrimary(null);
}
if ((paymentInfoForm.getAddress().getPhoneSecondary() != null) && (StringUtils.isEmpty(paymentInfoForm.getAddress().getPhoneSecondary().getPhoneNumber()))) {
paymentInfoForm.getAddress().setPhoneSecondary(null);
}
if ((paymentInfoForm.getAddress().getPhoneFax() != null) && (StringUtils.isEmpty(paymentInfoForm.getAddress().getPhoneFax().getPhoneNumber()))) {
paymentInfoForm.getAddress().setPhoneFax(null);
}
savedPaymentService.addSavedPayment(customer, paymentInfoForm);
return getCustomerPaymentRedirect();
}
return getCustomerPaymentView();
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafSocialRegisterController method processRegister.
// Calls ProviderSignInUtils.handlePostSignUp() after a successful registration
public String processRegister(RegisterCustomerForm registerCustomerForm, BindingResult errors, HttpServletRequest request, HttpServletResponse response, Model model) throws ServiceException, PricingException {
if (isUseEmailForLogin()) {
Customer customer = registerCustomerForm.getCustomer();
customer.setUsername(customer.getEmailAddress());
}
registerCustomerValidator.validate(registerCustomerForm, errors, isUseEmailForLogin());
if (!errors.hasErrors()) {
Customer newCustomer = customerService.registerCustomer(registerCustomerForm.getCustomer(), registerCustomerForm.getPassword(), registerCustomerForm.getPasswordConfirm());
assert (newCustomer != null);
ProviderSignInUtils.handlePostSignUp(newCustomer.getUsername(), new ServletWebRequest(request));
// The next line needs to use the customer from the input form and not the customer returned after registration
// so that we still have the unencoded password for use by the authentication mechanism.
loginService.loginCustomer(registerCustomerForm.getCustomer());
// Need to ensure that the Cart on CartState is owned by the newly registered customer.
Order cart = CartState.getCart();
if (cart != null && !(cart instanceof NullOrderImpl) && cart.getEmailAddress() == null) {
cart.setEmailAddress(newCustomer.getEmailAddress());
orderService.save(cart, false);
}
String redirectUrl = registerCustomerForm.getRedirectUrl();
if (StringUtils.isNotBlank(redirectUrl) && redirectUrl.contains(":")) {
redirectUrl = null;
}
return StringUtils.isBlank(redirectUrl) ? getRegisterSuccessView() : "redirect:" + redirectUrl;
} else {
return getRegisterView();
}
}
Aggregations