php - Magento API v2 PHP 错误

标签 php api magento soap

我正在尝试将 SOAP 与 C# 结合使用。 Magento 1.4.2。

http://localhost/api/v2_soap/?wsdl

在这里我可以看到方法 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
);

但是我收到了这个输出:

Fatal error: Uncaught SoapFault exception: [4] Resource path is not callable.

最佳答案

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

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

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

app/code/core/Mage/Api/Model/Server/Handler/Abstract.php

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

app/code/local/Mage/Api/Model/Server/Handler/Abstract.php

用于代码池覆盖。

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

throw new Mage_Api_Exception('resource_path_not_callable')

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

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

这会让您知道是哪个错误导致了您的问题,您可以从中进一步调试和记录。有两个地方可能会发生这种情况(文件中总共有四个地方,一个用于常规调用,另一个用于多次调用)。

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

//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');
}

找出 Magento 抛出 API 错误的原因。它通常会指向您的 soap 调用中的一种类型,或者指向您的 PHP 系统中被黑的内容

关于php - Magento API v2 PHP 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8520970/

相关文章:

php - 如何为magento管理添加订单打印? Magento>销售>订单>订单打印

php - 如何使用 PHP 获取 HTML Div 的值

python - 如何找到发出 POST 请求所需的参数和 header ?

Magento 1.7.0.2 图像不存在

javascript - magento 编辑数量而不重定向到另一个页面

php - 在php后台运行url

javascript - 在头文件顶部导航中使用 AJAX Search Lite 插件 - WordPress

javascript - Catch() 不处理 404

java - 如何在数组响应android retrofit2中获取特定的响应数据

php - magento 管理员通过 curl 登录