Posted on 02/10/2008 11:01:14
Sorensen wrote:
You shold go the other way around and see if the caregory already exists in the recipients Subscriptions list.
So, what are you saying is to change that code to this:
Dynamicweb.NewsLetterV3.RandomPassword randPwd = new RandomPassword();
Dynamicweb.NewsLetterV3.Recipient MyRecipient = new Recipient();
MyRecipient.RecipientType = Consts.RecipientType.User;
MyRecipient.AccessUserActive = true;
MyRecipient.AccessUserName = MyOrder.CustomerName;
MyRecipient.AccessUserEmail = MyOrder.CustomerEmail;
MyRecipient.AccessUserPassword = randPwd.ToString(); //make a random password or something
MyRecipient.AccessUserMobile = MyOrder.CustomerCell;
Dynamicweb.NewsLetterV3.Subscription MySubscription = new
Subscription(NewsletterListID, Dynamicweb.Modules.Common.Constants.MailFormat.HTML);
if (!MyRecipient.Subscriptions.Contains(MySubscription))
{
MyRecipient.Subscriptions.Add(MySubscription);
MyRecipient.Save();
}
Where the .Contains check if the user already have a subscription and if not, then I add and save, is that it?
By the way, do you know why does the system execute this twice every time? per each order I have 2 inserts of the same User / Email.
I use this code to get into the Notification Subscriber, both nothing else, should I have an IF somewhere?
[Subscribe(Dynamicweb.Notifications.eCommerce.Order.Steps.CustomerInfoHarvested)]
public class NewsletterSubscription : NotificationSubscriber
{
public override void OnNotify(string notification, object[] args)
{
//Code that gets myOrder and have the code above to add the subscription
}
}