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