is there a possibility to create a new message template, which allows to integrate an individual serial number into the message of a customer after successful payment?
This serial number should be read from a newly created table, which is always filled with serial numbers. When an order is paid, a serial number should be read from the table and sent with an email to the customer. The previously read serial number should then be removed from the table so that it can no longer be reused.
yes you can create a new message template then you could edit Libraries\Nop.Services\Messages\MessageTokenProvider.cs and create a new token that reads the serial number from the table
However, related to your other post, (https://www.nopcommerce.com/en/boards/topic/90973/license-key-manager), I suggest that you handle the Order Paid event, get your serial number from db, and post it to some field in the order (e.g. in the CustomValuesXml). Then, when you add the message token, you retrieve the stored serial number.
There is no step-by-step / example for all your requirments. See the above link for message token. See example plugins, like SendInBlue, for HandleEvent(OrderPaidEvent eventMessage)
I have already seen this plugin (https://github.com/kfoubert/nopcommerce/blob/master/Plugins/CustomMessageToken/4.1/Nop.Plugin.Misc.CustomToken/Infrastructure/CustomMessageTokenProvider.cs) and tried to implement it. Unfortunately some methods and properties of the classes have changed and I think also the general flow when inserting a new MessageToken. Is there possibly an easier way to insert a MessageToken without directly changing the SourceCode of nopCommerce? How can I even create a MessageToken that accesses the LicenseDownloadId (this attribute is in OrderItem and not in Order).
My approach now is the following: 1. Create a new table, which contains the license keys/serial keys (here I would have thought of using FluentMigrator in the Up() method, which, as I understood, is called during the first installation) - this table is then populated with already generated license keys (externally via SQL Server Management Studio, for example). 2. Creation of a MessageToken for the license key integration into the eMail. 3. As you already suggested, I will now use the OrderPaidEvent to read a license key from the newly created table and then insert it into the LicenseDownloadId table (OrderItem) and Download (the actual license file). Would anyone have a suitable tutorial for the current version where you can see how to access the database and how to insert new data?
Is there possibly an easier way to insert a MessageToken without directly changing the SourceCode of nopCommerce?
No - You can look at how the version you are using does it
stefanhummer wrote:
How can I even create a MessageToken that accesses the LicenseDownloadId (this attribute is in OrderItem and not in Order).
foreach (var item in order.OrderItems) { tokens.Add(new Token("OrderItem.LicenseDownloadId", item.LicenseDownloadId); }
stefanhummer wrote:
how to insert new data
You can use the routines that you create for accessing the new database table Or see Libraries\Nop.Services\Installation\CodeFirstInstallationService.cs which is how it is done for Install - you could use some parts of that routine and change for your database table as required