Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

[11.8.5] Find variants based on metafield search?


I'm upgrading an old cms+commerce site from 7.5+. It uses the old ICatalogSystem.FindItems(...) to search for variations, based on the contents of two metafields.

That method is now obsolete, so I need to rewrite the code to use the content API instead. However, I can't figure out how to do a search (or filtering?) of all variants based on two metafields.

Can anyone point me in the right direction, please?

Jul 04, 2018 11:31

There is no equivalent APIs in ContentAPI for such requirements. You would have to call GetChildren and then filter on that.

Your best bet would be using Find ... 

Jul 04, 2018 11:46

I guess I can use FindItemsDto(...) instead and then just load the content items with IContentLoader...

Jul 04, 2018 11:50

It is a bit tricky because the query for filter by metafields was changed in Commerce 9. So now you can't really filter for two metafields, but only one. You would have to do two call and then combine the result (union or intersect)

I know that is a awkward limitation, but we can't really do anything about it now. 

Jul 04, 2018 11:58

I was kind of hoping not having to implement an external searching solution at this time, because there are a lot of things to rewrite (such as rewriting the cart functionality to use ICart, etc), and I have a rather limited time of doing the upgrade.

Yeah, a union/intersect should work now that searching for multiple metafields isn't possible anymore. And after testing searching for a single metafield using FindItemsDto() it looks to be a whole lot faster than the old FindItems() (mainly because it doesn't load everything the other one does).

Thanks! :)

Jul 04, 2018 12:37
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.