Change the Last Logged In date
-
16-10-2019 - |
문제
I'm trying to write a custom password reset script that adds rewards points to the accounts of all those that reset their passwords. A customised link to this will only be sent to the customers that have never logged into their account before (About 900 of them).
I need to know how to change the customer's last logged in date so that they can only get the rewards points once. This is the way I make sure that they haven't reset their password before.
$logCustomer = Mage::getModel('log/customer')->loadByCustomer($customer);
$lastVisited = $logCustomer->getLoginAtTimestamp();
if ($lastVisited == NULL)
{
// Reset password
// Add reward points to account
}
해결책
When the customer logs in, this date will be updated automatically. However, if you need to change this manually you can do so with the following statement:
$customerLog = Mage::getModel('log/customer')->loadByCustomer($customer);
$customerLog->setLoginAt('2013-12-31 00:00:00');
$customerLog->save();
다른 팁
You can get the last logged in date by the following code.
$customer = Mage::getSingleton('customer/session')->getCustomer();
$logCustomer = Mage::getModel('log/customer')->loadByCustomer($customer);
$lastVisited = $logCustomer->getLoginAtTimestamp();
$lastVisitedDate = date('Y-m-d H:i:s', $lastVisited);
This $lastVisitedDate
will update automatically by the system whenever the user logged in. S o if you want to keep this value freeze after first login of the user, then you will have to hard-code some value for this.
$lastVisitedDate = '2013-11-11 00:00:00';// the date you want to set.
$customer = Mage::getSingleton('customer/session')->getCustomer();
$logCustomer = Mage::getModel('log/customer')->loadByCustomer($customer);
$logCustomer->setLoginAtTimestamp($lastVisitedDate)->save();