I have a Sitecore Habitat Commerce Instance installed in my machine and everything is working fine.
I would like to extend the ICreateCustomerPipeline
to include a block to call my loyalty program. When I tried to register a customer through Sitecore Habitat Commerce registration page, it was able to register the user in Sitecore (have verified in User Manager and Commerce User).
But it would not redirect me to the account page (Without the custom block, it is able to redirect me after registration complete). No error is thrown in Sitecore CD and Commerce Authoring log.
My questions - How do we troubleshoot Sitecore SXA component if the log does not contain any relevant error?
Below is my block code (the issue still persist even I remove all the logic in this block)
public override async Task<Customer> Run(Customer arg, CommercePipelineExecutionContext context)
{
context.Logger.LogInformation("Running Customers.CreateLoyaltyCustomerBlock");
Condition.Requires(arg).IsNotNull($"{this.Name}: The argument can not be null");
string baseUri = @"http://localhost:8080";
string merchantId = @"00004";
string createUserUri = baseUri + @"/users";
var createUserhttpWebRequest = (HttpWebRequest)WebRequest.Create(createUserUri);
createUserhttpWebRequest.ContentType = "application/json";
createUserhttpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(createUserhttpWebRequest.GetRequestStream()))
{
string json = "{" +
"\"email\": \"" + arg.Email + "\"," +
"\"enabled\": true," +
"\"merchant_id\": \""+ merchantId + "\"," +
"\"name\": \"" + arg.Name + "\"," +
"\"password\": \"\"," +
"\"user_id\": \"" + arg.Id + "\"," +
"\"user_type\": \"\"" +
"}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse = await createUserhttpWebRequest.GetResponseAsync();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
context.Logger.LogInformation("Creating loyalty customer result: " + result);
//var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(result);
}
return arg;
}
Below is my ConfigureSitecore code (which is similar to Sitecore.HabitatHome.Feature.ProductKit.Engine
)
var assembly = Assembly.GetExecutingAssembly();
services.RegisterAllPipelineBlocks(assembly);
services.Sitecore().Pipelines(config => config
.ConfigurePipeline<ICreateCustomerPipeline>(builder => builder.Add<CreateLoyaltyCustomerBlock>().After<CreateCustomerBlock>())
.ConfigurePipeline<IConfigureServiceApiPipeline>(configure => configure.Add<ConfigureServiceApiBlock>()));
services.RegisterAllCommands(assembly);