5

I want replacement of the following in magento 2

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

or similar to getting current store admin name and email.

Thanks.

2 Answers 2

20

Try the below code -

<?php
namespace Custom\Module\Controller\Index;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class Index extends \Magento\Framework\App\Action\Action
{
    protected $request;
    protected $scopeConfig;

public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\App\Request\Http $request,
    ScopeConfigInterface $scopeConfig
){
    parent::__construct($context);
    $this->scopeConfig = $scopeConfig;
    $this->request = $request;
}

public function execute()
{
    $email = $this->scopeConfig->getValue('trans_email/ident_support/email',ScopeInterface::SCOPE_STORE);
    $name  = $this->scopeConfig->getValue('trans_email/ident_support/name',ScopeInterface::SCOPE_STORE);

    echo $email;echo "<br/>";
    echo $name;echo "<br/>";

    $this->_view->loadLayout();
    $this->_view->renderLayout();
}

}

3
  • I got information related to customer how to get regarding sales ??
    – Manish
    Apr 5, 2016 at 8:45
  • 1
    got it replacing 'trans_email/ident_support/email' with 'trans_email/ident_general/email'
    – Manish
    Apr 5, 2016 at 8:50
  • Thanks Accepted.....!!
    – Manish
    Apr 5, 2016 at 9:01
0

Use DI instead of direct Object manager use

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $scopeConfig = $objectManager->create('\Magento\Framework\App\Config\ScopeConfigInterface');
    $email = $scopeConfig->getValue('trans_email/ident_support/email',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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