2015-02-06 32 views
1

我使用v2 SOAP Web服务将图像上传到我的Magento服务器。我的PHP代码是:Magento catalogProductAttributeMediaCreate()异常

// Session and other stuff... 
// 

$file = fopen ("magento_art.txt" , "r"); 
$data = fgetcsv ($file , 2048, "$", "\\"); 

while (($data = fgets ($file , 2048)) !== false) { 

    $data = str_replace('º', '&deg', $data); 
    $data = str_replace('"', '', $data); 
    $data = str_getcsv($data, "$"); 

    $path= 'fotos/'.$data[14]; 
    $type = pathinfo($path, PATHINFO_EXTENSION); 
    $raw_image = file_get_contents($path); 
    $base64 = 'data:image/' . $type . ';base64,' . base64_encode($raw_image); 
    $image = array(
     'content' => $base64, 
     'mime' => 'image/jpeg' 
    ); 

    var_dump($image); 
    echo "\n\n"; 

    try{ 
     print_r("SKU: ".$data[1]."\n\n"); 
     $result = $client->catalogProductAttributeMediaCreate(
      $session, 
      (string)$data[1], 
      array('file' => $image, 'label' => 'image', 'position' => '100', 'types' => ['image'], 'exclude' => 0) 
     ); 
    } 

    catch(Exception $e){ 
     echo "Exception: ".$e->getMessage()."\n\n"; 
    } 

而且每一次我得到异常'产品不存在'。我检查了我自己的产品存在于我的服务器中,SKU代码在我的PHP脚本和我的服务器中是相同的,但是API方法不起作用。

¿什么是?我也尝试了对我的某个产品的SKU进行“硬编码”,但这也不起作用。

回答

1

您需要传递最后一个参数,即表示您的标识符是什么。

所以,你的代码应该看起来像:

$result = $client->catalogProductAttributeMediaCreate(
      $session, 
      (string)$data[1], 
      array('file' => $image, 'label' => 'image', 'position' => '100', 'types' => ['image'], 'exclude' => 0), 
      'sku' 
     );