Get Current Website ID in magento2

Get Current Website ID in magento2:

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

$ecommerceHelper =$this->_objectManager->get('Jute\Ecommerce\Helper\Data');
$currentStoreID = $ecommerceHelper->getCurrentWebsiteId(); //Website ID
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;
 $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: Logo

You are commenting using your 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