I am trying to get the store number using a module the correct way and am having a bit of difficulty. I have used the below code which works however when trying to compile i recieve an error. My code is currently as below:
namespace Vendor\Module\Block;
class Contact extends \Magento\Framework\View\Element\Template
{
protected $_storeInfo;
protected $_storeManagerInterface;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Store\Model\Information $storeInfo,
\Magento\Store\Model\StoreManagerInterface $storeManagerInterface,
array $data = []
)
{
parent::__construct($context, $data);
$this->_storeInfo = $storeInfo;
$this->_storeManagerInterface = $storeManagerInterface;
}
public function getPhoneNumber()
{
return $this->_storeInfo->getStoreInformationObject($this->_storeManagerInterface->getStore(null))->getPhone();
}
}
This appears to work fine and number is shown on front-end as expected. However upon running 'bin/magento setup:di:compile' the following errors are shown and compilation fails.
Incorrect dependency in class Vendor\Module\Block\Storenumber
\Magento\Store\Model\StoreManagerInterface already exists in context object
I can see that the storeManager interface is already called within \Magento\Framework\View\Element\Template however removing this from construct also does not work. How do i correctly call the store number?