0

I tried to retrieve it as:

\Magento\Store\Model\StoreManagerInterface $storeManager

and

$websiteId = (int)$this->storeManager->getWebsite()->getId();

But it returns null in cron class.

How to get website ID there?

| improve this question | | | | |
1

The cron is run on an Application level rather than a Website level. What i mean by that is, a single crontask needs to be able to handle all website / store views.

So you can either add an entry into the system config where you can set a website id and pull that into the crontask. Or iterate all the websites likes so.

$websites = $this->storeManager->getWebsites();
foreach($websites as $id => $website) {
    ....
}
| improve this answer | | | | |
0

Another option is to set current store in the cron task itself

https://magento.stackexchange.com/a/188727/70343

$this->_storeManager->setCurrentStore($this->_storeManager->getStore(0));

Then you can retrieve it

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.