Subscription Date Fix

Print

Subscription Date Fix

So I wanted to know the date that users were subscribing or unsubscribing to newsletters.

I dove into the database to see if the newsletter subscription table had some sort of updated_at field, and there it was - change_status_at. At first I was joyful, then tears came to my eyes when I saw that the field always contained NULL.

I jumped screens and used the power of Goooogle to divine an answer from the internets. I soon found that others had run into this very issue and went away unanswered. There were even those who claim -

"that it used to work in very old versions of Magento, but doesn't anymore".

At a guess, I think what happened is that the field's definition used to be setup to magically update as a default timestamp (i.e. ON UPDATE CURRENT_TIMESTAMP), but that setting was lost in a past and long forgotten update. So there's no core Magento code that writes to the field because "it didn't have to".

So I put down my beer and put on my trusty Magento Certified Developer's thinking cap and bashed out a quick module that solves the problem by observing changes to the mystical event newsletter_subscriber_save_before and provides the missing date.

Now I'm here to share this solution with the anyone in the Mage Multiverse who might find need of it.

Install this little gem and you can take cat naps peacefully, knowing that you now have a time and date when someone subscribed (or unsubscribed) to your site's newsletter.