I am working on fetching category URL for stores which are part of two different websites on a multiwebsite setup i.e abc.com and abc.co.uk, Issue happens when I fetch URL for abc.co.uk it returns me the URL of abc.com only. I have tried fetching with below solutions but none of them has worked:
1) Here in collection factory class I used is as below and latter is the code
\Magento\Catalog\Model\Category
$collection = $this->_categoryCollectionFactory->getCollection()->setStoreId($storeId)->addAttributeToSelect('*')->addIsActiveFilter();
2) I looped through all the categories and tried fetching it from repository
$this->categoryRepository->get($category->getEntityId(), $storeId);
3) Another solution tried with looping the categories fetched based on store id, looping it and generating URL as below, Although below URL provides me with a solution for correct website URL but still the category URL path is incorrect.
$this->storeManager->getStore($storeId)->getBaseUrl().$category->getUrlPath().$category->getUrlKey().$categoryUrlSuffix;
Any help or guidance on this would be much appreciated.