Magento 1.6添加新地址模板

时间:2012-12-14 17:49:40

标签: php xml magento

我正在尝试向Magento 1.6添加新的地址模板,因此我可以输出格式化我的货件PDF中的标签的地址以及保留标准的PDF地址格式。

到目前为止,我已将文件app / code / core / Mage / Customer / etc / config.xml复制到本地代码池,并已从现有模板复制xml并将其重命名为。以下是config.xml的相关部分

代码: 应用程序/代码/核心/法师/客户的/ 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}}&lt;br/&gt;
                {{depend company}}{{var company}}&lt;br /&gt;{{/depend}}
                {{if street1}}{{var street1}}&lt;br /&gt;{{/if}}
                {{depend street2}}{{var street2}}&lt;br /&gt;{{/depend}}
                {{depend street3}}{{var street3}}&lt;br /&gt;{{/depend}}
                {{depend street4}}{{var street4}}&lt;br /&gt;{{/depend}}
                {{if city}}{{var city}},  {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}&lt;br/&gt;
                {{var country}}&lt;br/&gt;
                {{depend telephone}}T: {{var telephone}}{{/depend}}
                {{depend fax}}&lt;br/&gt;F: {{var fax}}{{/depend}}
                {{depend vat_id}}&lt;br/&gt;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}}&lt;br/&gt;F: {{var fax}}{{/depend}}|
                {{depend vat_id}}&lt;br/&gt;VAT: {{var vat_id}}{{/depend}}|
            </pdf>
            <js_template>#{prefix} #{firstname} #{middlename} #{lastname} #{suffix}&lt;br/&gt;#{company}&lt;br/&gt;#{street0}&lt;br/&gt;#{street1}&lt;br/&gt;#{street2}&lt;br/&gt;#{street3}&lt;br/&gt;#{city}, #{region}, #{postcode}&lt;br/&gt;#{country_id}&lt;br/&gt;T: #{telephone}&lt;br/&gt;F: #{fax}&lt;br/&gt;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;
}

但输出的不是我的新地址模板,它似乎是某种默认模板。我刷新了缓存,但这并没有改变任何东西。有谁知道我哪里出错了?

1 个答案:

答案 0 :(得分:0)

<强>!解决了Magento 1.7.0.2 - 目前尚未在v1.6中尝试过!

受到帖子的启发,我找到了自己的地址模板的解决方案。

这是我的模块配置只是一个演示模块

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <NAMESPACE_MODULE>
            <version>0.1.0</version>
        </NAMESPACE_MODULE>
    </modules>
    <global>

        ...

        <customer>
            <address>
                <formats>
                    <html_special translate="title" module="customer">
                        <title>HTML special</title>
                        <htmlEscape>true</htmlEscape>
                    </html_special>
                </formats>
            </address>
        </customer>

        ...

    </global>

    ...

    <default>
        <customer>
            <address_templates>
                <html_special><![CDATA[
MY SPECIAL HTML ADDRESS
{{depend company}}{{var company}}<br />{{/depend}}
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}<br/>
{{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 postcode}}{{var postcode}} {{/if}}{{if city}}{{var city}}{{/if}}<br/>
{{var country}}<br/>
{{depend telephone}}Tel: {{var telephone}}{{/depend}}
{{depend fax}}<br/>Fax: {{var fax}}{{/depend}}
                ]]></html_special>
            </address_templates>
        </customer>
    </default>

</config>

我猜你没有将<address>...</address>放入<global>区块?!