Magento API v2 PHP错误

Ste*_*Ste 5 php api soap magento

我正在尝试将SOAP与C#一起使用.Magento 1.4.2.

http://localhost/api/v2_soap/?wsdl
Run Code Online (Sandbox Code Playgroud)

在这里,我可以看到方法 catalogProductCreate

所以我尝试连接:

$proxy = new SoapClient('http://localhost/api/v2_soap/?wsdl');

$sessionId = $proxy->login('xxx', 'xxxxxx'); // user with full access

$newProductData                     = new stdClass();
$newProductData->name               = 'Product Name';
$newProductData->description        = 'Description';
$newProductData->short_description  = 'Short Description';
$newProductData->websites           = array(138);
$newProductData->categories         = array(7,15);
$newProductData->status             = 1;
$newProductData->price              = 45;
$newProductData->tax_class_id       = 2;
$newProductData->weight             = 1;


$result = $proxy->catalogProductCreate(
    $sessionId,           // Soap Session
    'simple',           // Product Type
    4,                  // Attribute Set Id (Default)
    'product-sku',      // Product Sku
    $newProductData     // Product Data
);
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个输出:

致命错误:未捕获的SoapFault异常:[4]资源路径不可调用.

Ala*_*orm 16

(具体是Magento 1.6.x,但技术,如果不是细节,应适用于其他版本)

我假设,根据您的代码示例,您正在使用PHP客户端代码来测试方法的存在,然后您可以将其应用于C#应用程序的调用?

假设是这种情况,这意味着您了解PHP,因此您需要在Magento soap服务器PHP级别进行调试.唯一产生该错误的类文件是

app/code/core/Mage/Api/Model/Server/Handler/Abstract.php
Run Code Online (Sandbox Code Playgroud)

将以下日志记录临时直接添加到该文件,或者删除该类文件的副本

app/code/local/Mage/Api/Model/Server/Handler/Abstract.php
Run Code Online (Sandbox Code Playgroud)

用于代码池覆盖.

在该类文件中查找以下异常

throw new Mage_Api_Exception('resource_path_not_callable')
Run Code Online (Sandbox Code Playgroud)

这就是导致Magento soap服务器响应该错误的原因.这个文件中有四个地方.在每个上面添加日志记录调用.

Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
throw new Mage_Api_Exception('resource_path_not_callable');
Run Code Online (Sandbox Code Playgroud)

这将让您知道哪个故障导致您的问题,您可以从中进行调试和进一步记录.有两个地方可以发生这种情况(文件中有四个,一个用于常规呼叫,另一个用于多呼叫).

在出现顺序,可能的原因在评论中.

//here magento is attempting to instantiate the "API Model" that will perform
//the work of your API call. Upon instantiation, it discovers that the model 
//doesn't inherit from Mage_Api_Model_Resource_Abstract, and bails.
//This is rare for a non-custom API call, but might be caused by a class rewrite
//gone amuck, or a very hacked system
try {
    $model = Mage::getModel($modelName);
    if ($model instanceof Mage_Api_Model_Resource_Abstract) {
        $model->setResourceConfig($resources->$resourceName);
    }
} catch (Exception $e) {
    Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
    throw new Mage_Api_Exception('resource_path_not_callable');
}


//Here Magento's been able to instantiate the $model, and is checking if the method is
//callable.  If not, it bails.  Again, for a standard, stock API call this shouldn't
//be happening, but could be the result of a rewrite gone wrong, or someone hacking an
//api class to make the method non accesible, or someone hacking the method mapping in api.xml
if (is_callable(array(&$model, $method))) {
    if (isset($methodInfo->arguments) && ((string)$methodInfo->arguments) == 'array') {
        return $model->$method((is_array($args) ? $args : array($args)));
    } elseif (!is_array($args)) {
        return $model->$method($args);
    } else {
        return call_user_func_array(array(&$model, $method), $args);
    }
} else {
    Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
    throw new Mage_Api_Exception('resource_path_not_callable');
}
Run Code Online (Sandbox Code Playgroud)

弄清楚为什么Magento会抛出API错误.它通常会指向您的soap调用中的类型,或者指向您在PHP系统中被黑客攻击的内容


小智 1

确保您可以使用 wsdl 资源是正确的,但是当我没有在角色下为用户设置正确的权限时,我也遇到了这个问题。