In magento 2 I am trying to update session_cutoff column in table customer_entity during login

Below is my code which I add in observer using event customer_login

public function execute(\Magento\Framework\Event\Observer $observer)

        $customer_data = $observer->getEvent()->getCustomer();
        $gtrustCustNo = $customer_data->getData('gtrust_custno');

        $param = array('custNo' => $gtrustCustNo);
        $result = $this->_gtrustApiHelper->getUserBenefit(($param));
        $customer = $this->customerFactory->create();
        $customer = $customer->setWebsiteId(1);
        // set sessionCutOff to null
        $customer = $customer->setSessionCutOff(NULL);
        $customer = $customer->loadByEmail($customer_data->getEmail());
        $customerData = $customer->getDataModel();       
        if (isset($result['resultData']['result']['usableSaveamt'])){
            $saveamt = $result['resultData']['result']['usableSaveamt'];
            $customerData->setCustomAttribute('customer_point', $saveamt);
        if (isset($result['resultData']['result']['usePbDeposit'])){
            $deposit = $result['resultData']['result']['usePbDeposit'];
            $customerData->setCustomAttribute('customer_deposit', $deposit);
        if (isset($result['resultData']['result']['usableCouponCnt'])){
            $coupon = $result['resultData']['result']['usableCouponCnt'];
            $customerData->setCustomAttribute('coupon_downloaded', $coupon);

As you can see I already added the $customer->setSessionCutOff(NULL); to set the customer session_cutoff to null but apparently when I try login the value doesnt change

I already var_dump to confirm whether the observer is being read or not, and able to see clearly that the soure code is being read and passed through during login

$customer->setWebsiteId(1) also didn't work I check, I already dicompile, upgrade and cache clean but nothing works

Please help check and advice on what is causing this issue

  • I think the method of ‘session_cutoff’ should be ‘ $customer->setSessionCutoff(NULL);’ Feb 21, 2023 at 15:37
  • @AmiyoGhosh when I try to use $customer->setSessionCutoff(NULL); it return error "Error: Call to undefined method Magento\Customer\Model\Data\Customer::setSessionCutoff()" Feb 22, 2023 at 5:33

1 Answer 1


I'm unsure of what you're trying to achieve with the customer factory and calling loadByEmail? Do you not already have the customer entity you want from the observer event? Seems you are assigning data to a new customer entity created by the customer factory, then reloading it using the email from the customer entity attached to the observer event?

Would something like this be better?

$customer = $observer->getEvent()->getCustomer();
$gtrustCustNo = $customer->getData('gtrust_custno');
$param = array('custNo' => $gtrustCustNo);
$result = $this->_gtrustApiHelper->getUserBenefit(($param));

$customerData = $customer->getDataModel();

I'd also advise you be more defensive with the rest of your logic, like asserting $gtrustCustNo contains the values you'd expect etc.

  • Thank you, the update is working now, but when I try use $customer->setSessionCutOff(null); I got error "Error: Call to undefined method Magento\Customer\Model\Data\Customer::setSessionCutOff()" Feb 22, 2023 at 4:08
  • Can you try $customer->setData('session_cutoff', null) instead of $customer->setSessionCutOff(null)? Feb 22, 2023 at 9:32

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.