I have used below code to set the session in Observer file:
namespace VendorName\ModueleName\Observer;
use Magento\Framework\Event\ObserverInterface;
class ClassName implements ObserverInterface
{
protected $customerSession;
public function __construct(
\Magento\Customer\Model\Session $customerSession
){
$this->customerSession = $customerSession;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$this->customerSession->setIpAddress($_SERVER['REMOTE_ADDR']);
}
}
I want to access this session at app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php fetch() action.
I use the below code:
protected $customerSession;
public function __construct(
\Magento\Customer\Model\Session $customerSession
){
$this->customerSession = $customerSession;
}
$this->customerSession->getIpAddress();
Please help.