Try our conversational search powered by Generative AI!

Getting asset folder for NodeContent


We want to save a block in the asset folder for a NodeContent.

When we call contentAssetHelper.GetOrCreateAssetFolder we get null back. Reflecting the code it seems to be caused by the fact that NodeContent is not marked as IResourceable.

Strange thing is that this can be done in the Catalog UI. You can create a block and store it on a category. So it seems to be supported.

So how can this be achieved through the API?

Oct 19, 2017 12:45

I'm a bit confused here, but I think you are talking about different things. "You can create a block and store it on a category." => How do you do it? 

Oct 19, 2017 13:08

Is this related to having an "For this IContent" folder for catalog content?

That is an "For this node" that works like "For this page" in cms?

Oct 19, 2017 13:22

Sorry I was being unclear. We have a ContentArea on our category class (subclass of NodeContent).

In the Catalog UI, you can add the Block widget to the right pane.

Then you can see the "global" block folder in the upper part and in the lower part you get the section called "For this page" in CMS.

So I create a block there and drag it to the ContentArea on my NodeContent.

All is fine and dandy, and works exactly as in CMS.

But when I try to do the same thing from the API it is not working.

Edited, Oct 19, 2017 13:57

As I "suspected" - the Block you mentioned is just a property (it will be converted to a XHTML property to store in database, IIRC, but I don't trust my sleepy head right now). It has nothing to do with the IResourcable. 

Oct 19, 2017 14:02

Sorry for being unclear again =)

When we use the API we can only create blocks in the global folder.

Which is why we try to call GetOrCreateAssetFolder to get a reference to the asset folder for the specific content.

Upon reflecting that method we discovered that it returns null if the content does not implement IResourcable.

Your turn =)

Oct 19, 2017 14:09

What version of commerce is this?

The only thing i can create below "For all sites" are folders, there is no "For this node" as far as i know it is only available for Blocks and Pages.

Oct 19, 2017 14:10

We're on latest version -3 or so. You don't believe me Erik? :-P

Well, what can I say? It works perfectly in the UI. Exactly how we want it to be - and also how you would expect it to be (coming from CMS).

Problem is that the API does not seem to support this :(

So I would like to know what API is used in the Catalog UI!

Oct 19, 2017 14:15

No, there is no "For this site/For this category/For this whatever" when it comes to block and Catalog content. With catalog content it's always "global" 

Oct 19, 2017 14:18

Uhmm... I spoke with Erik and I guess I was fooled by the UI. It does look like there was a "For this" pane, but all the time we were creating blocks in the "For all sites" folder =)

Too bad though that this was not implemented for Commerce, as it is a nice feature in CMS. Maybe something to put in the backlog?

Thanks for the help!

Oct 19, 2017 14:41

Oh dear, I spoke too soon and it really is true what they say, Idle hands is the devil's play things.

Here you go Johan:

public class NodeDataModelBase : NodeContent, IResourceable
        public virtual string NodeContentAssetId { get; set; }

        public Guid ContentAssetsID
                if (!string.IsNullOrEmpty(NodeContentAssetId))
                    return new Guid(NodeContentAssetId);
                return Guid.Empty;
            set { NodeContentAssetId = value.ToString(); }

Go ahead and try it out, but I am in no way responsible for this hack. wink

Oct 19, 2017 14:51

Yes, I agree this is nice to have - I'll file a story so we won't forget about it.

However I'll be honest here, we have a bunch of "interesting" stuffs (interesting stuffs, and stuffs) in the backlog already - and it can take forever to get to this. So don't hold your breath :)

Oct 19, 2017 14:52

It seems Erik's solution works! So I guess you can remove it from the todo list, Quan cool

Oct 19, 2017 15:07

Nah, I insist :)

I see it's a valid scenario when you want to have resources only available to a specific catalog/category. I can imagine the editors would like to have that.

But of course I'm not the one who can decide - so I'll just leave it there. Maybe someday we look into it. 

Oct 19, 2017 15:12

If you do end up doing it Quan, you might want to do it for entries too and actually enable a built-in integration between that folder and the entry's assets.

Handling product images globally is quite a pain for editors at times.

Oct 19, 2017 15:18
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.