I was recently tasked with debugging some faulty magento reset password email code. I have, I think, found the culprit of the faulty behavior but I am really confused as to how to resolve it. Here is my log:
2015-04-23T15:38:02+00:00 DEBUG (7): site id is: 1
2015-04-23T15:38:02+00:00 DEBUG (7): loaded customer by email
2015-04-23T15:38:02+00:00 ERR (3): Recoverable Error: Object of class Mage_Customer_Model_Customer could not be converted to string in /var/www/magento/apijson/customer/forgotPassword.php on line 30
2015-04-23T15:38:02+00:00 DEBUG (7): the customer is:
2015-04-23T15:38:02+00:00 DEBUG (7): new reset password link token generated
2015-04-23T15:38:02+00:00 DEBUG (7): resetToken is: 44bbce19e297c088c2bca9f97a21d020
2015-04-23T15:38:02+00:00 DEBUG (7): SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'entity_id' cannot be null, query was: INSERT INTO `customer_entity_varchar` (`entity_type_id`,`entity_id`,`attribute_id`,`value`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UP DATE `value` = VALUES(`value`)
Here is the reset email password code:
5 $customer = Mage::getModel("customer/customer");
6 Mage::log("site id is: ".Mage::app()->getWebsite()->getId());
7 $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
...
26 if ($email) {
27 try {
28 $customer->loadByEmail($email);
29 Mage::log("loaded customer by email");
30 Mage::log("the customer is: ".$customer);
31 $newResetPasswordLinkToken = Mage::helper('customer')->generateResetPasswordLinkToken();
32 Mage::log("new reset password link token generated");
33 Mage::log("resetToken is: ".$newResetPasswordLinkToken);
34 $customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
35 Mage::log("rest password link token changed");
36 $customer->sendPasswordResetConfirmationEmail();
37 Mage::log("password reset confirmation email sent");
38 } catch(Exception $e) {
39 Mage::log($e->getMessage());
40 }
From the log I know the code fails when it gets to the changeResetPasswordLinkToken function. However I don't understand why. I've looked online and googled a lot for the last couple of days but it seems I have stumbled onto a very unique issue. I did find this post that had an answer to my issue but unfortunately it did not work for me.
So my question for anyone who views this post is. Do you know what's causing the issue, and why changeResetPasswordLinkToken is failing? If there is a question similar to this one that you think will be of use please provide link since anything helps at this point. Thanks everyone.