$currentWebsite = $block->getCurrentWebsite(); is returning NULL even when the website has been well configured.

Where should I check in the databases or at the backend, in order to solve for this issue?

  • add your block class
    – fmsthird
    Commented Apr 24, 2019 at 9:51

1 Answer 1


Options : 1 (Using Object Manager)

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$store = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$storeId = $store->getStore()->getId();
$currentStoreID = $store->getStore($storeId)->getWebsiteId(); //Website ID
$currentStoreName = $store->getStore($storeId)->getWebsiteName(); //Website Name

Options : 2 (Using construct)

protected $storeManager;

public function __construct(
    \Magento\Store\Model\StoreManagerInterface $storeManager
    $this->storeManager = $storeManager;

public function getCurrentWebsiteId()
    $storeId = $this->storeManager->getStore()->getId();
    $currentStoreID = $this->storeManager->getStore($storeId)->getWebsiteId();
    $currentStoreName = $this->storeManager->getStore($storeId)->getWebsiteName();
    echo $currentStoreName; // Current Website Name
    return $currentStoreID;

You can add Options : 2 code in your block and access in phtml like echo $block->getCurrentWebsiteId();

I hope it will helpful for you.

  • This shows the Website ID, but I'd like to have the current website Commented Apr 24, 2019 at 10:03
  • Please check my updated answer. Commented Apr 24, 2019 at 10:10
  • @JulianMurillo is it working for you? Commented Apr 24, 2019 at 10:27
  • I get the website ID anyway; for Instance I expect 'Spain' -which is the current website- instead of '5' which is the website ID Commented Apr 24, 2019 at 10:39
  • Check my updated answer. You can now accept and upvote answer if it's helpful for you. So, other user will use this answer in their logic. :) Commented Apr 24, 2019 at 11:00

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.