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?
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 ...
I guess I can use FindItemsDto(...) instead and then just load the content items with IContentLoader...
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.
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).