Get Category IDs for Product via Service Contract / API
-
29-09-2020 - |
Question
In Magento 2, is there a way to get the assigned category ids for a given product, via Service Contracts?
The CategoryLinkManagementInterface
API interface only has one method that returns the assigned products for a given category ID, but I need it the other way around.
Solution
I haven't found such method from the service contracts.
The only way I can see this working via a service contract is by using Magento\Catalog\Api\ProductRepositoryInterface
to get the product first (via get
or getById
) and then call getCategoryIds
on that product.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange