【问题标题】:Magento API v2 PHP errorMagento API v2 PHP 错误
【发布时间】:2011-12-15 13:38:51
【问题描述】:

我正在尝试将 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
);

但是我收到了这个输出:

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

【问题讨论】:

  • 错误的哪一部分你不完全理解?你能详细说明一下吗?
  • localhost/api/v2_soap/?wsdl在浏览器打开看看有没有catalogProductCreate这样的方法
  • 我知道这意味着我找不到该方法..但我可以在 xml 中看到它...我该如何解决这个问题?
  • 是的,我可以看到 catalogProductCreate 方法....
  • 这与 C# 有什么关系?

标签: php api magento soap


【解决方案1】:

(细节是 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');

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

按照出现的顺序,在 cmets 中有可能的原因。

//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系统中被黑客入侵的东西

【讨论】:

  • 2011-12-16T10:39:12+00:00 调试 (7): 文件 /usr/www/app/code/core/Mage/Api/Model/Server/Handler 中的第 295 行/Abstract.php
  • 记录 get_class($model) 和 $method。也许你在这个模型中没有这样的方法。
  • 我这里有同样的问题(第二个如果)。我记录了模型,我的方法在模型的方法列表中,但显然不可调用。权限规则适用于 ALL。
  • 我在我的测试服务器中完成了它并且它的工作。但在我的产品服务器中,我得到了 resource_path_not_callable 异常。
  • @DenisSpalenza 然后添加一些调试代码以查看 $model 和 $method 中的内容,并找出 PHP 认为它们不可调用的原因。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    尝试创建一个具有角色的 Web 服务用户,并将其分配给有权访问“ALL”的角色。角色信息中角色资源菜单中的选项。

    【讨论】:

      【解决方案4】:

      把这个文件放到magento/project的根目录下,这样你就可以访问magento的所有方法了。

      享受这个想法......

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多