How to edit PDF address in Magento

Posted in Magento site management on February 24, 2012 0 comment(s)  

When you code in magento, maybe you will have question, how to edit PDF address in Magento.? You can do as following:

Editing PDF in Magento can be restrictive but if you need to edit just an address you can use events.

First set up your observer in config.xml:

----------------------------------------------------------------------------------

<adminhtml>
<events>
<customer_address_format>
<observers>
<inchoo_sales_customer_address_format_observer>
<type>model</type>
<class>inchoo_sales/observer</class>
<method>addAdditionalDataToAddress</method>
</inchoo_sales_customer_address_format_observer>
</observers>
</customer_address_format>
</events>
</adminhtml>

--------------------------------------------------------------------------

After obsever is set you need to set in code and edit address templates:

--------------------------------------------------------------------------

/**
* Observer printing invoices in PDF
*

*/
class Inchoo_Sales_Model_Observer
{
public function addAdditionalDataToAddress(Varien_Event_Observer $address)
{
$data = $address->getEvent();
if($data->type['code']=="pdf")
{
$customerData = $data["address"]->getOrder()->getData();
$customerId = $customerData['customer_id'];
//we are using customer object because it give us latest user data, if you want data from user on order creation use $customerData
$customer = Mage::getModel('customer/customer')->load($customerId);
$customerVariable = $customer->get?????;
//prevent of multiple insertion
if(strpos($data->type['default_format'],"Customer Variable")===false)
{
$stringToInsert = "{{var company}}|{{/depend}}|Customer Variable: ".$customerVariable."|";
$data->type['default_format'] = str_replace("{{var company}}|{{/depend}}",$stringToInsert, $data->type['default_format']);
};
};
}
}

------------------------------------------------------------------

If you use customer from order in PDF you get state from user in order state, if you wont get latest user data you have to use Mage::getModel(‘customer/customer’) object.
Replace ????? with your own data.

We are fetching address template and changing that template.

----------------------------------------------------------------

- From inchoo.net -


This post was posted in Magento site management

Leave a comments
Your email address will not published. Required fields are marked *

What Our Clients Say?

  • Oscar Soto MANAGER
    ArrowHiTech has always impressed me! They are professionals and are quick to response to my needs. I have used
    them in the past and will continue to use them in the future. Thanks Martin and all the Staff at ArrowHiTech!!!
  • The guys of AHT solutions did a perfect job and are real profesionals. Definitely recommend them and will use them again!
  • Jonatas Leonel MANAGER
    Martin has a great team of Magento experts, I really liked the work he did for me. I asked him to customize my template following a couple of jpg files that I got from a designer and he worked on that template without the psd's - that was awesome, the result I got was really good.
  • I really enjoy working with ahtsolutions. Quick response to our questions, delivery the project in time and excellent skills. I hope to work with them soon
Request us now! Yahoo:gravitational_boy Email:info@mage-shop.com Skype:hyun_yoo_it +84437955813