DEV Community

Arif
Arif

Posted on

3 2

Sitecore Commerce - Pipeline and Block

Introduction

Pipelines are the extension point of Sitecore and Sitecore Commerce. Although there is a difference in terms of how we implement from Sitecore to Sitecore Commerce.

Difference between Sitecore and Sitecore Commerce

In Sitecore, we register pipelines in Configuration files. We then register processors in those pipelines. There is no configuration approach in Commerce for pipelines. We need to register pipelines in code and then we can attach blocks in those pipelines. In Sitecore XM/XP, each of the processors has a PipelineArgs from where we can pass our data to the next processor whereas, in Commerce, the returned result of the first block will be used as an input to the next Block and so on.

Seriously, there is no config? then how to patch (i.e replace, after, before)

Let me give you couple of examples:

Example 1, Adding a new pipeline with a single block

public void ConfigureServices(IServiceCollection services)
        {
            var assembly = Assembly.GetExecutingAssembly();
            services.RegisterAllPipelineBlocks(assembly);
     services.Sitecore().Pipelines(config => config
             .AddPipeline<IMemberDiscountPipeline, MemberDiscountPipeline>(
                    configure =>
                        {
                            configure.Add<MemberDiscountBlock>();
                        })
      );
 }

Example 2

We are adding a block to a existing pipeline (ICalculateCartPipeline)

      public void ConfigureServices(IServiceCollection services)
        {
            var assembly = Assembly.GetExecutingAssembly();
            services.RegisterAllPipelineBlocks(assembly);

            services.Sitecore().Pipelines(config => config
             .ConfigurePipeline<ICalculateCartPipeline>(
                    configure =>
                    {
                        configure.Add<CalculateDiscountBlock>();
                    })
                        );
        }

Example 3

We are now replacing a block with our own block:

services.Sitecore().Pipelines(config => config
             .ConfigurePipeline<IMemberDiscountPipeline>(
                    configure =>
                    {
                        configure.Replace<MemberDiscountBlock, NewMemberDiscountBlock>();
                    })
      );

Example 4

We are now adding our own block a block after/before a certain block:

services.Sitecore().Pipelines(config => config
             .ConfigurePipeline<IAddCartLinePipeline>(
                    configure =>
                        {
                            configure.Add<SpecialDiscountBlock>().Before<ICalculateCartPipelineBlock>();
                        })
                        );

Pretty easy and cool, right? It's really important to know how many pipelines and blocks are there in the Commerce System and how they work together. In Sitecore, we have "showconfig.aspx" where we can see all of them together. But in Commerce, there is no such thing but a log where we can see. It's called node configuration. If we explore the commerce hosting directory, we will have a log in the following path: "wwwroot/log/NodeConfiguration_Deployment.....log". If we explore this file, we will see something like this:

Alt Text

Alt Text

This file should contain all of the registered (including your's one) with all the blocks associated with the pipelines.

How Sitecore Commerce Solution uses pipelines

Sitecore commerce already provides core pipelines and blocks. We just need to use them and as necessary we might need to add blocks to them and sometimes obviously we will need to create our own pipeline and we can push that to an existing pipeline. (A pipeline can hold not only blocks but also pipelines )

Conclusion

I hope now it's clear what is Commerce Pipeline and Block. I will use them to create our own feature in Commerce in my later articles. I will publish an article about the implementation of Pipeline and Block to solve a simple business problem in my next article.

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
🎥 Audio/video file upload with real-time preview
🗣️ Advanced transcription with speaker identification
⭐ Automatic highlight extraction of key moments
✍️ AI-powered article draft generation
📤 Export interview's subtitles in VTT format

Read full post

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay