Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

NewsletterModelFactory.cs

using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Security;
using Nop.Services.Localization;
using Nop.Web.Models.Newsletter;

namespace Nop.Web.Factories;

/// 
/// Represents the newsletter model factory
/// 
public partial class NewsletterModelFactory : INewsletterModelFactory
{
    #region Fields

    protected readonly CaptchaSettings _captchaSettings;
    protected readonly CustomerSettings _customerSettings;
    protected readonly ILocalizationService _localizationService;

    #endregion

    #region Ctor

    public NewsletterModelFactory(CaptchaSettings captchaSettings,
        CustomerSettings customerSettings,
        ILocalizationService localizationService)
    {
        _captchaSettings = captchaSettings;
        _customerSettings = customerSettings;
        _localizationService = localizationService;
    }

    #endregion

    #region Methods

    /// 
    /// Prepare the newsletter box model
    /// 
    /// 
    /// A task that represents the asynchronous operation
    /// The task result contains the newsletter box model
    /// 
    public virtual Task PrepareNewsletterBoxModelAsync()
    {
        var model = new NewsletterBoxModel
        {
            AllowToUnsubscribe = _customerSettings.NewsletterBlockAllowToUnsubscribe,
            DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnNewsletterPage,
            IsReCaptchaV3 = _captchaSettings.CaptchaType == CaptchaType.ReCaptchaV3,
            ReCaptchaPublicKey = _captchaSettings.ReCaptchaPublicKey
        };

        return Task.FromResult(model);
    }

    /// 
    /// Prepare the subscription activation model
    /// 
    /// Whether the subscription has been activated
    /// 
    /// A task that represents the asynchronous operation
    /// The task result contains the subscription activation model
    /// 
    public virtual async Task PrepareSubscriptionActivationModelAsync(bool active)
    {
        var model = new SubscriptionActivationModel
        {
            Result = active
                ? await _localizationService.GetResourceAsync("Newsletter.ResultActivated")
                : await _localizationService.GetResourceAsync("Newsletter.ResultDeactivated")
        };

        return model;
    }

    #endregion
}