If Sitecore XC sellable items are not getting published or it automatically removed (weird scenario) - It could be because you have not published sellable items correctly.
For the catalog import, there are a few options available - but if you want to use the Sitecore XC APIs, It's a good option to enable AutoApprovePolicy and remove once you finish your import.
If you are using the commerce core than you can set up this through the AutoApprovePolicy()
public class ImportCatalogsCommand : CommerceCommand
{
public IImportCatalogsPipeline ImportCatalogsPipeline
{
get;
}
public ImportCatalogsCommand(IImportCatalogsPipeline importCatalogsPipeline, IServiceScopeFactory serviceScopeFactory)
: base(serviceScopeFactory)
{
Condition.Requires(importCatalogsPipeline, "importCatalogsPipeline").IsNotNull();
ImportCatalogsPipeline = importCatalogsPipeline;
}
public virtual async Task
<CommerceCommand> Process(CommerceContext commerceContext, IFormFile importFile, string mode, int batchSize, int errorThreshold, bool publishEntities = true)
{
using (CommandActivity.Start(commerceContext, this))
{
CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.PipelineContextOptions;
ImportCatalogsArgument arg = new ImportCatalogsArgument(importFile, mode)
{
BatchSize = batchSize,
ErrorThreshold = errorThreshold
};
if (publishEntities)
{
commerceContext.Environment.SetPolicy(new AutoApprovePolicy());
}
ImportResult importResult = await ImportCatalogsPipeline.Run(arg, pipelineContextOptions).ConfigureAwait(continueOnCapturedContext: false);
if (importResult != null)
{
base.Messages.AddRange(importResult.Errors);
base.ResponseCode = importResult.ResultCode;
}
else
{
base.ResponseCode = commerceContext.GetPolicy
<KnownResultCodes>().Error;
}
if (publishEntities)
{
commerceContext.Environment.RemovePolicy(typeof(AutoApprovePolicy));
}
return this;
}
}
}
You can set up this directly in the policy during the import - If you are using the commerce API { "$type": "Sitecore.Commerce.Core.AutoApprovePolicy, Sitecore.Commerce.Core", }
No comments:
Post a Comment