Example #1
0
        /// <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);
        }
Example #2
0
        /// <summary>
        /// Gets available pickup points
        /// </summary>
        /// <param name="address">Address</param>
        /// <param name="customer">Load records allowed only to a specified customer; pass null to ignore ACL permissions</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, Customer customer = null, string providerSystemName = null, int storeId = 0)
        {
            var result = new GetPickupPointsResponse();
            var pickupPointsProviders = LoadActivePickupPointProviders(customer, 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 (var error in pickPointsResponse.Errors)
                    {
                        result.AddError(error);
                        _logger.Warning($"PickupPoints ({provider.PluginDescriptor.FriendlyName}). {error}");
                    }
                }
            }

            //any pickup points is enough
            if (allPickupPoints.Count > 0)
            {
                result.Errors.Clear();
                result.PickupPoints = allPickupPoints.OrderBy(point => point.DisplayOrder).ThenBy(point => point.Name).ToList();
            }

            return(result);
        }
Example #3
0
        /// <summary>
        /// Gets available pickup points
        /// </summary>
        /// <param name="addressId">Address identifier</param>
        /// <param name="customer">Load records allowed only to a specified customer; pass null to ignore ACL permissions</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 async Task <GetPickupPointsResponse> GetPickupPointsAsync(int addressId, Customer customer = null,
                                                                                 string providerSystemName        = null, int storeId = 0)
        {
            var result = new GetPickupPointsResponse();

            var pickupPointsProviders = await _pickupPluginManager.LoadActivePluginsAsync(customer, storeId, providerSystemName);

            if (!pickupPointsProviders.Any())
            {
                return(result);
            }

            var allPickupPoints = new List <PickupPoint>();

            foreach (var provider in pickupPointsProviders)
            {
                var pickPointsResponse = await provider.GetPickupPointsAsync(await _addressService.GetAddressByIdAsync(addressId));

                if (pickPointsResponse.Success)
                {
                    allPickupPoints.AddRange(pickPointsResponse.PickupPoints);
                }
                else
                {
                    foreach (var error in pickPointsResponse.Errors)
                    {
                        result.AddError(error);
                        await _logger.WarningAsync($"PickupPoints ({provider.PluginDescriptor.FriendlyName}). {error}");
                    }
                }
            }

            //any pickup points is enough
            if (allPickupPoints.Count <= 0)
            {
                return(result);
            }

            result.Errors.Clear();
            result.PickupPoints = allPickupPoints.OrderBy(point => point.DisplayOrder).ThenBy(point => point.Name).ToList();

            return(result);
        }
        /// <summary>
        /// Get pickup points for the address
        /// </summary>
        /// <param name="address">Address</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the represents a response of getting pickup points
        /// </returns>
        public async Task <GetPickupPointsResponse> GetPickupPointsAsync(Address address)
        {
            var result = new GetPickupPointsResponse();
            var store  = await _storeContext.GetCurrentStoreAsync();

            foreach (var point in await _storePickupPointService.GetAllStorePickupPointsAsync(store.Id))
            {
                var pointAddress = await _addressService.GetAddressByIdAsync(point.AddressId);

                if (pointAddress == null)
                {
                    continue;
                }

                result.PickupPoints.Add(new PickupPoint
                {
                    Id                 = point.Id.ToString(),
                    Name               = point.Name,
                    Description        = point.Description,
                    Address            = pointAddress.Address1,
                    City               = pointAddress.City,
                    County             = pointAddress.County,
                    StateAbbreviation  = (await _stateProvinceService.GetStateProvinceByAddressAsync(pointAddress))?.Abbreviation ?? string.Empty,
                    CountryCode        = (await _countryService.GetCountryByAddressAsync(pointAddress))?.TwoLetterIsoCode ?? string.Empty,
                    ZipPostalCode      = pointAddress.ZipPostalCode,
                    OpeningHours       = point.OpeningHours,
                    PickupFee          = point.PickupFee,
                    DisplayOrder       = point.DisplayOrder,
                    ProviderSystemName = PluginDescriptor.SystemName,
                    Latitude           = point.Latitude,
                    Longitude          = point.Longitude,
                    TransitDays        = point.TransitDays
                });
            }

            if (!result.PickupPoints.Any())
            {
                result.AddError(await _localizationService.GetResourceAsync("Plugins.Pickup.PickupInStore.NoPickupPoints"));
            }

            return(result);
        }
        /// <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)
                {
                    continue;
                }

                result.PickupPoints.Add(new PickupPoint
                {
                    Id                 = point.Id.ToString(),
                    Name               = point.Name,
                    Description        = point.Description,
                    Address            = pointAddress.Address1,
                    City               = pointAddress.City,
                    County             = pointAddress.County,
                    StateAbbreviation  = pointAddress.StateProvince?.Abbreviation ?? string.Empty,
                    CountryCode        = pointAddress.Country?.TwoLetterIsoCode ?? string.Empty,
                    ZipPostalCode      = pointAddress.ZipPostalCode,
                    OpeningHours       = point.OpeningHours,
                    PickupFee          = point.PickupFee,
                    DisplayOrder       = point.DisplayOrder,
                    ProviderSystemName = PluginDescriptor.SystemName,
                    Latitude           = point.Latitude,
                    Longitude          = point.Longitude
                });
            }

            if (!result.PickupPoints.Any())
            {
                result.AddError(_localizationService.GetResource("Plugins.Pickup.PickupInStore.NoPickupPoints"));
            }

            return(result);
        }