November Happy Hour will be moved to Thursday December 5th.

Getting asset folder for NodeContent

Vote:
 

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?

#183670
Oct 19, 2017 12:45
Vote:
 

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? 

#183675
Oct 19, 2017 13:08
Vote:
 

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?

#183676
Oct 19, 2017 13:22
Vote:
 

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.

#183679
Edited, Oct 19, 2017 13:57
Vote:
 

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. 

#183680
Oct 19, 2017 14:02
Vote:
 

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 =)

#183682
Oct 19, 2017 14:09
Vote:
 

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.

#183683
Oct 19, 2017 14:10
Vote:
 

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!

#183684
Oct 19, 2017 14:15
Vote:
 

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" 

#183685
Oct 19, 2017 14:18
Vote:
 

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!

#183688
Oct 19, 2017 14:41
Vote:
 

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
    {
        [Editable(false)]
        public virtual string NodeContentAssetId { get; set; }

        [Ignore]
        public Guid ContentAssetsID
        {
            get
            {
                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

#183689
Oct 19, 2017 14:51
Vote:
 

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 :)

#183690
Oct 19, 2017 14:52
Vote:
 

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

#183693
Oct 19, 2017 15:07
Vote:
 

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. 

#183694
Oct 19, 2017 15:12
Vote:
 

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.

#183695
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.