Php 覆盖自定义模块中的客户地址模型

Php 覆盖自定义模块中的客户地址模型,php,magento,Php,Magento,我想在abstract.php中添加一个自定义函数,它位于app/code/core/Mage/Customer/Model/Address public function getCorrectAddress(){ $post_data['strret'] = '18334 W. Purdue Ave.'; $post_data['city'] = 'Waddell'; $post_data['state'] = 'AZ'; $post_data['zip'] =

我想在abstract.php中添加一个自定义函数,它位于
app/code/core/Mage/Customer/Model/Address

public function getCorrectAddress(){
    $post_data['strret'] = '18334 W. Purdue Ave.';
    $post_data['city'] = 'Waddell';
    $post_data['state'] = 'AZ';
    $post_data['zip'] = '85355';

    //traverse array and prepare data for posting (key1=value1)
    foreach ( $post_data as $key => $value) {
        $post_items[] = $key . '=' . $value;
    }

    //create the final string to be posted using implode()
    $post_string = implode ('&', $post_items);

    echo "post string=$post_string";
    echo"<br>";
    //create cURL connection
    $curl_connection = curl_init("http://www.example.com/.urlencode(json_encode($post_string))");

    //set options
    curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Content-Type:text/html;charset=utf-8',
      'Content-Length: '.strlen($post_string)
    ));
    curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

    //set data to be posted
    curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

    //perform our request
    $result = curl_exec($curl_connection);

    //show information regarding the request
    print_r(curl_getinfo($curl_connection));
    echo curl_errno($curl_connection) . '-' . curl_error($curl_connection);

    //close the connection
    curl_close($curl_connection);
    return $result;
}
公共函数getCorrectAddress(){
$post_data['strret']='18334西普渡大道';
$post_data['city']='Waddell';
$post_data['state']='AZ';
$post_data['zip']='85355';
//遍历数组并准备过帐数据(key1=value1)
foreach($key=>$value形式的post_数据){
$post_items[]=$key.'='.$value;
}
//使用内爆()创建要发布的最终字符串
$post_字符串=内爆(“&”,$post_项);
echo“post string=$post_string”;
回声“
”; //创建卷曲连接 $curl\u connection=curl\u init(“http://www.example.com/.urlencode(json_encode($post_string))”; //设置选项 curl_setopt($curl_连接,CURLOPT_连接超时,30); curl_setopt($curl_连接,CURLOPT_用户代理,“Mozilla/4.0(兼容;MSIE 6.0;Windows NT 5.1)”); curl_setopt($curl_connection,CURLOPT_RETURNTRANSFER,true); curl_setopt($curl_连接,CURLOPT_SSL_验证对等,false); curl_setopt($ch,CURLOPT_HTTPHEADER,数组( '内容类型:text/html;charset=utf-8', “内容长度:”.strlen($post_字符串) )); curl_setopt($curl_连接,CURLOPT_FOLLOWLOCATION,1); //设置要发布的数据 curl_setopt($curl_connection,CURLOPT_POSTFIELDS,$post_string); //执行我们的请求 $result=curl\u exec($curl\u connection); //显示有关请求的信息 打印(curl_getinfo($curl_connection)); echo curl\u errno($curl\u connection)。'-'.curl\u error($curl\u connection); //关闭连接 卷曲关闭($curl\u连接); 返回$result; }
并且该结果将显示在以下文本字段的edit.phtml页面中

<table>
    <tr>
        <td width="30%" valign="top">Street</td>
        <td width="2%">:</td>
        <td width="68%"><input name="Street" type="text" id="correctStreet" size="50" </td>
    </tr>           
    <tr>
        <td valign="top">City</td>
        <td valign="top">:</td>
        <td><input name="City" type="text" id="correctCity" size="50"></td>
    </tr>
    <tr>
        <td valign="top">State</td>
        <td>:</td>
        <td><input name="State" type="text" id="correctState" size="44"></td>
    </tr>
    <tr>
        <td valign="top">Zip</td>
        <td>:</td>
        <td><input name="Zip" cols="32" rows="4" id="correctZip"></textarea></td>
    </tr>
</table>
<input type="text" value="xyz" id="newcity">
<input type="submit" name="submit" value="This will real submit the form" />

大街
:

这个问题已经回答了

实现这一点的最佳方法是覆盖核心模型。 为此,请在模块的config.xml中添加几个节点:


...

<?xml version="1.0"?>
<config>
    ...
    <global>
        <models>
            <customer>
                <address>Your_Module_Model_Customer_Address</address>
            </customer>
        </models>
    </global>
    ...
</config>
<?php

class Your_Module_Model_Customer_Address extends Mage_Customer_Model_Address
{

    public function getCorrectAddress()
    {
        /**
         * Your custom code goes here...
         */
    }

}