Ecommerce Checkout Issue - Ecommerce - Ecommerce - Progress Community

Ecommerce Checkout Issue

  • Ecommerce Checkout Issue

  • Having a problem with checkout returning this error.

    Timestamp: 9/5/2014 3:37:22 PM

    Message: System.Reflection.TargetInvocationException: Exception has been
    thrown by the target of an invocation. --->
    System.InvalidOperationException: Query execution found more than one

    cutter, MethodCallExpression mce, ChainedContext piece, QueryOptions

       at Telerik.OpenAccess.Query.Piece`1.ExecuteSingle[TResult](Expression expression)

       --- End of inner exception stack trace ---

       at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)

       at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,
    BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo

       at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)

       at Telerik.Sitefinity.Data.Linq.OpenAccess.OpenAccessQueryProvider`2.Execute(Expression expression)


       at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source)

       at Telerik.Sitefinity.Modules.Ecommerce.Orders.Web.UI.CheckoutViews.Preview.Checkout()

    Category: ErrorLog

    Priority: -1

    EventId: 1

    Severity: Information


    Machine: HFWINWEB02

    App Domain: /LM/W3SVC/1/ROOT-1-130539467060220794

    ProcessId: 1616

    Process Name: c:\windows\system32\inetsrv\w3wp.exe

    Thread Name:

    Win32 ThreadId:3408

    Extended Properties:

     We believe this is occurring because we created a custom control to
    add items to the cart.  If we use the standard cart items and checkout
    the error does not occur.  Here is the code we are using for the custom
    add to cart.

     OrdersManager orderManager = OrdersManager.GetManager();

            CatalogManager catManager = CatalogManager.GetManager();

            CartOrder shoppingCart = this.TryGetShoppingCartForUser(orderManager);

            Product liveProduct = catManager.GetProduct(selectedProductID, ContentLifecycleStatus.Live);

            if (shoppingCart == null)


                shoppingCart = orderManager.CreateCartOrder();

                HttpCookie shoppingCartCookie = new

                shoppingCartCookie.Value = shoppingCart.Id.ToString();

                shoppingCartCookie.Expires = DateTime.Now.AddMonths(1);



            shoppingCart.Currency = Config.Get<EcommerceConfig>().DefaultCurrency;

            CartDetail cartDetail = shoppingCart.Details.Where(d => d.ProductId == liveProduct.Id).SingleOrDefault();

            if (cartDetail != null)


                orderManager.SetQuantity(cartDetail, cartDetail.Quantity + 1);




                OptionsDetails optionDetails = new OptionsDetails();

                orderManager.AddToCart(shoppingCart, liveProduct, optionDetails, 1);


     The selectedProductID represents the proper sku for the selected
    product.  Everything adds to the cart without error and you can go
    through the entire checkout process but the moment you select place
    order on the preview page this error occurs.  Any thoughts on what is
    wrong here??

  • This solution worked for me.  Hopefully this will help someone else who stumbles on this issue.

     public bool AddToCart(string sku, int qty)
            OrdersManager OrdersMgr = OrdersManager.GetManager();
            CatalogManager CatalogMgr = CatalogManager.GetManager();

            if (string.IsNullOrWhiteSpace(sku) || qty < 0) return false;

            /* Get Product */

            //var product = CatalogManager.GetProducts().FirstOrDefault(c => c.Sku == sku);
            var product = CatalogMgr.GetProduct(sku, ContentLifecycleStatus.Live);

            /* Add to cart */

            if (product != null)
                // Get CartOrder
                var cartOrder = GetCartOrder();

                // If still null create cart
                if (cartOrder == null)
                    // Create and save order
                    cartOrder = OrdersMgr.CreateCartOrder();

                    // Increment order number
                    var on = OrdersMgr.GetNextOrderNumber();
                    cartOrder.OrderNumber = on.Next;

                    // Save

                    // Save new order to session

                    // Save new order to cookie

                IProductImagePopulator ImgPopulator = new ProductImagePopulator();
                IProductVatTaxPopulator VatTaxPopulator = new ProductVatTaxPopulator();

                // Populate Images and Tax

                if (cartOrder.Details.Any(c => c.ProductId == product.Id)) // existing item in cart, bump qty
                    var detail = cartOrder.Details.First(c => c.ProductId == product.Id);
                    OrdersMgr.IncreaseQuantity(detail.Id, qty);
                else // no existing item in cart, addtocart
                    // Create OptionsDetails - we're not handling variations at this point
                    // Note - if you populate SKU or TotalDetailPrice it will concat the default product values
                    var options = new OptionsDetails();

                    OrdersMgr.AddToCart(cartOrder, product, options, qty);

                // Populate CartOrder/Details info
                var calc = new EcommerceOrderCalculator();

                // Final Save

                return true;

            return false;

        public CartOrder GetCartOrder()
            CartOrder r = null;

            var mgr = OrdersManager.GetManager();

            // Get cart by cookie
            var cookieId = GetCartIdFromCookie();
            if (cookieId != null && cookieId != Guid.Empty)
                var exists = mgr.GetCartOrders().Any(c => c.Id == cookieId);
                if (exists) r = mgr.TryGetCartOrder((Guid)cookieId);

            return r;

        public static Guid? GetCartIdFromSession()
            var session = HttpContext.Current.Session["cartOrderId"];
            if (session != null)
                var r = Guid.Empty;
                Guid.TryParse(session.ToString(), out r);
                if (r != Guid.Empty) return r;

            return null;

        public static Guid? GetCartIdFromCookie()
            var cookie = HttpContext.Current.Request.Cookies["shoppingCartId"];
            if (cookie != null)
                var r = Guid.Empty;
                Guid.TryParse(cookie.Value, out r);
                if (r != Guid.Empty) return r;

            return null;

        public static void SetCartIdInSession(Guid id)
            HttpContext.Current.Session["cartOrderId"] = id;

        public static void SetCartIdInCookie(Guid id)
            var _id = id.ToString();

            // Remove any existing cookie

            var cookie = HttpContext.Current.Response.Cookies["shoppingCartId"];
            if (cookie == null)
                cookie = new HttpCookie("shoppingCartId") Expires = DateTime.Now.AddMonths(6) ;

                cookie.Value = _id;

                cookie.Value = _id;

        public static void RemoveCartIdFromSession(Guid id)
            HttpContext.Current.Session["cartOrderId"] = null;

        public static void RemoveCartCookie(Guid id)
            // Remove any existing request cookie
            if (HttpContext.Current.Request.Cookies["shoppingCartId"] != null)

            // Remove any existing response cookie
            if (HttpContext.Current.Response.Cookies["shoppingCartId"] != null)

  • Hi,

    Thank you for sharing the solution with the community.

    Atanas Valchev
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items