Commerce 7.5 Nice to know
Even though EPiServer has made a lot of effort trying to make EPiServer and Commerce 7.5 appear as one united product there is still some areas you need to be aware of.
One example is user handling. Or more precise: authenticated users handling during a purchase. Let’s take a look at three scenarios where a customer is trying to add product A to his/hers basket:
Customer is an anonymous user:
This will work as anticipated. The product is added to basket and all is well.
Customer is a user created from Commerce Manager UI:
Also this scenario goes as planned.
Customer is a user created from EPiServer Admin UI:
This is where it all goes wrong!
What happens is you get this null reference exception:
[NullReferenceException: Object reference not set to an instance of an object.] Mediachase.Commerce.Workflow.Activities.CalculateDiscountsActivity.InitMarketingContext() Mediachase.Commerce.Workflow.Activities.CalculateDiscountsActivity.Execute(ActivityExecutionContext executionContext)
from running the
OrderGroupWorkflowManager.RunWorkflow(Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);
Without digging too much into this it looks like it is the casting of CurrentUseProfile to CustomerProfileWrapper in InitMarketingContext() that does it… Maybe.
Most likely you would create your customers through the EPiServer Commece API code during the checkout procedure or a create user page. But if you want to do it manually then you need to keep this in mind.
So if you’re developing a EPiServer Commerce 7.5 web site make sure to handle authenticated users “the commerce way”, and that is to create all your authenticated users from the Commerce Manager!