volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Create Catalog In Code

Hi

Could someone please help me out on how to create a new catalog in code for EPiserver Commerce.

ICatalogContentCommitter ??

Kind Regards

Sandeep

#115265
Jan 12, 2015 17:15

Hi,

You could use IContentRepository, like with any other type of content. Something like this (untested):

var repository = ServiceLocator.Current.GetInstance<IContentRepository>();
var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>();
var root = referenceConverter.GetRootLink();

var catalog = repository.GetDefault<CatalogContent>(root);

catalog.Name = "My catalog";

repository.Save(catalog, SaveAction.Publish, AccessLevel.NoAccess);
#115269
Jan 12, 2015 18:46

Hi Johan

I had presumed that would be the case as I am using the above to create category nodes and product entries. However when I run th above code I get the following error 

No implementation of ICatalogContentCommitter available to handle content of type CatalogContentProxy

at EPiServer.Commerce.Catalog.Provider.CatalogContentCommitterHandler.GetCommitter(CatalogContentBase content)
at EPiServer.Commerce.Catalog.Provider.CatalogContentCommitterHandler.Save(CatalogContentBase content)
at EPiServer.Commerce.Catalog.Provider.CatalogContentDraftStore.<>c__DisplayClass2e.<CommitChanges>b__2d()
at EPiServer.Commerce.Catalog.Provider.CatalogEventHandler.ExecuteWithLocalEventsDiabled(Action action)
at EPiServer.Commerce.Catalog.Provider.CatalogContentDraftStore.CommitChanges(CatalogContentBase content)
at EPiServer.Commerce.Catalog.Provider.CatalogContentDraftStore.SaveInternal(CatalogContentBase content, SaveAction saveAction, String userName, Boolean forceCurrentVersion, Boolean newVersionRequired, Boolean delayedPublish)
at EPiServer.Commerce.Catalog.Provider.CatalogContentDraftStore.Save(IContent content, SaveAction saveAction)
at EPiServer.Commerce.Catalog.Provider.CatalogContentProvider.Save(IContent content, SaveAction action)
at EPiServer.DataFactory.Save(IContent content, SaveAction action, AccessLevel access)
at EPiServer.Commerce.Sample.Templates.Sample.Pages.ShoppingOverview.Page_Load(Object sender, EventArgs e) in c:\EPiServer7.5\EPiServerSiteMVC7.5DemoInstallerComm\wwwroot\Templates\Sample\Pages\ShoppingOverview.aspx.cs:line 116
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Kind Regards

Sandeep

#115270
Jan 12, 2015 19:19

Hmmm I don't know about the latest version of Commerce, but you had to create catalogs within Commerce Manager before. I thought that was fixed in later versions though.

#115271
Jan 12, 2015 19:27

Hi All

Found a solution. Aparently this was not supported in version 7.5. In Episerver Version 7.9 and above you can do it using the following. Please note the default properties below are mandatory -

var repository = ServiceLocator.Current.GetInstance<IContentRepository>();
            var referenceConverter = ServiceLocator.Current.GetInstance<Mediachase.Commerce.Catalog.ReferenceConverter>();
            var root = referenceConverter.GetRootLink();
            var catalog = repository.GetDefault<CatalogContent>(root);
            catalog.Name = "My catalog2";
            catalog.DefaultCurrency = "USD";
            catalog.DefaultLanguage = "en";
            catalog.WeightBase = "Pounds";
            repository.Save(catalog, SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);


Kind Regards

Sandeep

#115274
Jan 12, 2015 22:30
* 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.