How to get root category using store id in magento 2 block file?how to position block within category page?Magento 2 get current category Id using registryHow can i get different new products store wise?How to get the store id from the any category idMagento 2 - Multiple stores with different root categoryMagento get store Name in a file which is in root directoryMagento 2: How to get secure category URL programmatically?Get store ID by codemagento 2 get all category id of a specific store including all level nested child categoryGet Category URL multistore and multisite

Why does the 6502 have the BIT instruction?

Employer demanding to see degree after poor code review

Boots: Does light damage affect waterproofing?

Where can I find the list of all tendons in the human body?

Terminology about G- simplicial complexes

Is there an explanation for Austria's Freedom Party virtually retaining its vote share despite recent scandal?

File globbing pattern, !(*example), behaves differently in bash script than it does in bash shell

Looking after a wayward brother in mother's will

Uses of T extends U?

I think I may have violated academic integrity last year - what should I do?

What are the benefits of cryosleep?

Can the Help action be used to give advantage to a specific ally's attack (rather than just the next ally who attacks the target)?

Declining an unreasonable request from a superior

Which noble houses were destroyed during the Game of Thrones?

Smart people send dumb people to a new planet on a space craft that crashes into a body of water

Is it ok to put a subplot to a story that is never meant to contribute to the development of the main plot?

Is there any use case for the bottom type as a function parameter type?

Do firearms count as ranged weapons?

How is character development a major role in the plot of a story

How many chess players are over 2500 Elo?

How do Russian speakers idiomatically express the idea of "Ce n’est pas donné à tout le monde de ..." in French?

What are these (utility?) boxes at the side of the house?

Draw a checker pattern with a black X in the center

What F1 in name of seeds/varieties means?



How to get root category using store id in magento 2 block file?


how to position block within category page?Magento 2 get current category Id using registryHow can i get different new products store wise?How to get the store id from the any category idMagento 2 - Multiple stores with different root categoryMagento get store Name in a file which is in root directoryMagento 2: How to get secure category URL programmatically?Get store ID by codemagento 2 get all category id of a specific store including all level nested child categoryGet Category URL multistore and multisite






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















How to get root category using store id.
we get store id using $storeId = $this->getStoreId();
We use below code for get root category using store id; but we get wrong.



$rootCat = $this->_storeManager->getStore($storeId)->getRootCategoryId();


Any one help us for solve this.










share|improve this question
























  • No; we want store root category; which is assign in 'Store > Setting > All store > Here select any store > you show 'Root Category'.

    – Anil
    May 22 at 11:36

















2















How to get root category using store id.
we get store id using $storeId = $this->getStoreId();
We use below code for get root category using store id; but we get wrong.



$rootCat = $this->_storeManager->getStore($storeId)->getRootCategoryId();


Any one help us for solve this.










share|improve this question
























  • No; we want store root category; which is assign in 'Store > Setting > All store > Here select any store > you show 'Root Category'.

    – Anil
    May 22 at 11:36













2












2








2








How to get root category using store id.
we get store id using $storeId = $this->getStoreId();
We use below code for get root category using store id; but we get wrong.



$rootCat = $this->_storeManager->getStore($storeId)->getRootCategoryId();


Any one help us for solve this.










share|improve this question
















How to get root category using store id.
we get store id using $storeId = $this->getStoreId();
We use below code for get root category using store id; but we get wrong.



$rootCat = $this->_storeManager->getStore($storeId)->getRootCategoryId();


Any one help us for solve this.







magento2 blocks store-id root-category






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 at 5:30









Muhammad Anas

1,1703526




1,1703526










asked May 22 at 11:32









AnilAnil

698




698












  • No; we want store root category; which is assign in 'Store > Setting > All store > Here select any store > you show 'Root Category'.

    – Anil
    May 22 at 11:36

















  • No; we want store root category; which is assign in 'Store > Setting > All store > Here select any store > you show 'Root Category'.

    – Anil
    May 22 at 11:36
















No; we want store root category; which is assign in 'Store > Setting > All store > Here select any store > you show 'Root Category'.

– Anil
May 22 at 11:36





No; we want store root category; which is assign in 'Store > Setting > All store > Here select any store > you show 'Root Category'.

– Anil
May 22 at 11:36










2 Answers
2






active

oldest

votes


















2














You can use MagentoStoreModelStoreManagerInterface class to get store default root category Id.



<?php
class Test

/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $storeManagerInterface;

public function __construct(MagentoStoreModelStoreManagerInterface $StoreManagerInterface)

$this->storeManagerInterface = $StoreManagerInterface;




public function getRootCategoryId()

$store = 1;
return $this->storeManagerInterface->getStore($store)->getRootCategoryId();








share|improve this answer























  • We use it but not work for me

    – Anil
    May 22 at 11:43











  • what problem you are facing

    – surbhi agr
    May 22 at 11:46











  • Admin side page break; get error page can't reach. Not generate any error in log file.

    – Anil
    May 22 at 11:47



















1














I think something like this




namespace MyCompanyMyModuleBlock;

class MyModel extends MagentoFrameworkViewElementTemplate

protected $_storeManager;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoStoreModelStoreManagerInterface $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();





share|improve this answer























  • Page break in admin; page show 'This page isn’t working'.

    – Anil
    May 22 at 12:06











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f275668%2fhow-to-get-root-category-using-store-id-in-magento-2-block-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You can use MagentoStoreModelStoreManagerInterface class to get store default root category Id.



<?php
class Test

/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $storeManagerInterface;

public function __construct(MagentoStoreModelStoreManagerInterface $StoreManagerInterface)

$this->storeManagerInterface = $StoreManagerInterface;




public function getRootCategoryId()

$store = 1;
return $this->storeManagerInterface->getStore($store)->getRootCategoryId();








share|improve this answer























  • We use it but not work for me

    – Anil
    May 22 at 11:43











  • what problem you are facing

    – surbhi agr
    May 22 at 11:46











  • Admin side page break; get error page can't reach. Not generate any error in log file.

    – Anil
    May 22 at 11:47
















2














You can use MagentoStoreModelStoreManagerInterface class to get store default root category Id.



<?php
class Test

/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $storeManagerInterface;

public function __construct(MagentoStoreModelStoreManagerInterface $StoreManagerInterface)

$this->storeManagerInterface = $StoreManagerInterface;




public function getRootCategoryId()

$store = 1;
return $this->storeManagerInterface->getStore($store)->getRootCategoryId();








share|improve this answer























  • We use it but not work for me

    – Anil
    May 22 at 11:43











  • what problem you are facing

    – surbhi agr
    May 22 at 11:46











  • Admin side page break; get error page can't reach. Not generate any error in log file.

    – Anil
    May 22 at 11:47














2












2








2







You can use MagentoStoreModelStoreManagerInterface class to get store default root category Id.



<?php
class Test

/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $storeManagerInterface;

public function __construct(MagentoStoreModelStoreManagerInterface $StoreManagerInterface)

$this->storeManagerInterface = $StoreManagerInterface;




public function getRootCategoryId()

$store = 1;
return $this->storeManagerInterface->getStore($store)->getRootCategoryId();








share|improve this answer













You can use MagentoStoreModelStoreManagerInterface class to get store default root category Id.



<?php
class Test

/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $storeManagerInterface;

public function __construct(MagentoStoreModelStoreManagerInterface $StoreManagerInterface)

$this->storeManagerInterface = $StoreManagerInterface;




public function getRootCategoryId()

$store = 1;
return $this->storeManagerInterface->getStore($store)->getRootCategoryId();









share|improve this answer












share|improve this answer



share|improve this answer










answered May 22 at 11:38









surbhi agrsurbhi agr

51912




51912












  • We use it but not work for me

    – Anil
    May 22 at 11:43











  • what problem you are facing

    – surbhi agr
    May 22 at 11:46











  • Admin side page break; get error page can't reach. Not generate any error in log file.

    – Anil
    May 22 at 11:47


















  • We use it but not work for me

    – Anil
    May 22 at 11:43











  • what problem you are facing

    – surbhi agr
    May 22 at 11:46











  • Admin side page break; get error page can't reach. Not generate any error in log file.

    – Anil
    May 22 at 11:47

















We use it but not work for me

– Anil
May 22 at 11:43





We use it but not work for me

– Anil
May 22 at 11:43













what problem you are facing

– surbhi agr
May 22 at 11:46





what problem you are facing

– surbhi agr
May 22 at 11:46













Admin side page break; get error page can't reach. Not generate any error in log file.

– Anil
May 22 at 11:47






Admin side page break; get error page can't reach. Not generate any error in log file.

– Anil
May 22 at 11:47














1














I think something like this




namespace MyCompanyMyModuleBlock;

class MyModel extends MagentoFrameworkViewElementTemplate

protected $_storeManager;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoStoreModelStoreManagerInterface $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();





share|improve this answer























  • Page break in admin; page show 'This page isn’t working'.

    – Anil
    May 22 at 12:06















1














I think something like this




namespace MyCompanyMyModuleBlock;

class MyModel extends MagentoFrameworkViewElementTemplate

protected $_storeManager;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoStoreModelStoreManagerInterface $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();





share|improve this answer























  • Page break in admin; page show 'This page isn’t working'.

    – Anil
    May 22 at 12:06













1












1








1







I think something like this




namespace MyCompanyMyModuleBlock;

class MyModel extends MagentoFrameworkViewElementTemplate

protected $_storeManager;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoStoreModelStoreManagerInterface $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();





share|improve this answer













I think something like this




namespace MyCompanyMyModuleBlock;

class MyModel extends MagentoFrameworkViewElementTemplate

protected $_storeManager;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoStoreModelStoreManagerInterface $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();






share|improve this answer












share|improve this answer



share|improve this answer










answered May 22 at 11:59









Dominic XigenDominic Xigen

63511




63511












  • Page break in admin; page show 'This page isn’t working'.

    – Anil
    May 22 at 12:06

















  • Page break in admin; page show 'This page isn’t working'.

    – Anil
    May 22 at 12:06
















Page break in admin; page show 'This page isn’t working'.

– Anil
May 22 at 12:06





Page break in admin; page show 'This page isn’t working'.

– Anil
May 22 at 12:06

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f275668%2fhow-to-get-root-category-using-store-id-in-magento-2-block-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form