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);
}
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);
}
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;
}
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;
}
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();
}
}
Aggregations