2

I've created a customer attribute(file upload field) in the back end of magento: Customers > Manage Customer Attributes.

Now I want to show that this file has been uploaded in the customer's account center.

I can dump the attribute by:

$fileUpload = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'file_upload_code');
echo "<pre>";
print_r($fileUpload->getData());
echo "</pre>";

I can also see the file path that is being saved into the customer_entity_varchar table after a successful upload. But, I can't seem to figure out how to target that table. Each attempt at wording a search on google tends to bring up those attempting to pull data with SQL queries instead of using models.

I just want to do something such as:

$customer = Mage::getSingleton('customer/session')->getCustomer();
$fileUpload = Mage::getModel(customer/entity_varchar)->load($customer->getId())->getFileUpload();
  • I reckon $customer->getFileUpload() should do it if the customer has been loaded. – Raphael at Digital Pianism Jan 18 '16 at 21:53
  • I wonder what I'm doing wrong then. I've tried like 5 variations of $customer->getFileUpload()... – Front_End_Dev Jan 19 '16 at 0:47
  • also, if i do a print_r of: $customerData = Mage::getModel('customer/customer')->load($customer->getId())->getData(); My custom attribute isn't displayed. – Front_End_Dev Jan 19 '16 at 0:52
  • Have you set Show on Frontend for that customer attribute? – Adarsh Khatri Jan 19 '16 at 2:27
3

Try this:

$customer = Mage::getSingleton('customer/session')->getCustomer();
echo $customer->getFileUploadCode();

OR

$customer = Mage::getSingleton('customer/session')->getCustomer();
$customerData = Mage::getModel('customer/customer')->load($customer->getId());
echo $customerData->getFileUploadCode();
  • I feel like an idiot. These are both methods I knew and tried minutes into working on this. I had a file permissions issue that was preventing the file from uploading (my test account) and therefor was returning NULL. The live ones were showing which led me to believe it was working. – Front_End_Dev Jan 19 '16 at 16:32
  • can you share your file uploaded code? – Abdul Jan 20 '16 at 4:32
  • I just used the back end of magento: Customers > Manage Customer Attributes. – Front_End_Dev Jan 20 '16 at 14:33
  • Everything is working now. The problem was that the account I was logged in as didn't have that field populated in the database because of a file write permission. – Front_End_Dev Jan 20 '16 at 14:34

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.