I have a 2 website.
Now I'm accessing the admin panel using the
https://website.com/admin/catalog/category... Now when I save the categories I have an observer that generate the menu for each of this site. Take note that each website is using different root category. Upon clicking the save category button it generate an html file which contains the list of categories for each website. But the problem now is when I checked the generated url for
https://site.website.com/ it generates a category url of
https://website.com/secondsitecategory which I expect should be
Below is my code to retrieve the category in Magento 2
$subcategories = $category->getCollection() ->addAttributeToSelect('*') ->setStoreId($store->getId()) ->addAttributeToSort('position', 'ASC') ->addIdFilter($category->getChildren()) ->load();
$category->collection() is the root category of every website. I tried using emulator like
$this->_emulator->startEnvironmentEmulation($store->getId(), \Magento\Framework\App\Area::AREA_FRONTEND, true);
$category->getCollection() but it's not working. Would any one of you have an idea on how to solve this?