Convert Mage_Customer_Model_Customer Object to an array and convert again to object
-
22-10-2019 - |
سؤال
I had encrypted customer's firstname ,lastname and email and need to decrypt data to show in front end.
I will be Overriding public function getCustomer()
located at app/code/core/Mage/Model/Session.php
file.
Customer Data retrieved from
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
$customer->load($this->getId());
UPDATE
When ever i use print_r($customer)
to print data of logged in customer i get Mage_Customer_Model_Customer Object
.
Problem
I want to replace decrypted value of firstname,lastname and email with an array $customer['_origData:protected']
and $customer['_Data:protected']
since methods are protected so i have converted object into an array and converted again into an Object after passing decryption function , but converted Object is without protected methods.
I'm getting Fatal Error when converted Object is passed to function $this->setCustomer($customer);
What I want
Replace three encrypted values firstname , lastname and email in Object Mage_Customer_Model_Customer Object
Basic Question is :- How to Replace values in an object ?
المحلول
Use setData($key, $value)
to change _data
and setOrigData($key, $value)
to change _origData
.
Also, instead of setData('firstname', 'John')
you can always write setFirstname('John')
, even though the method is not declared, thanks to the "magic" getters and setters in Varien_Object
.
نصائح أخرى
I don't exactly understand your question, but if you want to convert an array to a stdClass instance here is a simple way to do it.
$arr = YOUR ARRAY HERE;
$encoded = json_encode($arr);
$obj = json_decode($encoded);