Try our conversational search powered by Generative AI!

Setting Epi_IsPublished Programatically

Vote:
 

Hi all,

I've seen other articles talking about using the APIs to get Epi_IsPublished to true to check that option in commerce programatically. I've tried doing it with the IContentRepository using

    var contentReference = episerverCommerceHelper.GetContentReferenceFromCode("Antibacterial-Viral-Filter_1");
    var item = contentWriter.Get(contentReference);
    var writableItem = item.CreateWritableClone();
    writableItem["Epi_IsPublished"] = false;
    contentWriter.Save(writableItem, SaveAction.Save, AccessLevel.NoAccess);

I've also tried getting the DTO object to see if I can set it but I can't see which value to set to do it this way, can someone advise

var item = CatalogContext.Current.GetCatalogEntryDto("Antibacterial-Viral-Filter_1");
#182626
Sep 26, 2017 16:16
Vote:
 

The metafield is not in DTO, but in the MetaObject attached to the Dto.

However why would you use DTO object, when you should use the content APIs?

#182629
Sep 26, 2017 17:24
Vote:
 

I don't want to do it with DTOs, I'm just trying things out at this stage, I'd rather use the IContentRepository as stated in my post, but how do you do it? There's no property I can find in the model and writableItem["Epi_IsPublished"] = false; doesn't work?

#182630
Sep 26, 2017 17:28
Vote:
 

Epi_IsPublished is a system property and the general guideline is to "not touch it".

If you want to unpublish the content, the best way is to make it expired (set the StopPublish property)

#182631
Sep 26, 2017 17:33
Vote:
 

I'm already expiring this, but it was explained to us in the Commerce course that the a content editor would be able to use this to easily mark a catalog item as unavalable. It just seems like a disconnect when if you create an item but don't save it it's Available false, then when you publish it it's Available true, then when you expire the content it's still Available True. It's like this is similar to the draft status in Episerver main but the naming of it isn't exactly intuitive for end users, I could easily see users if using the commerce manager instead of the canvas view getting confused.

I'll just mark it as expired for now, and we'll have to update our documentation for this project to indicate it.

Thanks for the help. 

#182632
Sep 26, 2017 17:55
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.