Try our conversational search powered by Generative AI!

How to import product to episerver commerce and leave it as draft(not publish)

Vote:
 

Hi,

I am trying to write a custom import tool use CatalogImportExport  to import product to eppiserver and leave it as draft version, but i did not see any option to do it

Can anyone please give me the solution to this problem?

Here is my code

// Start import
using (var catalogXmlStream = new MemoryStream())
{
catalogXDoc.Save(catalogXmlStream);
// set stream pointer to beginning
catalogXmlStream.Seek(0, SeekOrigin.Begin);

// import back by episerver import export
CatalogImportExport cie = new CatalogImportExport();
cie.ImportExportProgressMessage += progressHandler.Invoke;
cie.Import(catalogXmlStream, true);
}

Thanks,

Thao Pham

#204184
May 22, 2019 5:31
Vote:
 

I think you have two options:

#204186
May 22, 2019 8:34
Vote:
 

Hi Quan,

When i set the IsActive of the entry to false it lead to product no longer display on front-end, is there any way to leave it as draff version like in a "AwaitingApproval/CheckedIn?

Thanks,
Thao Pham

#204190
May 22, 2019 9:02
Vote:
 

It should be still visible in Catalog UI. if you want it to be visible in view mode (For end users) then you would have to change the code to not filter it. 

#204191
May 22, 2019 9:18
Vote:
 

Hi Quan,

As i understand, if IsActive set to false, then entry will be change status publish to checkout. But i still want to keep the publish version in order to display on www and just create a draft version to pending aprroval

I try to decombine the code of episerver i can see two flash NeedToSyncDraft/NeedToSyncDraft

So can i use this flash to solve my issue?

/// <summary>Updates the catalog.</summary>
public void Save()
{
if (this.CurrentDto.Catalog == null || this.CurrentDto.Catalog.Count <= 0)
return;
CatalogAdmin.EnsureLanguagesContainsDefault(this.CurrentDto);
this.EnsureUriSegment(this.CurrentDto);
using (TransactionScope transactionScope = new TransactionScope())
{
HashSet<int> source = new HashSet<int>((IEnumerable<int>) this.CurrentDto.Catalog.Where<CatalogDto.CatalogRow>((Func<CatalogDto.CatalogRow, bool>) (row =>
{
if (row.RowState != DataRowState.Deleted)
return row.RowState != DataRowState.Added;
return false;
})).Select<CatalogDto.CatalogRow, int>((Func<CatalogDto.CatalogRow, int>) (row => row.CatalogId)));
IEnumerable<IBulkChangeItem<CatalogEntryChange>> changes = this.GetCatalogEntryChanges(this.CurrentDto);
DataHelper.SaveDataSetSimple(CatalogDataHelper.CreateDataCommand(), (DataSet) this.CurrentDto, CatalogAdmin._tableNames);
if (!CatalogContext.DisableVersionSync && (!this.CurrentDto.Items.Contains((object) CatalogEventArgs.NeedToSyncDraft) || (bool) this.CurrentDto.Items[(object) CatalogEventArgs.NeedToSyncDraft]))
{
this._catalogContentSync.CreateDraft(this.CurrentDto, PrincipalInfo.CurrentPrincipal.Identity.Name);
this._catalogContentSync.DeletePublishedVersionsOfInactiveContents(this.CurrentDto.Catalog.Where<CatalogDto.CatalogRow>((Func<CatalogDto.CatalogRow, bool>) (row => !row.IsActive)).Select<CatalogDto.CatalogRow, int>((Func<CatalogDto.CatalogRow, int>) (row => row.CatalogId)).ToArray<int>(), CatalogContentType.Catalog);
}
else if (CatalogContext.DisableVersionSync && !this.CurrentDto.Items.Contains((object) CatalogEventArgs.NeedToSyncDraft))
this._catalogContentSync.DeleteAllVersions(source.ToArray<int>(), CatalogContentType.Catalog);
TransactionScope.OnCommit((System.Action) (() => this._changeManager.NotifyChanges(changes)));
transactionScope.Complete();
}
}

Thanks,

Thao Pham

#204192
Edited, May 22, 2019 9:47
Vote:
 

Then you would have to use the second option.

#204193
May 22, 2019 9:49
Vote:
 

Hi Quan,

The second option is import one by one, that is not good solution, i prefer using CatalogImportExport to import by bactch

Any suggestion?

Thanks,

Thao Pham

#204194
May 22, 2019 10:12
Vote:
 

Unfortunately importing uses the lower layer level so it does not know anything about "versions". If you are importing with CatalogImportExport then there is no way to create new draft version while keeping the older version published.

#204197
May 22, 2019 12:38
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.