I'm attempting to implement encryption on certain customer data in a fresh install of Magento 1.9.3.6. I'm aware that this will cause numerous issues in the Magento dashboard, and probably elsewhere, but I'm just trying to put together a proof-of-concept.
I've succeeded in encrypting the data using the customer_address_save_before
event, I'm looking for a way to reliably decrypt the contents of the address each time it is loaded.
For now I'm working inside of the core Customer module until I get it working, at which point I'll move the code out into a module of it's own.
I've created a new function in the
app/code/core/Mage/Customer/Model/Observer.php
file, called afterAddressLoad
, which I have successfully managed to run by making use of another event. I've included the <events>
section of the config.xml file below, note the top two events are unchanged from the stock file:
<events>
<customer_address_save_before>
<observers>
<customer_address_before_save_viv_observer>
<class>customer/observer</class>
<method>beforeAddressSave</method>
</customer_address_before_save_viv_observer>
</observers>
</customer_address_save_before>
<customer_address_save_after>
<observers>
<customer_addres_after_save_viv_observer>
<class>customer/observer</class>
<method>afterAddressSave</method>
</customer_addres_after_save_viv_observer>
</observers>
</customer_address_save_after>
<customer_address_load_after>
<observers>
<customer_address_after_load_viv_observer>
<class>customer/observer</class>
<method>afterAddressLoad</method>
</customer_address_after_load_viv_observer>
</observers>
</customer_address_load_after>
</events>
The customer_address_save_before and customer_address_save_after events function fine, but the customer_address_load_after
does not fire at all when loading a customer address.
Changing the event to customer_load_after at least runs the function when the customer data is accessed, but then the contents of the $observer variable is the Customer object, not the Address object which I need to modify.
How can I do this? If the customer_address_load_after
event won't work, is there a way I can alter the contents of the loaded address by making use of some other event which fires each time the address is loaded?
Any help would be much appreciated!
EDIT: The relevant function in the Observer.php
file is below:
class Mage_Customer_Model_Observer
{
public function afterAddressLoad($observer)
{
Mage::log($observer);
}
}
This function runs fine when bound to other events, just not the customer_address_load_after
event. Caching is disabled on my install.