Created
December 20, 2017 11:34
-
-
Save 6ui11em/661b89618eeffbc40627e4f77a568a95 to your computer and use it in GitHub Desktop.
Magento2 get store information #magento2 #php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Chapagain\HelloWorld\Block; | |
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