Search in sources :

Example 1 with MergeCartResponse

use of org.broadleafcommerce.core.order.service.call.MergeCartResponse in project BroadleafCommerce by BroadleafCommerce.

the class CartTest method testMergeWithNoAnonymousCart.

@Transactional
@Test(groups = { "testMergeCart" })
public void testMergeWithNoAnonymousCart() throws PricingException, RemoveFromCartException, AddToCartException {
    Order anonymousCart = null;
    Order customerCart = setUpCartWithActiveSku();
    Customer customer = customerCart.getCustomer();
    MergeCartResponse response = mergeCartService.mergeCart(customer, anonymousCart);
    assert response.getOrder().getOrderItems().size() == 1;
    assert response.getOrder().getId().equals(customerCart.getId());
    assert response.isMerged() == false;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) MergeCartResponse(org.broadleafcommerce.core.order.service.call.MergeCartResponse) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with MergeCartResponse

use of org.broadleafcommerce.core.order.service.call.MergeCartResponse in project BroadleafCommerce by BroadleafCommerce.

the class CartTest method testMergeWithBothCarts.

@Transactional
@Test(groups = { "testMergeCart" })
public void testMergeWithBothCarts() throws PricingException, RemoveFromCartException, AddToCartException {
    Order anonymousCart = setUpCartWithActiveSku();
    Order customerCart = setUpCartWithActiveSku();
    Customer customer = customerCart.getCustomer();
    MergeCartResponse response = mergeCartService.mergeCart(customer, anonymousCart);
    assert response.getOrder().getOrderItems().size() == 1;
    assert response.getOrder().getId().equals(anonymousCart.getId());
    assert response.isMerged() == false;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) MergeCartResponse(org.broadleafcommerce.core.order.service.call.MergeCartResponse) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with MergeCartResponse

use of org.broadleafcommerce.core.order.service.call.MergeCartResponse in project BroadleafCommerce by BroadleafCommerce.

the class CartTest method testMergeWithNoCustomerCart.

@Transactional
@Test(groups = { "testMergeCart" })
public void testMergeWithNoCustomerCart() throws PricingException, RemoveFromCartException, AddToCartException {
    Order anonymousCart = setUpCartWithActiveSku();
    Order customerCart = null;
    Customer customer = customerService.saveCustomer(createNamedCustomer());
    MergeCartResponse response = mergeCartService.mergeCart(customer, anonymousCart);
    assert response.getOrder().getOrderItems().size() == 1;
    assert response.getOrder().getId().equals(anonymousCart.getId());
    assert response.isMerged() == false;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) MergeCartResponse(org.broadleafcommerce.core.order.service.call.MergeCartResponse) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with MergeCartResponse

use of org.broadleafcommerce.core.order.service.call.MergeCartResponse in project BroadleafCommerce by BroadleafCommerce.

the class CartTest method testMergeWithInactiveAnonymousCart.

@Transactional
@Test(groups = { "testMergeCart" })
public void testMergeWithInactiveAnonymousCart() throws PricingException, RemoveFromCartException, AddToCartException {
    Order anonymousCart = null;
    Order customerCart = setUpCartWithInactiveSku();
    Customer customer = customerCart.getCustomer();
    MergeCartResponse response = mergeCartService.mergeCart(customer, anonymousCart);
    assert response.getOrder().getOrderItems().size() == 0;
    assert response.getOrder().getId().equals(customerCart.getId());
    assert response.isMerged() == false;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) MergeCartResponse(org.broadleafcommerce.core.order.service.call.MergeCartResponse) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with MergeCartResponse

use of org.broadleafcommerce.core.order.service.call.MergeCartResponse in project BroadleafCommerce by BroadleafCommerce.

the class MergeCartServiceImpl method mergeCart.

@Override
public MergeCartResponse mergeCart(Customer customer, Order anonymousCart, boolean priceOrder) throws PricingException, RemoveFromCartException {
    MergeCartResponse mergeCartResponse = new MergeCartResponse();
    // We no longer merge items, only transition cart states
    mergeCartResponse.setMerged(false);
    // We need to make sure that the old, saved customer cart is reconstructed with availability concerns in mind
    ReconstructCartResponse reconstructCartResponse = reconstructCart(customer, false);
    mergeCartResponse.setRemovedItems(reconstructCartResponse.getRemovedItems());
    Order customerCart = reconstructCartResponse.getOrder();
    if (anonymousCart != null && customerCart != null && anonymousCart.equals(customerCart)) {
        // The carts are the same, use either ensuring it's owned by the current customer
        setNewCartOwnership(anonymousCart, customer);
        mergeCartResponse.setOrder(anonymousCart);
    } else if (anonymousCart == null || anonymousCart.getOrderItems().size() == 0) {
        // The anonymous cart is of no use, use the customer cart
        mergeCartResponse.setOrder(customerCart);
        // multiple IN_PROCESS carts. We can go ahead and clean up this empty cart anyway since it's empty
        if (anonymousCart != null) {
            orderService.cancelOrder(anonymousCart);
        }
    } else if (customerCart == null || customerCart.getOrderItems().size() == 0) {
        // hanging around
        if (customerCart != null) {
            orderService.cancelOrder(customerCart);
        }
        // The customer cart is of no use, use the anonymous cart
        setNewCartOwnership(anonymousCart, customer);
        mergeCartResponse.setOrder(anonymousCart);
    } else {
        // Both carts have some items. The anonymous cart will always be the more recent one by definition
        // Save off the old customer cart and use the anonymous cart
        setSavedCartAttributes(customerCart);
        orderService.save(customerCart, false);
        setNewCartOwnership(anonymousCart, customer);
        mergeCartResponse.setOrder(anonymousCart);
    }
    if (mergeCartResponse.getOrder() != null) {
        Order savedCart = orderService.save(mergeCartResponse.getOrder(), priceOrder, priceOrder);
        mergeCartResponse.setOrder(savedCart);
    }
    return mergeCartResponse;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) ReconstructCartResponse(org.broadleafcommerce.core.order.service.call.ReconstructCartResponse) MergeCartResponse(org.broadleafcommerce.core.order.service.call.MergeCartResponse)

Aggregations

Order (org.broadleafcommerce.core.order.domain.Order)8 MergeCartResponse (org.broadleafcommerce.core.order.service.call.MergeCartResponse)8 Customer (org.broadleafcommerce.profile.core.domain.Customer)6 Transactional (org.springframework.transaction.annotation.Transactional)4 Test (org.testng.annotations.Test)4 ReconstructCartResponse (org.broadleafcommerce.core.order.service.call.ReconstructCartResponse)2 RemoveFromCartException (org.broadleafcommerce.core.order.service.exception.RemoveFromCartException)2 PricingException (org.broadleafcommerce.core.pricing.service.exception.PricingException)2 HashMap (java.util.HashMap)1 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)1 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)1 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)1 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)1