public void GetCurrentCart_ShoudReturn_SuccessEqualsTrue_WhenServiceProviderResultIsSuccessAndCartNotExistInCacheAndCookieExist(Database db)
        {
            _mocks.MockContexts(db);
            MockCookie(Models.UserWithEmptyCache);
            _visitorContextMock.GetCustomerId().Returns(Models.UserWithEmptyCache);

            var result = _cartRepository.GetCurrentCart();

            result.Success.Should().BeTrue();
        }
        /// <summary>
        /// Submits the visitor order.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <param name="inputModel">The input model.</param>
        /// <returns>
        /// The manager response where the new CommerceOrder is returned in the Result.
        /// </returns>
        public ManagerResponse <SubmitVisitorOrderResult, CommerceOrder> SubmitVisitorOrder([NotNull] CommerceStorefront storefront, [NotNull] IVisitorContext visitorContext, [NotNull] SubmitOrderInputModel inputModel)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(visitorContext, "visitorContext");
            Assert.ArgumentNotNull(inputModel, "inputModel");

            SubmitVisitorOrderResult errorResult = new SubmitVisitorOrderResult {
                Success = false
            };

            var response = this._cartManager.GetCurrentCart(storefront, visitorContext, true);

            if (!response.ServiceProviderResult.Success || response.Result == null)
            {
                response.ServiceProviderResult.SystemMessages.ToList().ForEach(m => errorResult.SystemMessages.Add(m));
                return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null));
            }

            var cart = (CommerceCart)response.ServiceProviderResult.Cart;

            if (cart.Lines.Count == 0)
            {
                errorResult.SystemMessages.Add(new SystemMessage {
                    Message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.SubmitOrderHasEmptyCart)
                });
                return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null));
            }

            var cartChanges = new CommerceCart();

            cartChanges.Properties["Email"] = inputModel.UserEmail;

            var updateCartResult = this._cartManager.UpdateCart(storefront, visitorContext, cart, cartChanges);

            if (!updateCartResult.ServiceProviderResult.Success)
            {
                response.ServiceProviderResult.SystemMessages.ToList().ForEach(m => errorResult.SystemMessages.Add(m));
                return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null));
            }

            var request = new SubmitVisitorOrderRequest(cart);

            request.RefreshCart(true);
            errorResult = this._orderServiceProvider.SubmitVisitorOrder(request);
            if (errorResult.Success && errorResult.Order != null && errorResult.CartWithErrors == null)
            {
                var cartCache = ContextTypeLoader.CreateInstance <CartCacheHelper>();
                cartCache.InvalidateCartCache(visitorContext.GetCustomerId());
            }

            //Helpers.LogSystemMessages(errorResult.SystemMessages, errorResult);
            return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, errorResult.Order as CommerceOrder));
        }
        /// <summary>
        /// Gets the order details.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <param name="orderId">The order identifier.</param>
        /// <returns>
        /// The manager response where the order detail returned in the Result.
        /// </returns>
        public ManagerResponse <GetVisitorOrderResult, CommerceOrder> GetOrderDetails([NotNull] CommerceStorefront storefront, [NotNull] IVisitorContext visitorContext, [NotNull] string orderId)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(visitorContext, "visitorContext");
            Assert.ArgumentNotNullOrEmpty(orderId, "orderId");

            var customerId = visitorContext.GetCustomerId();
            var request    = new GetVisitorOrderRequest(orderId, customerId, storefront.ShopName);
            var result     = this._orderServiceProvider.GetVisitorOrder(request);

            //Helpers.LogSystemMessages(result.SystemMessages, result);
            return(new ManagerResponse <GetVisitorOrderResult, CommerceOrder>(result, result.Order as CommerceOrder));
        }
        /// <summary>
        /// Gets the product prices.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <param name="catalogName">Name of the catalog.</param>
        /// <param name="productId">The product identifier.</param>
        /// <param name="includeVariants">if set to <c>true</c> [include variants].</param>
        /// <param name="priceTypeIds">The price type ids.</param>
        /// <returns>
        /// The manager response with the list of prices in the Result.
        /// </returns>
        public virtual ManagerResponse <Sitecore.Commerce.Services.Prices.GetProductPricesResult, IDictionary <string, Price> > GetProductPrices([NotNull] CommerceStorefront storefront, [NotNull] IVisitorContext visitorContext, string catalogName, string productId, bool includeVariants, params string[] priceTypeIds)
        {
            Assert.ArgumentNotNull(storefront, "storefront");

            if (priceTypeIds == null)
            {
                priceTypeIds = DefaultPriceTypeIds;
            }

            var request = new Requests.GetProductPricesRequest(catalogName, productId, priceTypeIds);

            if (Sitecore.Context.User.IsAuthenticated)
            {
                request.UserId = visitorContext.GetCustomerId();
            }

            request.IncludeVariantPrices = includeVariants;
            request.CurrencyCode         = StorefrontManager.GetCustomerCurrency();
            var result = this._pricingServiceProvider.GetProductPrices(request);

            // Helpers.LogSystemMessages(result.SystemMessages, result);
            return(new ManagerResponse <Sitecore.Commerce.Services.Prices.GetProductPricesResult, IDictionary <string, Price> >(result, result.Prices == null ? new Dictionary <string, Price>() : result.Prices));
        }