0

I have setup a cronjob in my custom module and it works fine. I know this because i put a PHP email script in there and I do in fact receive the email. The problem is with loading the customer model. It won't load the customer, much less save a customer attribute.

A few things: 1. Yes entity_id 50 does absolutely exist. 2. When I leave the first 3 lines in pendingApproval() I do not get the email. When i remove them I do get the email. 3. I have tried changing the email, firstname, lastname. Nothing. But this same code works when I run it in a controller in my browser.

Do i have the wrong current store or what? It's strange because I have another method in the same observer.php file and I make a call to the getModel('customer/customer') and it allows me to retrieve and save. However, it does not utilize a cronjob.

Any help is appreciated. Been messing with this for hours.

    <crontab>
    <jobs>
        <mycompany_referral>
            <schedule><cron_expr>*/1 * * * *</cron_expr></schedule>
            <run><model>referral/observer::pendingApproval</model></run>
        </mycompany_referral>   
    </jobs>
</crontab>  


<?php

class MyCompany_Referral_Model_Observer {

public function pendingApproval() {

    $customer = Mage::getModel('customer/customer')->load(50);
    $customer->setEmail('joebob@yahoo.com');
    $customer->save();

    $to      = 'myemail@email.com';
    $subject = 'alex';
    $message = 'ljoe';
    $headers = 'From: myemail@email.com' . "\r\n" .
        'Reply-To: myemail@email.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);  

}

}

1

Best thing I can suggest is to enable logging to see what is going on. Or you can wrap the save set of code in a try catch block so you can see if there is an exception being thrown.

try {
    $customer = Mage::getModel('customer/customer')->load(50);
    $customer->setEmail('joebob@yahoo.com');
    $customer->save();
} catch (Mage_Core_Exception $e) {
    Do something here with $e
}

You could also try calling validate on the customer object before calling save

  • Wow thanks for much for your comment. Simply wrapping it in a try catch fixed it. No error existed. – Alex Lacayo May 31 '14 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.