Skip to content

Instantly share code, notes, and snippets.

@DominicWatts
Created February 22, 2020 01:11
Show Gist options
  • Select an option

  • Save DominicWatts/7476c52d4a7bf3cf59bd320c43a8b040 to your computer and use it in GitHub Desktop.

Select an option

Save DominicWatts/7476c52d4a7bf3cf59bd320c43a8b040 to your computer and use it in GitHub Desktop.
Magento 2 : Get store information #magento2
class HelloWorld extends \Magento\Framework\View\Element\Template
{    
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,        
        array $data = []
    ) {            
        parent::__construct($context, $data);
    }
/**
     * Get store identifier
     * @return  int
     */
    public function getStoreId()
    {
        return $this->_storeManager->getStore()->getId();
    }
    /**
     * Get website identifier
     * @return string|int|null
     */
    public function getWebsiteId()
   {
        return $this->_storeManager->getStore()->getWebsiteId();
    }
    /**
     * Get Store code
     *
     * @return string
     */
    public function getStoreCode()
    {
        return $this->_storeManager->getStore()->getCode();
    }
/**
     * Get Store name
     *
     * @return string
     */
    public function getStoreName()
    {
        return $this->_storeManager->getStore()->getName();
    }
   
    /**
     * Get current url for store
     * @param bool|string $fromStore Include/Exclude from_store parameter from URL
     * @return string    
     */
    public function getStoreUrl($fromStore = true)
    {
        return $this->_storeManager->getStore()->getCurrentUrl($fromStore);
    }
    /**
     * Check if store is active
     * @return boolean
     */
    public function isStoreActive()
    {
        return $this->_storeManager->getStore()->isActive();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment