Display customer's title in Print PDF invoice in Magento

I am trying to customize the PDF file created by the Print PDF button in our Magento admin.

After researching, I believe the file I need to modify is called: header.phtml

Here is the existing code:

<?php echo sprintf( '%s (%s)', $this->getCustomer()->getName(), $this->getOrder()->getBillingAddress()->getTitle() ); ?>

Open in new window


This is displaying the name as stored in the customer's Default Contact Address, followed by the title in parenthesis.

The problem is that it is displaying the incorrect title. I want it to show the title from the Default Contact Address, but it is displaying the title from a section in the customer information called Additional Address Entries.

I took a guess and tried changing my code to this:

<?php echo sprintf( '%s (%s)', $this->getCustomer()->getName(), $this->getCustomer()->getTitle() ); ?>

Open in new window


But that simply displays nothing in the parenthesis. Next, I tried this:

?php echo sprintf( '%s (%s)', $this->getCustomer()->getName(), $this->getOrder()->getShippingAddress()->getTitle() ); ?>

Open in new window


That seems to also display the incorrect title. How can I change this to display the Default Contact Address title rather than the others?

Thank you!
Brad BansnerWeb DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lenamtlCommented:
Not sure what you mean by title
If you are looking for the gender
$customer->getGender(); // ID

Check here there is a list of customer info you can display
http://www.kathirvel.com/magento-get-loggedin-customer-fullname-firstname-lastname-email-address/
0
Brad BansnerWeb DeveloperAuthor Commented:
I need the "title" of the customer (i.e., President, C.E.O., etc.). In my database, I see (among other things):

prefix
firstname
middlename
lastname
suffix
company
street
city
region
region_id
postcode
country_id
telephone
fax
title

That last one is what I need.

When I go to: https://www.mydomain.com/magento/customer/address/

...I see a Default Contact Address, Default Shipping Address and "Additional Address Entries". This:

$this->getOrder()->getBillingAddress()->getTitle()

Open in new window


Is pulling in the Additional Address Entries "title" field, for some reason. I'm trying to get the Default Contact Address "title" field instead, but not able to.
0
Brad BansnerWeb DeveloperAuthor Commented:
Also, I should point out, I'm not looking for the "title of the customer who is currently logged in". I'm in the admin interface generating a PDF of an invoice. I need the "title of the customer who placed the order".
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

lenamtlCommented:
Is title is a custom field, because by default this field is not on buyer account (maybe this have changed).
Are you using a third party extension for you invoice or for buyer account?
Are you using the Opensource version or other version?
0
Brad BansnerWeb DeveloperAuthor Commented:
Maybe it is a custom field. I'm not sure, because I took this project over from another company. I'm also not sure the answer to your other questions. The fact that you are saying this is not a default field definitely tells me something. If it is a custom field (which is my assumption at this point), is there some way to bring that data in and display it on the PDF? I understand that may be way outside the scope of this question.

Thanks.
0
lenamtlCommented:
Hi the Magento Version is displayed at the bottom of the page when you are logged in the backend.

If you can contact the previous company that may be useful to have more information about what the have customized.
And this will be important to know for future updates.

You can check the installed extensions related to invoice or account.
The extension can be in one of the following directory:
[MagentoFolder]/app/code/local/
[MagentoFolder]/app/code/community/

This is the Magento folder structure :
http://www.magentocommerce.com/wiki/2_-_magento_concepts_and_architecture/magento-folder-structure

To give you an idea how custom field work, this may help you to find the appropriate variable.
http://www.magentocommerce.com/wiki/5_-_modules_and_development/customers_and_accounts/registration_fields

There is a lot information you can find on Magento web site
http://community.magento.com/

If you have the enterprise edition
http://enterprise.magento.com/
0
Brad BansnerWeb DeveloperAuthor Commented:
Magento version: 1.8.1.0

Contacting the previous developer isn't really an option at this point, unfortunately.

Here are the folders within "community" and "local":

"community":
Belvg
Cm
Eltrino
IG
Magemaven
NextBits
OrganicInternet
ParadoxLabs
Phoenix
Widgento

"local":
Amasty
Greenacorn
MagePsycho
ParadoxLabs
ReadingThermal (client name)
Webcomm
Xtento

That seems like a lot? So all of those are various third-party extensions? It seems this is not going to be a simple change at all, even just changing one field like this. I may have to get a Magento sub-contractor involved, I think, unless there is some simple solution that I'm not understanding.

Thank you.
0
lenamtlCommented:
Yes you should hire someone that have experience with magento.
 Magento can be complicated even for experienced programmer.

Or if you find out the related extension, you can contact the extension author, you can get the info in readme file, or in the extension listed in the backend.

I think it is this extension have something for login so maybe related: http://www.magepsycho.com/

As you will see these company have a lot of extensions.

https://amasty.com/
http://www.greenacorn-websolutions.com/category/magento-extensions
http://www.magepsycho.com/
0
Brad BansnerWeb DeveloperAuthor Commented:
Here is the solution we arrived at:

//The 'company’ is a custom attribute added to a customer/address model.

//So we have access to a customer, lets get it’s ID:
$customer_id = $this->getCustomer()->getId();

//get handle to Magento’s model
$customerObj  = Mage::getModel('customer/address')->load($customer_id);

//get the custom attribute
$company = $customerObj->getData('company');
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brad BansnerWeb DeveloperAuthor Commented:
Thanks for your help and advice, this one was just a little more complicated. I hope this answer helps someone in the future.
0
Brad BansnerWeb DeveloperAuthor Commented:
Found the solution outside of EE.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
E-Commerce

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.