如果产品SKU包含斜杠(/),则无法在magento api中创建图像

时间:2014-02-21 08:29:01

标签: magento magento-1.8

我正在尝试按照此magento doc中的相同代码通过magento image api创建图像。

除了SKU之外它的工作正常,包含斜杠(/)字符。

SKU:SPA-1XCHOC12/DS0

以下是httpd/error_log中显示的错误:

[Fri Feb 21 07:35:33 2014] [error] [client 8.35.201.40] PHP Fatal error:  Uncaught SoapFault exception: [104] Cannot create image. in /var/www/html/product_api/image.php:22\nStack trace:\n#0 /var/www/html/product_api/image.php(22): SoapClient->__call('call', Array)\n#1 /var/www/html/product_api/image.php(22): SoapClient->call('67da4ad39466d6e...', 'product_media.c...', Array)\n#2 {main}\n  thrown in /var/www/html/product_api/image.php on line 22

要确定确切的问题,我已添加此代码

$this->_fault('not_created', $e->getMessage());

中的

app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api.php

这就是错误:

[Fri Feb 21 07:41:56 2014] [error] [client 8.35.201.42] PHP Fatal error:  Uncaught SoapFault exception: [104] Folder 'SPA-1XCHOC12' isn't writeable in /var/www/html/product_api/image.php:22\nStack trace:\n#0 /var/www/html/product_api/image.php(22): SoapClient->__call('call', Array)\n#1 /var/www/html/product_api/image.php(22): SoapClient->call('7f82eac2c509869...', 'product_media.c...', Array)\n#2 {main}\n  thrown in /var/www/html/product_api/image.php on line 22

media/catalog/product文件夹权限为777。仍然显示相同的错误。

这是我的代码:

发布值为sku = 'SPA-1XCHOC12/DS0'image_url='http://example.com/11233.jpg'

$sessionId = $proxy->login($api_user, $api_pwd);  

$newImage = array(
     'file' => array(
        'name' => $_POST['sku'],
        'content' => base64_encode(file_get_contents($_POST['img_url'])),
        'mime'    => 'image/jpeg'
     ),
     'position' => 0,
     'types'    => array('small_image', 'image', 'thumbnail'),
     'exclude'  => 0
);

$imageFilename = $proxy->call($sessionId, 'product_media.create', array($_POST['sku'], $newImage));

1 个答案:

答案 0 :(得分:1)

由于你的图像是由你手动发送到例程的sku生成的,为什么不在那里清理它。它不会影响其他任何事情。

发布值为sku ='SPA-1XCHOC12 / DS0'和image_url ='http://example.com/11233.jpg'

$sessionId = $proxy->login($api_user, $api_pwd);  

// Replace slashes like waldek_c suggested
$sku_filename = str_replace("/","_",$_POST['sku']).".jpg";

$newImage = array(
 'file' => array(
    'name' => $sku_filename,     // Put filtered $sku_filename var here from above
    'content' => base64_encode(file_get_contents($_POST['img_url'])),
    'mime'    => 'image/jpeg'
),
 'position' => 0,
 'types'    => array('small_image', 'image', 'thumbnail'),
 'exclude'  => 0
);

$imageFilename = $proxy->call($sessionId, 'product_media.create', array($_POST['sku'], $newImage));

图片文件名为SPA-1XCHOC12_DS0.jpg,而不是SPA-1XCHOC12/DS0