【问题标题】:Magento catalogProductAttributeMediaCreate() exceptionMagento 目录ProductAttributeMediaCreate() 异常
【发布时间】:2015-02-06 11:30:07
【问题描述】:

我正在使用 v2 SOAP Web 服务将图像上传到我的 Magento 服务器。我的 PHP 代码是:

// 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";
    }

每次我得到异常“产品不存在”。我已经检查过自己的产品是否存在于我的服务器中,并且我的 PHP 脚本和服务器中的 SKU 代码相同,但 API 方法不起作用。

¿ 它会是什么?我还尝试对我的一种产品的 SKU 进行“硬编码”,但也没有成功。

【问题讨论】:

    标签: php magento soap


    【解决方案1】:

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

    所以你的代码应该是这样的:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多