Developer forum

Forum » Development » Newsletter v3 new subscription

Newsletter v3 new subscription

Kevin Krämer
Reply

Hi

I have developed an Event signup custom module for a customer.

The customer has now requested that when somebody signups for one of severel events that they also can subscribe to their newsletter. 

So far i have figuered out how to get all Newsletter categories, so they on their own can choose wich Newsletter they will be subscribe to.

 

My problem now is, i have no clue of how to subscribe a person to the choose newsletter. 

 

It should be noted, that i have created my own seperate Table for the Event signup process, but that might bite me in the ass right now. 

 

I think i have to save a person again(If isnt already in the DB) in the database in order to subscribe to a newsletter, but im not sure wich classes to use in order to save a person, and afterwards subscribe to a newsletter.


Replies

 
Alexander Gubenko
Reply
This post has been marked as an answer

Hi Kevin,

Try to reuse(vb.net):

        Public Shared Sub MakeSubscription(subscriberEmail As String, fc As FrontendCategory)
            Dim recip As Recipient = Recipient.GetRecipientByEmail(0, subscriberEmail)
            If IsNothing(recip) Then
                Return '' or create new Recipient
            End If

            Dim subs As New Subscription()
            If fc.MailFormat = Constants.MailFormat.Both Or fc.MailFormat = 0 Then
                fc.MailFormat = Constants.MailFormat.HTML
            End If
            subs.MailFormat = fc.MailFormat
            subs.RecipientID = recip.ID
            subs.CategoryID = fc.ID
            recip.Subscriptions.Add(subs)
            recip.Save()
        End Sub

Votes for this answer: 1

 

You must be logged in to post in the forum