Image Magento-如何以编程方式设置媒体库图像?
我尝试设置一个新的magento产品图像,例如che_3.png:Image Magento-如何以编程方式设置媒体库图像?,image,magento,product,Image,Magento,Product,我尝试设置一个新的magento产品图像,例如che_3.png: $visibility = array ( 'thumbnail', 'small_image', 'image' ); $product->addImageToMediaGallery( $file, $visibility, true, false); 产品图像将从 临时目录:/media/tmp/catalog/product/upload/sessionid/original/cheu 3.pn
$visibility = array (
'thumbnail',
'small_image',
'image'
);
$product->addImageToMediaGallery( $file, $visibility, true, false);
产品图像将从
临时目录:/media/tmp/catalog/product/upload/sessionid/original/cheu 3.png
到
目标目录:/media/catalog/product/c/h/che_3.png
现在,如果我想调用由magento保存的映像文件路径,这是错误的。媒体库对象如下所示:
[media_gallery] => Array
(
[images] => Array
(
[0] => Array
(
[value_id] => 89
[file] => /c/h/che_3_2_1.png //che_3.svg is already in here
[label] =>
[position] => 1
[disabled] => 0
[label_default] =>
[position_default] => 1
[disabled_default] => 0
)
[1] => Array // why this second item?
(
[value_id] => 88
[file] => /c/h/che_3_2.png
[label] =>
[position] => 1
[disabled] => 0
[label_default] =>
[position_default] => 1
[disabled_default] => 0
)
)
[values] => Array
(
)
)
正如您所看到的,文件名由magento扩展,还有两个项目被添加到媒体库中
我的问题是,如何分别重置产品和内部计数器,以便magento使用原始文件
提前感谢。问题已解决:我用
$product->save()
保存了两次产品,似乎$product->addImageToDiagallery()
也执行了两次。最好的办法是,第二个可能是缩略图,您是否检查了两个图像尺寸是否相同?