Magento API v2 PHP 错误

发布于 2024-12-21 09:39:54 字数 1207 浏览 1 评论 0原文

我正在尝试将 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] 资源路径不可调用。

I'm trying to use SOAP with C#. Magento 1.4.2.

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

Here I can see the method catalogProductCreate

So I try to connect with:

$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
);

But I receive this output:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

香橙ぽ 2024-12-28 09:39:54

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

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

假设是这种情况,则意味着您了解 PHP,因此您需要在 Magento 肥皂服务器 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 肥皂服务器响应该错误的原因。该文件中有四个地方发生这种情况。在每个调用上方添加日志记录调用。

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 错误的原因。它通常会指向您的肥皂调用中的类型,或者指向您的 PHP 系统中被黑客攻击的内容

(details are Magento 1.6.x specific, but techniques, if not details, should be applicable to other versions)

I'm assuming, based on your code sample, that you're using PHP client code to test for the existence of a method, which you can then apply to a call from your C# application?

Assuming that's the case, it means you know PHP, so you'll want to debug this at the Magento soap server PHP level. The only class file that produces that fault is

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

Either add the following logging temporarily and directly to that file, or drop a copy of the class file in

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

for a codepool override.

Look in that class file for the following exception

throw new Mage_Api_Exception('resource_path_not_callable')

This is what causes the Magento soap server to response with that fault. There are four places this happens in that file. Add logging calls above each one.

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

This will let you know which fault is causing your problem, from which you can debug and log further. There are two places this can happen (four total in the file, one for a regular call, another for the multi-call).

In order of appearance, with possible causes in the comments.

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

Figure out why Magento is throwing the API error. It will often point to a type in your soap call, OR point you towards what's been hacked in your PHP system

紅太極 2024-12-28 09:39:54

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

Making sure that you can she the wsdl resource is correct, but i also ran into that issue when i didnt have the user set up to the correct permissions under the role.

巷子口的你 2024-12-28 09:39:54

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

Try to create a webservice user with role and assigned them to a role that has access to ‘ALL’. option in role resources menu in role information.

败给现实 2024-12-28 09:39:54

将此文件放入magento/project的根文件夹中,以便您可以访问magento的所有方法。

享受这个想法...

Put this file into root folder of magento/project so that you can access all the method of magento.

Enjoy the idea...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文