How To Intialiase the Episerver Commerce MetaClasses in Code

I've blogged previously about Adding a custom field into the commerce customer object via code.  After a recent upgrade to commerce, our DataContext.Current.MetaClasses always returned null in our Initialization module until the commerce migration script was run. A good example why you might want to use this is on your test server deployment. When you use a continuous integration process to deploy to a server, instead of using a central database server, you could delete and re-build the database on each deployment. You can then use fixtures to pre-populate your Episerver website with pages and blocks automatically. As part of this process, we want to include a test customer to be able to log-in.  If your customer also has custom properties then you need to make sure they are run when the application launches. If you have had a similar requirement pre-populating your objects before the migration script is run can be done. it's just not documented anywhere! Luckily, within CustomerContext.Current.GetContactById() there's a check to see if the customer object has been created yet if not, it will run a command to update database script to create the Customer MetaData class

CustomerContext.Current.GetContactById(Guid.Empty);

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top