2

I would like to know the equivalent Magento 2 code to give me access to display these values on the frontend.

/* Name */
Mage::getStoreConfig('trans_email/ident_sales/name'); 

/* Email */
Mage::getStoreConfig('trans_email/ident_sales/email');

How to get store admin email address and name in Magento 2?

I have seen this solution but I do not understand the need for a Controller/Index in order to display values such as Store Email Address.

7

You have to create first block and defined function inside block for getting store name and store email, inside construct method pass ScopeConfigInterface object

Create the method getStoreName(), getStoreEmail()

    protected $scopeConfig;
    public function __construct(
        .......
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig        
    ) {
        ...
        $this->_scopeConfig = $scopeConfig;
    }

    public function getStorename()
    {
        return $this->_scopeConfig->getValue(
            'trans_email/ident_sales/name',
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }

 public function getStoreEmail()
    {
        return $this->_scopeConfig->getValue(
            'trans_email/ident_sales/email',
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }

Call function inside your template file, like echo $block->getStoreEmail() and echo $block->getStoreName();

  • If your extending from AbstractBlock, you'll already have $this->_scopeConfig defined. – Aaron Allen Jul 13 '16 at 5:14
2

Use these methods in your block class:

    public function getSalesEmail()
    {
        return $this->_scopeConfig->getValue(
            'trans_email/ident_sales/email',
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }

    public function getSalesName()
    {
        return $this->_scopeConfig->getValue(
            'trans_email/ident_sales/name',
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }

Call from the template like echo $block->getSalesEmail();

0

use Magento\Store\Model\ScopeInterface;

Then

$this->scopeConfig->getValue('trans_email/ident_support/email', ScopeInterface::SCOPE_STORE);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.