编辑Magento中的PDF地址
在Magento中编辑PDF是受限制的,但是如果你需要编辑的只是一个地址,你可以使用事件。
首先在config.xml中设置你的观测者:
<adminhtml>
<events>
<customer_address_format>
<observers>
<alwayly_sales_customer_address_format_observer>
<type>model</type>
<class>alwayly_sales/observer</class>
<method>addAdditionalDataToAddress</method>
</alwayly_sales_customer_address_format_observer>
</observers>
</customer_address_format>
</events>
</adminhtml>
在设置完观测者之后,你需要写代码来编辑地址模版:
/**
* Observer printing invoices in PDF
*
* @category Alwayly
* @package Alwayly_Sales
*/
class Alwayly_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']);
};
};
}
}
如果你想要获取最后一个用户的数据,你要使用Mage::getModel(‘customer/customer’) 对象。注意,用你自己的数据替换?????。我们获取地址模版并做修改。
电商网站开发服务。
版权声明:本站内容源自互联网,如有内容侵犯了你的权益,请联系删除相关内容。