I think something like this
namespace MyCompany\MyModule\Block;
class MyModel extends \Magento\Framework\View\Element\Template
{
protected $_storeManager;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
array $data = []
)
{
$this->_storeManager = $storeManager;
parent::__construct($context, $data);
}
/**
* Get store identifier
*
* @return int
*/
public function getStoreId()
{
return $this->_storeManager->getStore()->getId();
}
/**
* Get root category id for current store
*
* @return int
*/
public function getRootCategoryId()
{
return $this->storeManagerInterface->getStore($this->getStoreId())->getRootCategoryId();
// or return $this->_storeManager->getStore()->getRootCategoryId();
}
}
So in your block template phtml you will use
$block->getRootCategoryId();