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;
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
add a comment |
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
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
add a comment |
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
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
magento2 blocks store-id root-category
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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();
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
add a comment |
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();
Page break in admin; page show 'This page isn’t working'.
– Anil
May 22 at 12:06
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
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
add a comment |
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();
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
add a comment |
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();
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();
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
add a comment |
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
add a comment |
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();
Page break in admin; page show 'This page isn’t working'.
– Anil
May 22 at 12:06
add a comment |
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();
Page break in admin; page show 'This page isn’t working'.
– Anil
May 22 at 12:06
add a comment |
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();
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();
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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