Search in sources :

Example 11 with CustomerAddress

use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.

the class CustomerAddressServiceImpl method saveCustomerAddress.

@Override
@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
public CustomerAddress saveCustomerAddress(CustomerAddress customerAddress) {
    // if parameter address is set as default, unset all other default addresses
    List<CustomerAddress> activeCustomerAddresses = readActiveCustomerAddressesByCustomerId(customerAddress.getCustomer().getId());
    if (activeCustomerAddresses != null && activeCustomerAddresses.isEmpty()) {
        customerAddress.getAddress().setDefault(true);
    } else {
        if (customerAddress.getAddress().isDefault()) {
            for (CustomerAddress activeCustomerAddress : activeCustomerAddresses) {
                if (!activeCustomerAddress.getId().equals(customerAddress.getId()) && activeCustomerAddress.getAddress().isDefault()) {
                    activeCustomerAddress.getAddress().setDefault(false);
                    customerAddressDao.save(activeCustomerAddress);
                }
            }
        }
    }
    return customerAddressDao.save(customerAddress);
}
Also used : CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with CustomerAddress

use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.

the class CustomerAddressDaoImpl method findDefaultCustomerAddress.

@SuppressWarnings("unchecked")
public CustomerAddress findDefaultCustomerAddress(Long customerId) {
    Query query = em.createNamedQuery("BC_FIND_DEFAULT_ADDRESS_BY_CUSTOMER_ID");
    query.setParameter("customerId", customerId);
    List<CustomerAddress> customerAddresses = query.getResultList();
    return customerAddresses.isEmpty() ? null : customerAddresses.get(0);
}
Also used : CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 13 with CustomerAddress

use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.

the class PaymentInfoServiceTest method createTestPayment.

@Test(groups = { "testCreatePaymentInfo" }, dependsOnGroups = { "createPaymentInfo" })
@Transactional
public void createTestPayment() {
    userName = "customer1";
    OrderPayment paymentInfo = paymentInfoService.create();
    Customer customer = customerService.readCustomerByUsername(userName);
    List<CustomerAddress> addresses = customerAddressDao.readActiveCustomerAddressesByCustomerId(customer.getId());
    Address address = null;
    if (!addresses.isEmpty())
        address = addresses.get(0).getAddress();
    Order salesOrder = orderService.findCartForCustomer(customer);
    paymentInfo.setBillingAddress(address);
    paymentInfo.setOrder(salesOrder);
    paymentInfo.setType(PaymentType.CREDIT_CARD);
    assert paymentInfo != null;
    paymentInfo = paymentInfoService.save(paymentInfo);
    assert paymentInfo.getId() != null;
    Long paymentInfoId = paymentInfo.getId();
    paymentInfoService.delete(paymentInfo);
    paymentInfo = paymentInfoService.readPaymentById(paymentInfoId);
    assert paymentInfo == null;
}
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) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with CustomerAddress

use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.

the class PaymentInfoServiceTest method createPayment.

@Test(groups = { "createPaymentInfo" }, dataProvider = "basicPaymentInfo", dataProviderClass = PaymentInfoDataProvider.class, dependsOnGroups = { "readCustomer", "createOrder" })
@Rollback(false)
@Transactional
public void createPayment(OrderPayment payment) {
    userName = "customer1";
    Customer customer = customerService.readCustomerByUsername(userName);
    List<CustomerAddress> addresses = customerAddressDao.readActiveCustomerAddressesByCustomerId(customer.getId());
    Address address = null;
    if (!addresses.isEmpty())
        address = addresses.get(0).getAddress();
    Order salesOrder = orderService.createNewCartForCustomer(customer);
    payment.setBillingAddress(address);
    payment.setOrder(salesOrder);
    payment.setType(PaymentType.CREDIT_CARD);
    assert payment.getId() == null;
    payment = paymentInfoService.save(payment);
    assert payment.getId() != null;
    this.paymentInfo = payment;
}
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) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Test(org.testng.annotations.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with CustomerAddress

use of org.broadleafcommerce.profile.core.domain.CustomerAddress 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)

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