Package org.broadleafcommerce.core.order.service.call

Examples of org.broadleafcommerce.core.order.service.call.MergeCartResponse


    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;
    }
View Full Code Here


    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;
    }
View Full Code Here

        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;
    }
View Full Code Here

        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;
    }
View Full Code Here

    }

    @Override
    public MergeCartResponse mergeCart(Customer customer, Order anonymousCart, boolean priceOrder)
            throws PricingException, RemoveFromCartException {
        MergeCartResponse mergeCartResponse = new MergeCartResponse();
        mergeCartResponse.setMerged(false); // We no longer merge items, only transition cart states

        // 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);
           
            // The anonymous cart is owned by a different customer, so there is no chance for a single customer to have
            // 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) {
            // Delete the saved customer order since it is completely empty anyway. We do not want 2 IN_PROCESS orders
            // 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);
            mergeCartResponse.setOrder(savedCart);
        }
       
        return mergeCartResponse;
    }
View Full Code Here

        return reconstructCart(customer, true);
    }
   
    @Override
    public MergeCartResponse mergeCart(Customer customer, Order anonymousCart, boolean priceOrder) throws PricingException {
        MergeCartResponse mergeCartResponse = new MergeCartResponse();
        // reconstruct cart items (make sure they are valid)
        ReconstructCartResponse reconstructCartResponse = reconstructCart(customer, false);
        mergeCartResponse.setRemovedItems(reconstructCartResponse.getRemovedItems());
        Order customerCart = reconstructCartResponse.getOrder();

        if (anonymousCart != null && customerCart != null && anonymousCart.getId().equals(customerCart.getId())) {
            /*
             * Set merged to false if the cart ids are equal (cookied customer
             * logs in).
             */
            mergeCartResponse.setMerged(false);
        } else {
            /*
             * Set the response to merged if the saved cart has any items
             * available to merge in.
             */
            mergeCartResponse.setMerged(customerCart != null && customerCart.getOrderItems().size() > 0);
        }

       
        // add anonymous cart items (make sure they are valid)
        if (anonymousCart != null && (customerCart == null || !customerCart.getId().equals(anonymousCart.getId()))) {
            if (anonymousCart != null && anonymousCart.getOrderItems() != null && !anonymousCart.getOrderItems().isEmpty()) {
                if (customerCart == null) {
                    customerCart = orderService.createNewCartForCustomer(customer);
                }
               
                Map<OrderItem, OrderItem> oldNewItemMap = new HashMap<OrderItem, OrderItem>();
                customerCart = mergeRegularOrderItems(anonymousCart, mergeCartResponse, customerCart, oldNewItemMap);
                customerCart = mergeOfferCodes(anonymousCart, customerCart);
                customerCart = removeExpiredGiftWrapOrderItems(mergeCartResponse, customerCart, oldNewItemMap);
                customerCart = mergeGiftWrapOrderItems(mergeCartResponse, customerCart, oldNewItemMap);

                orderService.cancelOrder(anonymousCart);
            }
        }
       
        // copy the customer's email to this order, overriding any previously set email
        if (customerCart != null && StringUtils.isNotBlank(customer.getEmailAddress())) {
            customerCart.setEmailAddress(customer.getEmailAddress());
            customerCart = orderService.save(customerCart, priceOrder);
        }
       
        mergeCartResponse.setOrder(customerCart);
        return mergeCartResponse;
    }
View Full Code Here

        return (anonymousCustomer != null && customer.getId() != null && !customer.getId().equals(anonymousCustomer.getId()));
    }

    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();
    }
View Full Code Here

    @Transactional
    @Test(groups = { "testMergeCartLegacy" })
    public void testMergeToEmptyCart() throws PricingException {
        Order anonymousCart = setUpAnonymousCartWithInactiveSku();
        Customer customer = customerService.saveCustomer(createNamedCustomer());
        MergeCartResponse response = cartService.mergeCart(customer, anonymousCart);
        assert response.getAddedItems().size() == 2;
        assert response.getOrder().getOrderItems().size() == 2;
        assert response.isMerged() == false;
        assert response.getRemovedItems().size() == 2;
    }
View Full Code Here

        Order anonymousCart = setUpAnonymousCartWithInactiveSku();
        Customer customer = customerService.saveCustomer(createNamedCustomer());
       
        //sets up existing cart with a DiscreteOrderItem, inactive DiscreteOrderItem, BundleOrderItem, and inactive BundleOrderItem
        initializeExistingCartWithInactiveSkuAndInactiveBundle(customer);
        MergeCartResponse response = cartService.mergeCart(customer, anonymousCart);
       
        assert response.getAddedItems().size() == 2;
        assert response.getOrder().getOrderItems().size() == 4;
        assert response.isMerged();
        assert response.getRemovedItems().size() == 4;
    }
View Full Code Here

       
        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) {
View Full Code Here

TOP

Related Classes of org.broadleafcommerce.core.order.service.call.MergeCartResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.