1

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.

1 Answer 1

0

This don't work ? If not, then maybe the event has not happened yet.

protected $customerSession;

public function __construct(
        \Magento\Customer\Model\Session $customerSession
    ){
        $this->customerSession = $customerSession;
    }

public function getValueFromObserver()
{
   return $this->customerSession->getIpAddress();
}

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.