簡體   English   中英

Magento API v2 PHP錯誤

[英]Magento API v2 PHP error

我正在嘗試將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]資源路徑不可調用。

(具體是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系統中被黑客攻擊的內容

嘗試創建具有角色的Web服務用戶,並將其分配給可以訪問“ALL”的角色。 角色信息中角色資源菜單中的選項。

確保你可以使用wsdl資源是正確的,但是當我沒有讓用戶在角色下設置正確的權限時,我也遇到了這個問題。

將此文件放入magento / project的根文件夾中,以便可以訪問magento的所有方法。

享受這個想法......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM