/// <summary> /// Get pickup points for the address /// </summary> /// <param name="address">Address</param> /// <returns>Represents a response of getting pickup points</returns> public GetPickupPointsResponse GetPickupPoints(Address address) { var result = new GetPickupPointsResponse(); foreach (var point in _storePickupPointService.GetAllStorePickupPoints(_storeContext.CurrentStore.Id)) { var pointAddress = _addressService.GetAddressById(point.AddressId); if (pointAddress != null) result.PickupPoints.Add(new PickupPoint { Id = point.Id.ToString(), Name = point.Name, Description = point.Description, Address = pointAddress.Address1, City = pointAddress.City, CountryCode = pointAddress.Country != null ? pointAddress.Country.TwoLetterIsoCode : string.Empty, ZipPostalCode = pointAddress.ZipPostalCode, OpeningHours = point.OpeningHours, PickupFee = point.PickupFee, ProviderSystemName = PluginDescriptor.SystemName }); } if (result.PickupPoints.Count == 0) result.AddError(_localizationService.GetResource("Plugins.Pickup.PickupInStore.NoPickupPoints")); return result; }
/// <summary> /// Gets available pickup points /// </summary> /// <param name="address">Address</param> /// <param name="providerSystemName">Filter by provider identifier; null to load pickup points of all providers</param> /// <param name="storeId">Load records allowed only in a specified store; pass 0 to load all records</param> /// <returns>Pickup points</returns> public virtual GetPickupPointsResponse GetPickupPoints(Address address, string providerSystemName = null, int storeId = 0) { var result = new GetPickupPointsResponse(); var pickupPointsProviders = LoadActivePickupPointProviders(storeId); if (!string.IsNullOrEmpty(providerSystemName)) pickupPointsProviders = pickupPointsProviders .Where(x => x.PluginDescriptor.SystemName.Equals(providerSystemName, StringComparison.InvariantCultureIgnoreCase)).ToList(); if (pickupPointsProviders.Count == 0) return result; var allPickupPoints = new List<PickupPoint>(); foreach (var provider in pickupPointsProviders) { var pickPointsResponse = provider.GetPickupPoints(address); if (pickPointsResponse.Success) allPickupPoints.AddRange(pickPointsResponse.PickupPoints); else { foreach (string error in pickPointsResponse.Errors) { result.AddError(error); _logger.Warning(string.Format("PickupPoints ({0}). {1}", provider.PluginDescriptor.FriendlyName, error)); } } } //any pickup points is enough if (allPickupPoints.Count > 0) { result.Errors.Clear(); result.PickupPoints = allPickupPoints; } return result; }