Magento API v2 PHP 错误 [英] Magento API v2 PHP error

查看:21
本文介绍了Magento API v2 PHP 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

在这里我可以看到方法 catalogProductCreate

Here I can see the method 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] 资源路径不可调用.

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

推荐答案

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

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

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

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?

假设是这样,这意味着您了解 PHP,因此您需要在 Magento 肥皂服务器 PHP 级别调试它.产生该错误的唯一类文件是

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

用于代码池覆盖.

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

Look in that class file for the following exception

throw new Mage_Api_Exception('resource_path_not_callable')

这就是导致 Magento 肥皂服务器响应该故障的原因.该文件中有四个地方会发生这种情况.在每个调用上方添加日志记录调用.

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

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

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

这篇关于Magento API v2 PHP 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆