• Publisert
  • 1 min

Implementing IResourceable on Commerce entities

If you want the now beloved "For this page" sort of thing on Commerce entities, you have to do some work yourself. Here's how.

The reason for this, is that Commerce entities do not implement IResourceable out of the box. That very interface, is what provides EPiServer with the knowledge of how to handle the so called asset folder for a given content node. I guess this might be implemented in the future, but as of now, it is not.

1. Stick the interface onto your class

2. Short explanation:

IResourceable requires you to implement the public property Guid ContentAssetsID. Doing so is easy, but just leaving it as a standard auto property won't do you any good. That is why the virtual backing property ContentAssetIdInternal is present. This is what will actually be stored in the Commerce database. After you add this to your entity, that new column should show up in the corresponding database table. This enables EPiServer to store a reference to the content asset folder on the product.

I have not tried, but it might be possible to just directly implement this into the ContentAssetsId property - I took this advice from Linus Ekström in the forum thread linked below. I guess one reason to do it this way is to not screw up for possible future out-of-the-box-implementations of this interface. It's easier to migrate some data than to just guess wildly that a possible future implementation will follow your own train of thought. Or it might simply not work, for some reason. I'm not going to spend hours figuring that (and why) out, so if you try, feel free to give me a shout below.

This blog post has taken things from this forum thread, making the info slightly easier accessible.