I'm trying to understand virtual types and how we can use them in practicalpractice. Referred some code from the vendor, still its, it is giving me an error when imI'm trying to access inthe helper class.
namespace Ravi\Learn\Helper;
use Magento\Framework\App\Helper\Context;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
* @var \Magento\Customer\Model\Session
*/
protected $customerSession;
public function __construct(Context $context, $customerSession)
{
parent::__construct($context);
$this->customerSession = $customerSession;
}
public function getSess(){
return $this->customerSession->getId();
}
}
Below is the code for di.xml
file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="Ravi\Learn\Helper\Data\Session" type="Ravi\Learn\Helper\Data">
<arguments>
<argument name="customerSession" xsi:type="object">Magento\Customer\Model\Session</argument>
</arguments>
</virtualType>
</config>