Create Helper in magento 2
Helpers are very useful and needful elements. And beside this you can inject any dependency and call it to anywhere you need.
You can create Helpers like this….
<?php
namespace Magesan\Extension\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\StoreManagerInterface;
class Data extends AbstractHelper
{
/** /Magento\Framework\App\Config\ScopeConfigInterface $_scopeConfig */
protected $_scopeConfig;
/** /Magento\Store\Model\StoreManagerInterface $_storeManager */
protected $_storeManager;
/**
* __construct function
*
* @param ScopeConfigInterface $scopeConfig
* @param StoreManagerInterface $storeManager
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager
) {
$this->_scopeConfig = $scopeConfig;
$this->_storeManager = $storeManager;
}
/**
* getScopeConfig function
*
* @return void
*/
public function getScopeConfig($path, $storeId = null)
{
$storeId = $this->getStoreId();
return $this->_scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
}
/**
* getStoreId function
*
* @return int
*/
public function getStoreId()
{
return $this->_storeManager->getStore()->getId();
}
}
Hairstyles
Thanks for your article.
Beauty Fashion
Good to read this.
Freebies
Cool.
Hairstyles
I have been examinating out a few of your articles and i must say clever stuff. I will surely bookmark your blog.
Hairstyles
Wow! This could be one particular of the most helpful blogs We’ve ever arrive across on this subject. Basically Magnificent. I’m also an expert in this topic so I can understand your hard work.