1

我正在连接其他应用程序以使用 SOAP 在 Magento 1.9 中创建和更新客户。因为我希望密码保持完全相同,客户将被迫在其他应用程序中更改密码。更改后,我希望通过 SOAP 连接在 Magento 中更改密码,但我无法使其正常工作。在请求之后我得到“bool(true)”但似乎没有任何改变。

我做错了什么,还是 Magento 有限制。

我的代码:

<?php
//ensure you are getting error output for debug
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',1);

$client = new SoapClient('http://www.mymagentosite.com/api/v2_soap/?wsdl');

// If some stuff requires api authentification,
// then get a session token
$session = $client->login('apiuser', 'apikey');

// CustomerID search
$params = array('complex_filter'=>
    array(
        array('key'=>'email','value'=>array('key' =>'eq','value' => $email)),

    ),

);
$result = $client->customerCustomerList($session, $params);

var_dump ($result);

$customerID = $result[0]->customer_id;
// echo $customerID;

// Update Customer
$result2 = $client->customerCustomerUpdate($session, $customerID, array('password' => 'newpassword'));

var_dump ($result2);
4

1 回答 1

1

这很奇怪。文档(和 wsdl)希望您传递password参数。我试图在代码中进行调查(Magento 1.7 系列)。在设置您通过API调用传递的值之前,在文件的相应update()函数中app/code/core/Mage/Customer/Model/Customer/Api.php,有以下代码:

foreach ($this->getAllowedAttributes($customer) as $attributeCode=>$attribute) {
        if (isset($customerData[$attributeCode])) {
            $customer->setData($attributeCode, $customerData[$attributeCode]);
        }   
    }

所以,我尝试打印允许的属性,password但不存在。存在的是password_hash,但该字段在文档中不存在,更重要的是,在 wsdl 中也不存在。

只是为了进行测试,我尝试将md5我想要传递的密码的值作为password参数传递,然后,在_prepareData函数中调用的update函数中,我添加了这行代码:

$data['password_hash'] = $data['password'];

结果是密码修改成功,我可以用新密码登录了。

现在,当然这不是继续的方式。首先,我正在更改核心文件。然后,可能可以更新允许的属性列表添加password属性,但您必须记住构建密码的 md5 版本,而不是“明文”版本,并且无论如何将其重命名为password_hash某个地方。另一种解决方案是自定义(不是在core/,再次)与复杂类型相关的 wsdl 参数customerCustomerEntityToCreate,添加password_hash.

于 2015-07-30T10:19:36.183 回答