我正在尝试向 Magento 1.6 添加一个新的地址模板,这样我就可以在我的货件 PDF 中输出为标签格式化的地址,并保持标准的 PDF 地址格式。
到目前为止,我已将文件 app/code/core/Mage/Customer/etc/config.xml 复制到本地代码池,并从现有模板中复制了 xml 并将其重命名为 . 以下是 config.xml 的相关部分
代码: app/code/core/Mage/Customer/etc/config.xml
第一部分:
<customer>
<address>
<formats>
<text translate="title" module="customer">
<title>Text</title>
</text>
<oneline translate="title" module="customer">
<title>Text One Line</title>
</oneline>
<html translate="title" module="customer">
<title>HTML</title>
<htmlEscape>true</htmlEscape>
</html>
<pdf translate="title" module="customer">
<title>PDF</title>
</pdf>
<js_template template="title" module="customer">
<title>JavaScript Template</title>
</js_template>
<add_label template="title" module="customer">
<title>Address Label</title>
</add_label>
</formats>
</address>
</customer>
第二部分:
<address_templates>
<text>
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}
{{depend company}}{{var company}}{{/depend}}
{{if street1}}{{var street1}}
{{/if}}
{{depend street2}}{{var street2}}{{/depend}}
{{depend street3}}{{var street3}}{{/depend}}
{{depend street4}}{{var street4}}{{/depend}}
{{if city}}{{var city}}, {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}
{{var country}}
T: {{var telephone}}
{{depend fax}}F: {{var fax}}{{/depend}}
{{depend vat_id}}VAT: {{var vat_id}}{{/depend}}
</text>
<oneline>{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}, {{var street}}, {{var city}}, {{var region}} {{var postcode}}, {{var country}}</oneline>
<html>
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}<br/>
{{depend company}}{{var company}}<br />{{/depend}}
{{if street1}}{{var street1}}<br />{{/if}}
{{depend street2}}{{var street2}}<br />{{/depend}}
{{depend street3}}{{var street3}}<br />{{/depend}}
{{depend street4}}{{var street4}}<br />{{/depend}}
{{if city}}{{var city}}, {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}<br/>
{{var country}}<br/>
{{depend telephone}}T: {{var telephone}}{{/depend}}
{{depend fax}}<br/>F: {{var fax}}{{/depend}}
{{depend vat_id}}<br/>VAT: {{var vat_id}}{{/depend}}
</html>
<pdf>
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}|
{{depend company}}{{var company}}|{{/depend}}
{{if street1}}{{var street1}}
{{/if}}
{{depend street2}}{{var street2}}|{{/depend}}
{{depend street3}}{{var street3}}|{{/depend}}
{{depend street4}}{{var street4}}|{{/depend}}
{{if city}}{{var city}},|{{/if}}
{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}|
{{var country}}|
{{depend telephone}}T: {{var telephone}}{{/depend}}|
{{depend fax}}<br/>F: {{var fax}}{{/depend}}|
{{depend vat_id}}<br/>VAT: {{var vat_id}}{{/depend}}|
</pdf>
<js_template>#{prefix} #{firstname} #{middlename} #{lastname} #{suffix}<br/>#{company}<br/>#{street0}<br/>#{street1}<br/>#{street2}<br/>#{street3}<br/>#{city}, #{region}, #{postcode}<br/>#{country_id}<br/>T: #{telephone}<br/>F: #{fax}<br/>VAT: #{vat_id}</js_template>
<add_label>
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}|
{{depend company}}{{var company}},|{{/depend}}
{{if street1}}{{var street1}},{{/if}}
{{depend street2}}{{var street2}},|{{/depend}}
{{depend street3}}{{var street3}},|{{/depend}}
{{depend street4}}{{var street4}},|{{/depend}}
{{if city}}{{var city}},|{{/if}}
{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}|
{{var country}}|
</add_label>
</address_templates>
然后我将 app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php 复制到本地代码池,并尝试使用以下代码输出我的新地址模板。
代码: app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php
$shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('add_label'));
$this->y = 170;
foreach ($shippingAddress as $value){
$page->drawText(strip_tags(ltrim($value)), 40, $this->y, 'UTF-8');
$this->y -=10;
}
但是输出的不是我的新地址模板,它似乎是某种默认模板。我已经刷新了缓存,但这并没有改变任何东西。有谁知道我哪里出错了?