Example #1
0
        public virtual string[] GetListOfAllowedTokens()
        {
            var allowedTokens = LiquidExtensions.GetTokens(
                typeof(LiquidAskQuestion),
                typeof(LiquidAttributeCombination),
                typeof(LiquidAuctions),
                typeof(LiquidOutOfStockSubscription),
                typeof(LiquidBlogComment),
                typeof(LiquidContactUs),
                typeof(LiquidCustomer),
                typeof(LiquidEmailAFriend),
                typeof(LiquidGiftVoucher),
                typeof(LiquidKnowledgebase),
                typeof(LiquidNewsComment),
                typeof(LiquidNewsLetterSubscription),
                typeof(LiquidOrder),
                typeof(LiquidOrderItem),
                typeof(LiquidProduct),
                typeof(LiquidProductReview),
                typeof(LiquidMerchandiseReturn),
                typeof(LiquidShipment),
                typeof(LiquidShipmentItem),
                typeof(LiquidShoppingCart),
                typeof(LiquidStore),
                typeof(LiquidVatValidationResult),
                typeof(LiquidVendor),
                typeof(LiquidVendorReview));

            return(allowedTokens.ToArray());
        }
        public virtual string[] GetListOfAllowedTokens()
        {
            var allowedTokens = LiquidExtensions.GetTokens(
                typeof(LiquidAskQuestion),
                typeof(LiquidAttributeCombination),
                typeof(LiquidAuctions),
                typeof(LiquidBackInStockSubscription),
                typeof(LiquidBlogComment),
                typeof(LiquidContactUs),
                typeof(LiquidCustomer),
                typeof(LiquidEmailAFriend),
                typeof(LiquidForums),
                typeof(LiquidGiftCard),
                typeof(LiquidKnowledgebase),
                typeof(LiquidNewsComment),
                typeof(LiquidNewsLetterSubscription),
                typeof(LiquidOrder),
                typeof(LiquidOrderItem),
                typeof(LiquidPrivateMessage),
                typeof(LiquidProduct),
                typeof(LiquidProductReview),
                typeof(RecurringPayment),
                typeof(LiquidReturnRequest),
                typeof(LiquidShipment),
                typeof(LiquidShipmentItem),
                typeof(LiquidShoppingCart),
                typeof(LiquidStore),
                typeof(LiquidVatValidationResult),
                typeof(LiquidVendor),
                typeof(LiquidVendorReview));

            return(allowedTokens.ToArray());
        }
        /// <summary>
        /// Sends a campaign to specified email
        /// </summary>
        /// <param name="campaign">Campaign</param>
        /// <param name="emailAccount">Email account</param>
        /// <param name="email">Email</param>
        public virtual async Task SendCampaign(Campaign campaign, EmailAccount emailAccount, string email)
        {
            if (campaign == null)
            {
                throw new ArgumentNullException("campaign");
            }

            if (emailAccount == null)
            {
                throw new ArgumentNullException("emailAccount");
            }

            var          language     = _serviceProvider.GetRequiredService <IWorkContext>().WorkingLanguage;
            LiquidObject liquidObject = new LiquidObject();
            await _messageTokenProvider.AddStoreTokens(liquidObject, _storeContext.CurrentStore, language, emailAccount);

            var customer = await _customerService.GetCustomerByEmail(email);

            if (customer != null)
            {
                await _messageTokenProvider.AddCustomerTokens(liquidObject, customer, _storeContext.CurrentStore, language);

                await _messageTokenProvider.AddShoppingCartTokens(liquidObject, customer, _storeContext.CurrentStore, language);
            }

            var body    = LiquidExtensions.Render(liquidObject, campaign.Body);
            var subject = LiquidExtensions.Render(liquidObject, campaign.Subject);

            await _emailSender.SendEmail(emailAccount, subject, body, emailAccount.Email, emailAccount.DisplayName, email, null);
        }
Example #4
0
        /// <summary>
        /// Sends a campaign to specified email
        /// </summary>
        /// <param name="campaign">Campaign</param>
        /// <param name="emailAccount">Email account</param>
        /// <param name="email">Email</param>
        public virtual void SendCampaign(Campaign campaign, EmailAccount emailAccount, string email)
        {
            if (campaign == null)
            {
                throw new ArgumentNullException("campaign");
            }

            if (emailAccount == null)
            {
                throw new ArgumentNullException("emailAccount");
            }

            LiquidObject liquidObject = new LiquidObject();

            _messageTokenProvider.AddStoreTokens(liquidObject, _storeContext.CurrentStore, emailAccount);
            var customer = _customerService.GetCustomerByEmail(email);

            if (customer != null)
            {
                _messageTokenProvider.AddCustomerTokens(liquidObject, customer);
                _messageTokenProvider.AddShoppingCartTokens(liquidObject, customer);
            }

            var body    = LiquidExtensions.Render(liquidObject, campaign.Body);
            var subject = LiquidExtensions.Render(liquidObject, campaign.Subject);

            _emailSender.SendEmail(emailAccount, subject, body, emailAccount.Email, emailAccount.DisplayName, email, null);
        }
        /// <summary>
        /// Gets list of allowed (supported) message tokens for campaigns
        /// </summary>
        /// <returns>List of allowed (supported) message tokens for campaigns</returns>
        public virtual string[] GetListOfCampaignAllowedTokens()
        {
            var allowedTokens = LiquidExtensions.GetTokens(typeof(LiquidStore),
                                                           typeof(LiquidNewsLetterSubscription),
                                                           typeof(LiquidShoppingCart),
                                                           typeof(LiquidCustomer));

            return(allowedTokens.ToArray());
        }
        public virtual string[] GetListOfCustomerReminderAllowedTokens(CustomerReminderRuleEnum rule)
        {
            var allowedTokens = LiquidExtensions.GetTokens(typeof(LiquidStore));

            if (rule == CustomerReminderRuleEnum.AbandonedCart)
            {
                allowedTokens.AddRange(LiquidExtensions.GetTokens(typeof(LiquidShoppingCart)));
            }

            if (rule == CustomerReminderRuleEnum.CompletedOrder || rule == CustomerReminderRuleEnum.UnpaidOrder)
            {
                allowedTokens.AddRange(LiquidExtensions.GetTokens(typeof(LiquidOrder)));
            }

            allowedTokens.AddRange(LiquidExtensions.GetTokens(typeof(LiquidCustomer)));

            return(allowedTokens.ToArray());
        }
Example #7
0
        /// <summary>
        /// Sends a campaign to specified email
        /// </summary>
        /// <param name="campaign">Campaign</param>
        /// <param name="emailAccount">Email account</param>
        /// <param name="email">Email</param>
        public virtual async Task SendCampaign(Campaign campaign, EmailAccount emailAccount, string email)
        {
            if (campaign == null)
            {
                throw new ArgumentNullException(nameof(campaign));
            }

            if (emailAccount == null)
            {
                throw new ArgumentNullException(nameof(emailAccount));
            }

            var language = await _languageService.GetLanguageById(campaign.LanguageId);

            if (language == null)
            {
                language = (await _languageService.GetAllLanguages()).FirstOrDefault();
            }

            var store = await _storeService.GetStoreById(campaign.StoreId);

            if (store == null)
            {
                store = (await _storeService.GetAllStores()).FirstOrDefault();
            }

            var builder = new LiquidObjectBuilder(_mediator);

            builder.AddStoreTokens(store, language, emailAccount);
            var customer = await _customerService.GetCustomerByEmail(email);

            if (customer != null)
            {
                builder.AddCustomerTokens(customer, store, language)
                .AddShoppingCartTokens(customer, store, language);
            }

            var liquidObject = await builder.BuildAsync();

            var body    = LiquidExtensions.Render(liquidObject, campaign.Body);
            var subject = LiquidExtensions.Render(liquidObject, campaign.Subject);

            await _emailSender.SendEmail(emailAccount, subject, body, emailAccount.Email, emailAccount.DisplayName, email, null);
        }
Example #8
0
        /// <summary>
        /// Sends a campaign to specified emails
        /// </summary>
        /// <param name="campaign">Campaign</param>
        /// <param name="emailAccount">Email account</param>
        /// <param name="subscriptions">Subscriptions</param>
        /// <returns>Total emails sent</returns>
        public virtual async Task <int> SendCampaign(Campaign campaign, EmailAccount emailAccount,
                                                     IEnumerable <NewsLetterSubscription> subscriptions)
        {
            if (campaign == null)
            {
                throw new ArgumentNullException("campaign");
            }

            if (emailAccount == null)
            {
                throw new ArgumentNullException("emailAccount");
            }

            int totalEmailsSent = 0;
            var language        = await _languageService.GetLanguageById(campaign.LanguageId);

            if (language == null)
            {
                language = (await _languageService.GetAllLanguages()).FirstOrDefault();
            }

            foreach (var subscription in subscriptions)
            {
                Customer customer = null;

                if (!String.IsNullOrEmpty(subscription.CustomerId))
                {
                    customer = await _customerService.GetCustomerById(subscription.CustomerId);
                }

                if (customer == null)
                {
                    customer = await _customerService.GetCustomerByEmail(subscription.Email);
                }

                //ignore deleted or inactive customers when sending newsletter campaigns
                if (customer != null && (!customer.Active || customer.Deleted))
                {
                    continue;
                }

                var liquidObject = new LiquidObject();
                var store        = await _storeService.GetStoreById(campaign.StoreId);

                if (store == null)
                {
                    store = (await _storeService.GetAllStores()).FirstOrDefault();
                }

                await _messageTokenProvider.AddStoreTokens(liquidObject, store, language, emailAccount);

                await _messageTokenProvider.AddNewsLetterSubscriptionTokens(liquidObject, subscription, store);

                if (customer != null)
                {
                    await _messageTokenProvider.AddCustomerTokens(liquidObject, customer, store, language);

                    await _messageTokenProvider.AddShoppingCartTokens(liquidObject, customer, store, language);
                }

                var body    = LiquidExtensions.Render(liquidObject, campaign.Body);
                var subject = LiquidExtensions.Render(liquidObject, campaign.Subject);

                var email = new QueuedEmail {
                    Priority       = QueuedEmailPriority.Low,
                    From           = emailAccount.Email,
                    FromName       = emailAccount.DisplayName,
                    To             = subscription.Email,
                    Subject        = subject,
                    Body           = body,
                    CreatedOnUtc   = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                };
                await _queuedEmailService.InsertQueuedEmail(email);
                await InsertCampaignHistory(new CampaignHistory()
                {
                    CampaignId = campaign.Id, CustomerId = subscription.CustomerId, Email = subscription.Email, CreatedDateUtc = DateTime.UtcNow, StoreId = campaign.StoreId
                });

                //activity log
                if (customer != null)
                {
                    await _customerActivityService.InsertActivity("CustomerReminder.SendCampaign", campaign.Id, _localizationService.GetResource("ActivityLog.SendCampaign"), customer, campaign.Name);
                }
                else
                {
                    await _customerActivityService.InsertActivity("CustomerReminder.SendCampaign", campaign.Id, _localizationService.GetResource("ActivityLog.SendCampaign"), campaign.Name + " - " + subscription.Email);
                }

                totalEmailsSent++;
            }
            return(totalEmailsSent);
        }