Beispiel #1
0
        public async Task <IList <OutOfStockSubscription> > Handle(SendNotificationsToSubscribersCommand request, CancellationToken cancellationToken)
        {
            if (request.Product == null)
            {
                throw new ArgumentNullException(nameof(request.Product));
            }

            int result = 0;

            var subscriptions = await GetAllSubscriptionsByProductId(request.Product.Id, request.Attributes, request.Warehouse);

            foreach (var subscription in subscriptions)
            {
                var customer = await _customerService.GetCustomerById(subscription.CustomerId);

                //ensure that customer is registered (simple and fast way)
                if (customer != null && CommonHelper.IsValidEmail(customer.Email))
                {
                    var customerLanguageId = customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.LanguageId, subscription.StoreId);
                    await _messageProviderService.SendBackinStockMessage(customer, request.Product, subscription, customerLanguageId);

                    result++;
                }
            }

            return(subscriptions);
        }