Esempio n. 1
0
 protected override void UpdateEditorShape(UpdateEditorContext context)
 {
     base.UpdateEditorShape(context);
     if (context.ContentItem.As <MailchimpSubscriptionPart>() != null)
     {
         try {
             _service.CheckAcceptedPolicy(context.ContentItem.As <MailchimpSubscriptionPart>());
         }
         catch (MissingPoliciesException) {
             context.Updater.AddModelError("MissingPolicies", T("You have to accept all required policies in order to subscribe to the newsletter."));
             _modelIsValid = false;
         }
         catch (Exception ex) {
             context.Updater.AddModelError("GenericPolicies", T("You have to accept all required policies in order to subscribe to the newsletter."));
             context.Logger.Log(LogLevel.Error, ex, "CheckAcceptedPolicy throws an error.", null);
             _modelIsValid = false;
         }
     }
 }
        private void UpdateSubscription(IUser user)
        {
            var part = user.As <MailchimpSubscriptionPart>();

            if (part != null)
            {
                // When a User is Created a Published is improperly called to early and the part is not Updated
                // So I skip this step
                if (part.Subscription.Audience == null || user.As <UserPart>().EmailStatus != UserStatus.Approved)
                {
                    return;
                }
                var settings = part.Settings.GetModel <MailchimpSubscriptionPartSettings>();
                try {
                    _service.CheckAcceptedPolicy(part);
                }
                catch (MissingPoliciesException) {
                    _notifier.Add(NotifyType.Warning, T("Wait... it seems you have not accepted all our required policies. Your account has been verified, but your email have not been subscribed. Please, retry after having accepted our policies."));
                    return;
                }
                if (!_apiService.TryUpdateSubscription(part, true))
                {
                    if (settings.NotifySubscriptionResult || AdminFilter.IsApplied(_workContext.GetContext().HttpContext.Request.RequestContext))
                    {
                        _notifier.Error(T("Oops! We are currently experienced a problem during your email subscription. Please, retry later."));
                    }
                }
                else
                {
                    // The message should only be displayed if the checkbox has been selected
                    if (part.Subscription.Subscribed)
                    {
                        if (settings.NotifySubscriptionResult || AdminFilter.IsApplied(_workContext.GetContext().HttpContext.Request.RequestContext))
                        {
                            _notifier.Information(T("Nice to meet you! Your subscription has been accepted."));
                        }
                    }
                }
            }
        }