I am having the same category in 2 stores and on the custom page, I need category detail as per current store id. I am using the below code to get a category by using the category URL.
In block
public function getCategoryId()
{
$pfCategoryId = $this->categoryFactory->create()
->getCollection()
->addAttributeToFilter('url_key', 'category-url')
->addAttributeToSelect(['entity_id']);
return $pfCategoryId;
}
In phtml
$categoryId = $block->getCategoryId()->getFirstItem()->getEntityId();
Now I am having 2 stores. How to get store specific category id by using the category URL?