public ManagerResponse <GetVisitorOrdersResult, IEnumerable <OrderHeader> > GetUserOrders(string userName)
        {
            if (userName == null)
            {
                throw new ArgumentNullException(nameof(userName));
            }

            var user = this.AccountManager.GetUser(userName);

            if (!user.ServiceProviderResult.Success || user.Result == null)
            {
                throw new ArgumentException("Could not find the user, invalid userName.", nameof(userName));
            }

            var request = new GetVisitorOrdersRequest(user.Result.ExternalId, StorefrontContext.Current.ShopName);
            var result  = OrderServiceProvider.GetVisitorOrders(request);

            if (result.Success && result.OrderHeaders != null && result.OrderHeaders.Count > 0)
            {
                return(new ManagerResponse <GetVisitorOrdersResult, IEnumerable <OrderHeader> >(result, result.OrderHeaders.ToList()));
            }

            result.WriteToSitecoreLog();
            //no orders found returns false - we treat it as success
            if (!result.Success && !result.SystemMessages.Any())
            {
                result.Success = true;
            }
            return(new ManagerResponse <GetVisitorOrdersResult, IEnumerable <OrderHeader> >(result, new List <OrderHeader>()));
        }
        public ManagerResponse <GetVisitorOrdersResult, OrderHeader[]> GetVisitorOrders(
            string customerId,
            string shopName,
            DateTime?fromDate,
            DateTime?untilDate,
            int page,
            int count)
        {
            var getVisitorOrdersRequest          = new GetVisitorOrdersRequest(customerId, shopName);
            GetVisitorOrdersResult visitorOrders = this.orderServiceProvider.GetVisitorOrders(getVisitorOrdersRequest);

            if (visitorOrders.OrderHeaders == null)
            {
                return(new ManagerResponse <GetVisitorOrdersResult, OrderHeader[]>(visitorOrders, new OrderHeader[0]));
            }

            IEnumerable <OrderHeader> query = visitorOrders.OrderHeaders;

            if (fromDate != null)
            {
                query = query.Where(x => x.OrderDate >= fromDate);
            }

            if (untilDate != null)
            {
                query = query.Where(oh => oh.OrderDate <= untilDate);
            }

            OrderHeader[] array = query
                                  .Skip(page * count)
                                  .Take(count)
                                  .ToArray();

            return(new ManagerResponse <GetVisitorOrdersResult, OrderHeader[]>(visitorOrders, array));
        }
        private bool TryResolveSubmittedOrder(CartBase cart, out ManagerResponse <SubmitVisitorOrderResult, Order> managerResponse)
        {
            var getVisitorOrdersRequest = new GetVisitorOrdersRequest(cart.CustomerId, cart.ShopName);
            GetVisitorOrdersResult getVisitorOrdersResult = this.orderServiceProvider.GetVisitorOrders(getVisitorOrdersRequest);

            if (getVisitorOrdersResult.Success)
            {
                // Getting the latest order
                OrderHeader orderHeader = getVisitorOrdersResult.OrderHeaders.OrderByDescending(x => x.OrderDate).FirstOrDefault();
                if (orderHeader != null)
                {
                    var getVisitorOrderRequest = new GetVisitorOrderRequest(orderHeader.OrderID, orderHeader.CustomerId, orderHeader.ShopName);

                    GetVisitorOrderResult getVisitorOrderResult =
                        this.orderServiceProvider.GetVisitorOrder(getVisitorOrderRequest);

                    if (getVisitorOrderResult.Order != null)
                    {
                        managerResponse = new ManagerResponse <SubmitVisitorOrderResult, Order>(
                            new SubmitVisitorOrderResult {
                            Order = getVisitorOrderResult.Order, Success = true
                        },
                            getVisitorOrderResult.Order);

                        return(true);
                    }
                }
            }

            managerResponse = null;
            return(false);
        }
        // GET
        public ActionResult Index()
        {
            var orderService = new OrderServiceProvider();

            var visitorOrdersRequest = new GetVisitorOrdersRequest("Entity-Customer-34d758ae2d2d472d89014954d0cc4440", "CommerceEngineDefaultStorefront");

            var result = orderService.GetVisitorOrders(visitorOrdersRequest);

            return(View(result));
        }
        /// <summary>
        /// Gets the orders.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="shopName">Name of the shop.</param>
        /// <returns>The manager response where list of order headers are returned in the Result.</returns>
        public ManagerResponse <GetVisitorOrdersResult, IEnumerable <OrderHeader> > GetOrders(string customerId, string shopName)
        {
            Assert.ArgumentNotNullOrEmpty(customerId, "customerId");
            Assert.ArgumentNotNullOrEmpty(shopName, "shopName");

            var request = new GetVisitorOrdersRequest(customerId, shopName);
            var result  = this._orderServiceProvider.GetVisitorOrders(request);

            if (result.Success && result.OrderHeaders != null && result.OrderHeaders.Count > 0)
            {
                return(new ManagerResponse <GetVisitorOrdersResult, IEnumerable <OrderHeader> >(result, result.OrderHeaders.ToList()));
            }

            //Helpers.LogSystemMessages(result.SystemMessages, result);
            return(new ManagerResponse <GetVisitorOrdersResult, IEnumerable <OrderHeader> >(result, new List <OrderHeader>()));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GetOrdersTest"/> class.
        /// </summary>
        public GetOrdersTest()
        {
            this.orderId      = 1;
            this.customerId   = 1;
            this.customerGuid = Guid.NewGuid();
            this.request      = new GetVisitorOrdersRequest(this.customerGuid.ToString(), "NopShop");
            this.result       = new GetVisitorOrdersResult();
            this.args         = new ServicePipelineArgs(this.request, this.result);

            this.client = Substitute.For <IOrdersServiceChannel>();

            var clientFactory = Substitute.For <ServiceClientFactory>();

            clientFactory.CreateClient <IOrdersServiceChannel>(Arg.Any <string>(), Arg.Any <string>()).Returns(this.client);

            this.processor = new GetOrders {
                ClientFactory = clientFactory
            };
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the orders.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="shopName">Name of the shop.</param>
        /// <returns>The manager response where list of order headers are returned in the Result.</returns>
        public ManagerResponse<GetVisitorOrdersResult, IEnumerable<OrderHeader>> GetOrders(string customerId, string shopName)
        {
            Assert.ArgumentNotNullOrEmpty(customerId, "customerId");
            Assert.ArgumentNotNullOrEmpty(shopName, "shopName");

            var request = new GetVisitorOrdersRequest(customerId, shopName);
            var result = this.OrderServiceProvider.GetVisitorOrders(request);
            if (result.Success && result.OrderHeaders != null && result.OrderHeaders.Count > 0)
            {
                return new ManagerResponse<GetVisitorOrdersResult, IEnumerable<OrderHeader>>(result, result.OrderHeaders.ToList());
            }

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return new ManagerResponse<GetVisitorOrdersResult, IEnumerable<OrderHeader>>(result, new List<OrderHeader>());
        }