Search in sources :

Example 96 with Customer

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

the class CartStateRequestProcessor method mergeCart.

/**
 * Looks up the anonymous customer and merges that cart with the cart from the given logged in <b>customer</b>. This
 * will also remove the customer from session after it has finished since it is no longer needed
 */
public Order mergeCart(Customer customer, WebRequest request) {
    Customer anonymousCustomer = customerStateRequestProcessor.getAnonymousCustomer(request);
    MergeCartResponse mergeCartResponse;
    try {
        Order cart = orderService.findCartForCustomer(anonymousCustomer);
        mergeCartResponse = mergeCartService.mergeCart(customer, cart);
    } catch (PricingException e) {
        throw new RuntimeException(e);
    } catch (RemoveFromCartException e) {
        throw new RuntimeException(e);
    }
    if (BLCRequestUtils.isOKtoUseSession(request)) {
        // The anonymous customer from session is no longer needed; it can be safely removed
        request.removeAttribute(CustomerStateRequestProcessor.getAnonymousCustomerSessionAttributeName(), WebRequest.SCOPE_GLOBAL_SESSION);
        request.removeAttribute(CustomerStateRequestProcessor.getAnonymousCustomerIdSessionAttributeName(), WebRequest.SCOPE_GLOBAL_SESSION);
        request.setAttribute(mergeCartResponseKey, mergeCartResponse, WebRequest.SCOPE_GLOBAL_SESSION);
    }
    return mergeCartResponse.getOrder();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) PricingException(org.broadleafcommerce.core.pricing.service.exception.PricingException) Customer(org.broadleafcommerce.profile.core.domain.Customer) MergeCartResponse(org.broadleafcommerce.core.order.service.call.MergeCartResponse) RemoveFromCartException(org.broadleafcommerce.core.order.service.exception.RemoveFromCartException)

Example 97 with Customer

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

the class MergeCartProcessorImpl method execute.

@Override
public void execute(WebRequest request, Authentication authResult) {
    Customer loggedInCustomer = customerService.readCustomerByUsername(authResult.getName());
    Customer anonymousCustomer = customerStateRequestProcessor.getAnonymousCustomer(request);
    Order cart = null;
    if (anonymousCustomer != null) {
        cart = orderService.findCartForCustomer(anonymousCustomer);
    }
    MergeCartResponse mergeCartResponse;
    try {
        mergeCartResponse = mergeCartService.mergeCart(loggedInCustomer, cart);
    } catch (PricingException e) {
        throw new RuntimeException(e);
    } catch (RemoveFromCartException e) {
        throw new RuntimeException(e);
    }
    if (BLCRequestUtils.isOKtoUseSession(request)) {
        request.setAttribute(mergeCartResponseKey, mergeCartResponse, WebRequest.SCOPE_GLOBAL_SESSION);
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) PricingException(org.broadleafcommerce.core.pricing.service.exception.PricingException) Customer(org.broadleafcommerce.profile.core.domain.Customer) MergeCartResponse(org.broadleafcommerce.core.order.service.call.MergeCartResponse) RemoveFromCartException(org.broadleafcommerce.core.order.service.exception.RemoveFromCartException)

Example 98 with Customer

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

the class OrderStateAOP method processOrderRetrieval.

public Object processOrderRetrieval(ProceedingJoinPoint call) throws Throwable {
    Object returnValue;
    /*
         * we retrieve the OrderState instance directly from the application
         * context, as this bean has a request scope.
         */
    OrderState orderState = (OrderState) applicationContext.getBean("blOrderState");
    Customer customer = (Customer) call.getArgs()[0];
    Order order = orderState.getOrder(customer);
    if (order != null) {
        returnValue = order;
    } else {
        returnValue = call.proceed();
        returnValue = orderState.setOrder(customer, (Order) returnValue);
    }
    return returnValue;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer)

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