Search in sources :

Example 86 with Customer

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

Example 87 with Customer

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

Example 88 with Customer

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

Example 89 with Customer

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

Example 90 with Customer

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();
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl)

Aggregations

Customer (org.broadleafcommerce.profile.core.domain.Customer)98 Order (org.broadleafcommerce.core.order.domain.Order)41 Transactional (org.springframework.transaction.annotation.Transactional)34 Test (org.testng.annotations.Test)33 Address (org.broadleafcommerce.profile.core.domain.Address)14 Rollback (org.springframework.test.annotation.Rollback)11 HashMap (java.util.HashMap)9 CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)9 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)8 MergeCartResponse (org.broadleafcommerce.core.order.service.call.MergeCartResponse)6 ArrayList (java.util.ArrayList)5 Money (org.broadleafcommerce.common.money.Money)5 Category (org.broadleafcommerce.core.catalog.domain.Category)5 Product (org.broadleafcommerce.core.catalog.domain.Product)5 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)5 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)5 CustomerImpl (org.broadleafcommerce.profile.core.domain.CustomerImpl)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)3