首页 文章

Magento API product_media.create因PEAR SOAP而失败

提问于
浏览
1

我正在尝试使用magento的SOAP api为产品添加图像,我可以使用标准 SoapClient 成功上传它,但如果我使用Pear SOAP_Client 则会失败

这是我正在做的 SoapClient

$image_data = array(
        'file' => array(
           'name' => 'test_image_name',
           'content' => $content,
           'mime'    => 'image/jpeg'
       ),
        'label'    => 'test_image_label',
        'position' => 1,
        'types'    => '',
        'exclude'  => 0
    );
$client = new SoapClient($wsdl_url);
$session_id = $client->login($mg_user, $mg_key);
$magento_filename = $client->call($session_id, 'product_media.create', array(
            $sku,
            $image_data
    ));

这将成功地将图像添加到产品中 .

但如果我使用 SOAP_Client

$client = new SOAP_Client($wsdl_url, true);
$session_id = $client->call(
    'login',
    array(
        'username'=>$mg_user,
        'apiKey'=> $mg_key
    )
);
$magento_filename = $client->call(
    'call',
    array(
        'sessionId'=>$session_id,
        'resourcePath'=>'product_media.create',
        'args'=>array(
            $sku,
            $image_data,
        )
    )
);

我得到了SOAPFault:“不能使用stdClass类型的对象作为数组”

但我可以调用catalog_product.info:

$info = $client->call(
    'call',
    array(
        'sessionId'=>$session_id,
        'resourcePath'=>'catalog_product.info',
        'args'=>array($sku)
    )
);

并返回所有正确的数据,没有错误 .

可能导致差异的原因是什么?

2 回答

  • 0

    我的解决方案,实际上根本没有解决方案,是用 --enable-soap 重新配置和重新安装php .

    但是根据他们的托管方案,这可能不是一个可行的解决方案 .

  • 0

    不要使用PEAR的SOAP包 . 它已经过时,并且在PHP SoapClient出现之前就已经使用过了 .

相关问题