/// <summary> /// Search orders /// </summary> /// <param name="storeId">Store identifier; 0 to load all orders</param> /// <param name="vendorId">Vendor identifier; null to load all orders</param> /// <param name="customerId">Customer identifier; 0 to load all orders</param> /// <param name="productId">Product identifier which was purchased in an order; 0 to load all orders</param> /// <param name="affiliateId">Affiliate identifier; 0 to load all orders</param> /// <param name="billingCountryId">Billing country identifier; 0 to load all orders</param> /// <param name="warehouseId">Warehouse identifier, only orders with products from a specified warehouse will be loaded; 0 to load all orders</param> /// <param name="paymentMethodSystemName">Payment method system name; null to load all records</param> /// <param name="createdFromUtc">Created date from (UTC); null to load all records</param> /// <param name="createdToUtc">Created date to (UTC); null to load all records</param> /// <param name="os">Order status; null to load all orders</param> /// <param name="ps">Order payment status; null to load all orders</param> /// <param name="ss">Order shipment status; null to load all orders</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <param name="orderNotes">Search in order notes. Leave empty to load all records.</param> /// <param name="orderGuid">Search by order GUID (Global unique identifier) or part of GUID. Leave empty to load all orders.</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <returns>Orders</returns> public virtual async Task <IPagedList <Order> > SearchOrders(string storeId = "", string vendorId = "", string customerId = "", string productId = "", string affiliateId = "", string warehouseId = "", string billingCountryId = "", string paymentMethodSystemName = null, DateTime?createdFromUtc = null, DateTime?createdToUtc = null, OrderStatus?os = null, PaymentStatus?ps = null, ShippingStatus?ss = null, string billingEmail = null, string billingLastName = "", string orderGuid = null, int pageIndex = 0, int pageSize = int.MaxValue) { var querymodel = new GetOrderQueryModel() { AffiliateId = affiliateId, BillingCountryId = billingCountryId, BillingEmail = billingEmail, BillingLastName = billingLastName, CreatedFromUtc = createdFromUtc, CreatedToUtc = createdToUtc, CustomerId = customerId, OrderGuid = orderGuid, Os = os, PageIndex = pageIndex, PageSize = pageSize, PaymentMethodSystemName = paymentMethodSystemName, ProductId = productId, Ps = ps, Ss = ss, StoreId = storeId, VendorId = vendorId, WarehouseId = warehouseId }; var query = await _mediator.Send(querymodel); return(await PagedList <Order> .Create(query, pageIndex, pageSize)); }
/// <summary> /// Gets all order items /// </summary> /// <param name="orderId">Order identifier; null to load all records</param> /// <param name="customerId">Customer identifier; null to load all records</param> /// <param name="createdFromUtc">Order created date from (UTC); null to load all records</param> /// <param name="createdToUtc">Order created date to (UTC); null to load all records</param> /// <param name="os">Order status; null to load all records</param> /// <param name="ps">Order payment status; null to load all records</param> /// <param name="ss">Order shipment status; null to load all records</param> /// <param name="loadDownloableProductsOnly">Value indicating whether to load downloadable products only</param> /// <returns>Orders</returns> public virtual async Task <IList <OrderItem> > GetAllOrderItems(string orderId, string customerId, DateTime?createdFromUtc, DateTime?createdToUtc, OrderStatus?os, PaymentStatus?ps, ShippingStatus?ss, bool loadDownloableProductsOnly) { var querymodel = new GetOrderQueryModel() { CreatedFromUtc = createdFromUtc, CreatedToUtc = createdToUtc, CustomerId = customerId, Os = os, OrderId = orderId, Ps = ps, Ss = ss, }; var query = await _mediator.Send(querymodel); var items = new List <OrderItem>(); foreach (var order in await query.ToListAsync()) { foreach (var orderitem in order.OrderItems) { if (loadDownloableProductsOnly) { var product = await _productRepository.GetByIdAsync(orderitem.ProductId); if (product == null) { product = await _productDeletedRepository.GetByIdAsync(orderitem.ProductId) as Product; } if (product != null) { if (product.IsDownload) { items.Add(orderitem); } } } else { items.Add(orderitem); } } } return(items); }
public Task <IMongoQueryable <Order> > Handle(GetOrderQueryModel request, CancellationToken cancellationToken) { int?orderStatusId = null; if (request.Os.HasValue) { orderStatusId = (int)request.Os.Value; } int?paymentStatusId = null; if (request.Ps.HasValue) { paymentStatusId = (int)request.Ps.Value; } int?shippingStatusId = null; if (request.Ss.HasValue) { shippingStatusId = (int)request.Ss.Value; } var query = _orderRepository.Table; if (!string.IsNullOrEmpty(request.OrderId)) { query = query.Where(o => o.Id == request.OrderId); } if (!string.IsNullOrEmpty(request.StoreId)) { query = query.Where(o => o.StoreId == request.StoreId); } if (!string.IsNullOrEmpty(request.VendorId)) { query = query .Where(o => o.OrderItems .Any(orderItem => orderItem.VendorId == request.VendorId)); } if (!string.IsNullOrEmpty(request.CustomerId)) { query = query.Where(o => o.CustomerId == request.CustomerId); } if (!string.IsNullOrEmpty(request.ProductId)) { query = query .Where(o => o.OrderItems .Any(orderItem => orderItem.ProductId == request.ProductId)); } if (!string.IsNullOrEmpty(request.WarehouseId)) { query = query .Where(o => o.OrderItems .Any(orderItem => orderItem.WarehouseId == request.WarehouseId )); } if (!string.IsNullOrEmpty(request.BillingCountryId)) { query = query.Where(o => o.BillingAddress != null && o.BillingAddress.CountryId == request.BillingCountryId); } if (!string.IsNullOrEmpty(request.PaymentMethodSystemName)) { query = query.Where(o => o.PaymentMethodSystemName == request.PaymentMethodSystemName); } if (!string.IsNullOrEmpty(request.AffiliateId)) { query = query.Where(o => o.AffiliateId == request.AffiliateId); } if (request.CreatedFromUtc.HasValue) { query = query.Where(o => request.CreatedFromUtc.Value <= o.CreatedOnUtc); } if (request.CreatedToUtc.HasValue) { query = query.Where(o => request.CreatedToUtc.Value >= o.CreatedOnUtc); } if (orderStatusId.HasValue) { query = query.Where(o => orderStatusId.Value == o.OrderStatusId); } if (paymentStatusId.HasValue) { query = query.Where(o => paymentStatusId.Value == o.PaymentStatusId); } if (shippingStatusId.HasValue) { query = query.Where(o => shippingStatusId.Value == o.ShippingStatusId); } if (!string.IsNullOrEmpty(request.BillingEmail)) { query = query.Where(o => o.BillingAddress != null && o.BillingAddress.Email == request.BillingEmail); } if (!string.IsNullOrEmpty(request.BillingLastName)) { query = query.Where(o => o.BillingAddress != null && o.BillingAddress.LastName.Contains(request.BillingLastName)); } if (!string.IsNullOrEmpty(request.OrderGuid)) { if (Guid.TryParse(request.OrderGuid, out Guid orderguid)) { query = query.Where(o => o.OrderGuid == orderguid); } } query = query.Where(o => !o.Deleted); query = query.OrderByDescending(o => o.CreatedOnUtc); return(Task.FromResult(query)); }