Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

1.5 KB
Raw Blame
using Grand.Business.Core.Events.Customers;
using Grand.Business.Core.Interfaces.Checkout.Orders;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Domain.Orders;
using Grand.Mediator;

namespace Grand.Business.Checkout.Events.Customers;

public class CustomerRegisteredEventHandler : INotificationHandler<CustomerRegisteredEvent>
{
    private readonly ILoyaltyPointsService _loyaltyPointsService;
    private readonly LoyaltyPointsSettings _loyaltyPointsSettings;
    private readonly ITranslationService _translationService;

    public CustomerRegisteredEventHandler(
        ITranslationService translationService,
        ILoyaltyPointsService loyaltyPointsService,
        LoyaltyPointsSettings loyaltyPointsSettings
    )
    {
        _translationService = translationService;
        _loyaltyPointsService = loyaltyPointsService;
        _loyaltyPointsSettings = loyaltyPointsSettings;
    }

    public async Task Handle(CustomerRegisteredEvent notification, CancellationToken cancellationToken)
    {
        //Add loyalty points for customer registration (if enabled)
        if (_loyaltyPointsSettings.Enabled &&
            _loyaltyPointsSettings.PointsForRegistration > 0)
            await _loyaltyPointsService.AddLoyaltyPointsHistory(notification.Customer.Id,
                _loyaltyPointsSettings.PointsForRegistration,
                notification.Customer.StoreId,
                _translationService.GetResource("LoyaltyPoints.Message.EarnedForRegistration"));
    }
}