且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Magento的API第2版PHP错误

更新时间:2023-10-28 15:22:46

(细节的Magento 1.6.x的特异性,但技术,如果没有详细说明,应适用于其它版本)

我假设的基础上,你的code样品,您使用的是PHP客户端code来测试方法,然后你就可以适用于从您的C#应用​​程序调用的存在?

假如是这样的话,就意味着你知道PHP的,所以你需要在Magento的SOAP服务器级别的PHP调试此。产生了故障。

中唯一的类文件
 应用程序/ code /核心/法师/原料药/型号/服务器/处理器/ Abstract.php

不管是临时的,直接添加以下记录到该文件,或在降类文件的副本

 应用程序/ code /本地/法师/原料药/型号/服务器/处理器/ Abstract.php

为codePOOL覆盖。

查找该类文件以下异常

 抛出新Mage_Api_Exception('resource_path_not_callable')

这是Magento的SOAP服务器是什么原因引起来的响应与错。有四个地方出现这种情况在该文件中。上方添加每一个记录的电话。

 法师::日志(sprintf的(行%S在文件%s',__ LINE__,__FILE__));
抛出新Mage_Api_Exception('resource_path_not_callable');

这将让你知道哪些故障导致您的问题,您可以从中进行调试,并进一步记录。有两个地方会发生这种情况(共四个文件中,一个是普通电话,另一个用于多方通话)。

为了美观,在评论可能的原因。

  //这里的Magento试图实例化API模型,将执行
//你的API调用的工作。在实例中,发现该模型
//不会从Mage_Api_Model_Resource_Abstract,并捞出继承。
//这是罕见的非定制的API调用,但可能由一类重写引起的
//横行了,还是很砍死系统
尝试{
    $模式=法师:: getModel($ MODELNAME);
    如果($模型的instanceof Mage_Api_Model_Resource_Abstract){
        $建模> setResourceConfig($资源 - > $资源名称);
    }
}赶上(例外$ E){
    法师::日志(sprintf的(行%S在文件%s',__ LINE__,__FILE__));
    抛出新Mage_Api_Exception('resource_path_not_callable');
}
//这里Magento的能够实例化$模型,并检查是否该方法
//调用。如果不是,它捞出。同样,对于一个标准的,股票API调用该不该
//是发生,但可能是一个改写了问题,或者有人黑客的结果
// API类,使非法入店,还是有人在黑客的api.xml映射方法
如果(is_callable(阵列(安培; $模式,$法))){
    如果(使用isset($&了MethodInfo- GT;参数)及及((字符串)$&了MethodInfo- GT;参数)=='阵'){
        返回$建模> $方法:((is_array($参数)$ args数组($参数))?)
    } ELSEIF(!is_array($参数)){
        返回$建模> $法($参数);
    }其他{
        返回call_user_func_array(阵列(安培; $模式,$法),$参数);
    }
}其他{
    法师::日志(sprintf的(行%S在文件%s',__ LINE__,__FILE__));
    抛出新Mage_Api_Exception('resource_path_not_callable');
}

弄明白为何Magento的抛出的API错误。它通常会指向一个类型的SOAP调用,或者是在你的PHP系统被黑客入侵为您指出

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.

(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