Hey there!
How would i go about adding a notification-email to a eCom basket from c#?
I cant really find any documentation on this topic.
Thanks in advance
Jonas
Hey there!
How would i go about adding a notification-email to a eCom basket from c#?
I cant really find any documentation on this topic.
Thanks in advance
Jonas
Here you go: http://developer.dynamicweb.com/documentation/for-developers/ecommerce/extensibility/notifications/cart-v2.aspx
These are the notifications - do you need more specifics?
BR
Morten
Hi Morten, thank you.
Yes, i guess i dident make myself completely clear - Sorry about that.
I would like to set a new recepient on the moduleproperties of the cart module.
I tried this, but have to realise that its the wrong way down the path
Dynamicweb.eCommerce.Cart.ModuleSettings.MailInfo MI = new Dynamicweb.eCommerce.Cart.ModuleSettings.MailInfo(); MI.Recipient = User.Email; MI.SenderMail = "ordre@mail.dk"; MI.SenderName = "Forhandlershop Ordre"; MI.Subject = "Ordre fra " + User.Name; MI.TemplatePath = "/Files/Templates/eCom7/CartV2/Mail/v2_forhandler_bestilling.html"; MI.Template = "/Files/Templates/eCom7/CartV2/Mail/v2_forhandler_bestilling.html"; Paragraph.ModuleProperties.set_Value("Mails", MI.ToString());
Hi Jonas,
There really isnt an API for this, but it can still be done. Depending on where you want to inject the new mail notification.
Like Morten said, you can manually add a MailInfo into the ModuleSettings.Mails by subscribing to the SendMails notification, but you can also add a mail to the Paragraph settings permanently. This is a bit more tricky because, like you found out, the ModuleSettings object is one-way.
To do this, you need to get the paragraph for the specific cart you want to edit. Then you need to edit Properties object in the ModuleProperties property. Each mail setting is stored in the Properties internal Hashtable using the format: "Mail<Index><MailInfoProperty>" (except for AttachmentPath which is "Attachment_path" and TemplatePath which is "Template_path"). You need to traverse the keys in the Properties.Values.Keys and find the next index, then you need to add in your own values for each of the properties in the MailInfo (except Attachment properties, as they are not required). Then finally save the paragraph.
Something like this:
// Find the paragraph and get the Properties. var p = Paragraph.GetParagraphById(10); // Or whatever paragraph id you need var props = p.ModuleProperties; // Find the next index -- Start index is 1 var settings = new Dynamicweb.eCommerce.Cart.ModuleSettings(props); // Cannot be used to save the MailInfo var index = settings.Mails.Count() + 1; // You have to add 1 -- just the way it is! // This step can be skipped and add the values directly into the Properties var mi = new MailInfo() { Recipient = "recipient@domain.tld", SenderMail = "sender@domain.tld", SenderName = "The shop", Subject = "New order", Template = "/path/to/template.html", IsCustomer = false }; // Add values into the Properties // This can also be automated using reflection by looping through the PropertyInfos of mi (MailInfo) props.Values.Add("Mail" + index + "Recipient", mi.Recipient); props.Values.Add("Mail" + index + "SenderMail", mi.SenderMail); props.Values.Add("Mail" + index + "SenderName", mi.SenderName); props.Values.Add("Mail" + index + "Subject", mi.Subject); props.Values.Add("Mail" + index + "Template", mi.Template); props.Values.Add("Mail" + index + "IsCustomer", mi.IsCustomer); // Save the paragraph p.Save(); /* Available Properties values are: "Recipient" "Subject" "Template" "Template_path" -> Not used anymore "SenderName" "SenderEmail" "IsCustomer" "EncodingCodePage" -> Not used anymore, UTF-8 is always used "Attachment" -> Not used anymore "Attachment_path" All with this format: "Mail{index}{property}" */
- Jeppe
Hey Jeppe, thank you for the fast reply.
I did the following :
Dynamicweb.Content.ParagraphCollection par = Dynamicweb.Content.Paragraph.GetParagraphsByPageID(p.ID); foreach (Dynamicweb.Content.Paragraph para in par) { if (para.Header == "basketpara") { Dynamicweb.eCommerce.Cart.ModuleSettings Settings = new Dynamicweb.eCommerce.Cart.ModuleSettings(para.ModuleProperties); int index = Settings.Mails.Count() + 1; Dynamicweb.eCommerce.Cart.ModuleSettings.MailInfo MI = new Dynamicweb.eCommerce.Cart.ModuleSettings.MailInfo(); MI.Recipient = User.Email; MI.SenderMail = "ordre@afac.dk"; MI.SenderName = "Forhandlershop Ordre"; MI.Subject = "Ordre fra " + User.Name; MI.Template = "eCom7/CartV2/Mail/afac_v2_forhandler_bestilling.html"; MI.IsCustomer = false; para.ModuleProperties.Values.Add("Mail" + index + "Recipient", MI.Recipient); para.ModuleProperties.Values.Add("Mail" + index + "SenderMail", MI.SenderMail); para.ModuleProperties.Values.Add("Mail" + index + "SenderName", MI.SenderName); para.ModuleProperties.Values.Add("Mail" + index + "Subject", MI.Subject); para.ModuleProperties.Values.Add("Mail" + index + "Template", MI.Template); para.ModuleProperties.Values.Add("Mail" + index + "IsCustomer", MI.IsCustomer); para.Save(); } } }
I know that the code is run ( If i do Response.Write inside the codeblock, it outputs as expected. )
But the Mailinfo is not added to the module as expected.
Do you see what im doing wrong? :S
Try this instead of line 24:
para.ModuleSettings = para.ModulePropeties.ToString(); para.Save();
For some reason the ModuleSettings string needs to be refreshed as well.
That did it! Thank you.
Now, its only that stupid issue about the area. It's like theres some sort of cache or something. I have to either uplaod a dll and thereby refresh the pool, or log into the backend, select the website/area, and click "save" for it to persist the domain/lock and stuff like that. :/
Well,
thank you Jeppe
You must be logged in to post in the forum