In other file I use this code to get base URL


where $this->storeManager is a instance of \Magento\Store\Model\StoreManagerInterface

My question is, how can I get base URL in cronjob? because the code gets store first before getting base url, and in cronjob, magento uses 0 as current store (Global store)

Any help would be appriciate.


1 Answer 1


I think before calling getBaseUrl() you need to set your current store then you can get correct URL.


Where $storeId is your store Id which you want the base URL.

  • Worked for me. Thanks :) Commented Apr 12, 2019 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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