allBlogsList

Sitecore Experience Commerce: How to Add Execution Order to Your Plugin’s Pipeline Processor Configuration

A lot of Sitecore development is about pipelines and processors. This is Sitecore’s way of making sure that any out-of-the-box (OOTB) processes are extensible and configurable. Not to mention, one can always make a custom pipeline that include both custom and OOTB processors. Sitecore Experience Commerce (SXC) shares the same architecture which makes it highly extensible and customizable as well.

However, in some cases, SXC custom processors do not get configured or registered properly. In some cases, they are being outright ignored. Or are they?

Let’s investigate a little further and see a case like this and see a possible solution.

Read on.

Custom Sitecore Experience Commerce Processor

One day, you decided to create a custom processor that will do some additional checks and computations prior to the cart totals being generated. Let’s call our custom processor CustomLastMinuteCartCalculationsBlock.

We then decide to add our custom processor to the OOTB pipeline called ICalculateCartPipeline and specifically want it to trigger after the Plugin.Tax.CalculateCartTaxBlock. Figure 1 below shows our chosen placement for the custom processor.

Figure 1: X marks the spot for our custom processor placement

Adding Custom Processor to An OOTB Pipeline

Once we are done creating our custom processor, its time to add it to our chosen pipeline. Figure 2 shows our configuration code that adds CustomLastMinuteCartCalculationsBlock to ICalculateCartPipeline.

Figure 2: Custom Processor added to OOTB pipeline

Figure 3 shows are custom block added to the pipeline but unfortunately, it shows up at the top instead of the target place. We need to place it after Plugin.Tax.CalculateCartTaxBlock.

Figure 3: Our custom processor showing up on OOTB pipeline incorrectly

Adding Custom Processor to An OOTB Pipeline with Placement

Figure 4 shows our configuration code but now includes additional code. The code added tells Sitecore to add the custom block after Plugin.Tax.CalculateCartTaxBlock.

Figure 4: Custom Processor added to OOTB pipeline and AFTER a specific processor

However, we see that in Figure 5, our custom processor no longer shows up on the pipeline!

Figure 5: Our custom processor NOT showing up on OOTB pipeline

The Problem: Execution Order

Our custom block is not showing up after our chosen block (or not showing up at all!) for one reason only, and that is the target block doesn’t exist yet in the pipeline when the configuration code is executed. Instead of it adding it to the top in case the target block is not there, it doesn’t add it all.

This seems to be the default behavior of Sitecore, and I like it better this way since it takes a more cautious approach. Basically, if all its conditions are NOT met, it doesn’t get executed.

The Solution: Delaying the Custom Configuration

In Sitecore Experience Platform (SXP) we learned the valuable art of manipulating filename and folder names to specify an order of execution for configuration files. We add “Z” or “Y” for example to change the alphabetical order of things since Sitecore executes it that way.

Figure 6 shows a sample configuration folder and file name manipulation to influence execution order.

Figure 6: SXP configuration order manipulation using folder and file names

Taking a cue from SXP, we need to have a way to specify execution order. But since SXC doesn’t use configuration files, we look back at our configuration code.

Apparently, there is a way to specify execution order and somehow “wait” for the target block to be added first to the pipeline. This can make sure that when our custom configuration code gets executed, the pipeline processor exists, and our conditions will be met.

Figure 7: Custom Processor added to OOTB pipeline and AFTER a specific processor with EXECUTION ORDER

Figure 8 shows that with the addition of the execution order, we were able to meet the AFTER condition and our custom block was added.

Figure 8: Our custom processor showing up on OOTB pipeline at the RIGHT place

Summary

SXP and SXC share the same pipeline and processor architecture. However, they implement configuration in different ways. XP uses physical configuration files while XC uses code inside plugins. We learned that if the configuration conditions are not met once it executes, the processor configuration will not be done.

SXP uses file name manipulation to influence execution order while SXC uses additional parameters. Knowing both is a must for Sitecore Developers since it can save them a whole lot of headache and time.