Get Current Website ID in magento2

Get Current Website ID in magento2:

Below script will return the current website id in magento2 frontend.

Step:1
$ecommerceHelper =$this->_objectManager->get('Jute\Ecommerce\Helper\Data');
$currentStoreID = $ecommerceHelper->getCurrentWebsiteId(); //Website ID
Step:2
<?php
namespace Jute\Ecommerce\Helper;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Helper\View as CustomerViewHelper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper{
 protected $_storeManager;
 protected $_objectManager;
 protected $_customerViewHelper;

public function __construct(
 \Magento\Framework\App\Helper\Context $context,
 \Magento\Customer\Model\Session $customerSession,
 CustomerViewHelper $customerViewHelper,
 \Magento\Store\Model\StoreManagerInterface $storeManager,
 \Magento\Framework\ObjectManagerInterface $objectManager
 ) {
 $this->_customerSession = $customerSession;
 $this->_customerViewHelper = $customerViewHelper;
 parent::__construct($context);
 $this->_storeManager = $storeManager;
 $this->_objectManager = $objectManager;
 }
 public function getCurrentWebsiteId(){
 return $this->_storeManager->getStore()->getWebsiteId();
 }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s