Ejemplo n.º 1
0
        private void SendUnRegUsers(AbandonedCart cart, AbandonedCartTemplate template)
        {
            var customer     = cart.OrderConfirmationData.Customer;
            var shoppingCart = ShoppingCartService.GetShoppingCart(ShoppingCartType.ShoppingCart, cart.CustomerId);

            if (_letters.Find(x => x.Email == customer.EMail) != null)
            {
                return;
            }

            template.Register(customer, shoppingCart);
            template.BuildMail();

            SendMail.SendMailNow(customer.EMail, template.Subject, template.Body, true);
            AbandonedCartsService.LogLetter(new AbandonedCartLetter()
            {
                CustomerId  = cart.CustomerId,
                TemplateId  = template.Id,
                Email       = customer.EMail,
                SendingDate = DateTime.Now
            });
        }
Ejemplo n.º 2
0
 public bool InstallModule()
 {
     return(AbandonedCartsService.InstallModule());
 }
Ejemplo n.º 3
0
        public void Execute(IJobExecutionContext context)
        {
            if (!context.CanStart())
            {
                return;
            }
            context.WriteLastRun();

            AbandonedCartsService.DeleteExpiredLetters();
            var templates = AbandonedCartsService.GetTemplates().Where(x => x.Active).ToList();

            if (!templates.Any())
            {
                return;
            }

            var cartsUnReg =
                AbandonedCartsService.GetAbondonedCartsUnReg()
                .Where(
                    x =>
                    x.OrderConfirmationData != null && x.OrderConfirmationData.Customer != null &&
                    x.OrderConfirmationData.Customer.EMail.IsNotEmpty() &&
                    !x.OrderConfirmationData.Customer.IsAdmin)
                .ToList();

            var cartsReg = AbandonedCartsService.GetAbondonedCartsReg();

            _letters = AbandonedCartsService.GetAllLetters();

            foreach (var template in templates)
            {
                var date   = DateTime.Now.AddHours(-template.SendingTime);
                var upDate = DateTime.Now.AddDays(-1).AddHours(-template.SendingTime);

                try
                {
                    foreach (var cart in cartsUnReg.Where(c => c.LastUpdate <date && c.LastUpdate> upDate &&
                                                          _letters.Find(x => x.TemplateId == template.Id && x.CustomerId == c.CustomerId) == null))
                    {
                        SendUnRegUsers(cart, template);
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex);
                }


                try
                {
                    foreach (var cart in cartsReg.Where(c => c.LastUpdate <date && c.LastUpdate> upDate &&
                                                        _letters.Find(x => x.TemplateId == template.Id && x.CustomerId == c.CustomerId) == null))
                    {
                        SendRegUsers(cart, template);
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex);
                }
            }
        }