【问题标题】:Magento - How to set media gallery images programmatically?Magento - 如何以编程方式设置媒体库图像?
【发布时间】:2012-02-14 14:39:10
【问题描述】:

我尝试设置一个新的 magento 产品图片,例如che_3.png 与:

$visibility = array (
   'thumbnail',
   'small_image',
   'image'
);
$product->addImageToMediaGallery( $file, $visibility, true, false);

产品图片从

临时目录:/media/tmp/catalog/product/upload/sessionid/original/che_3.png

目标目录:/media/catalog/product/c/h/che_3.png

现在,如果我想调用由 magento 保存的图像文件路径是错误的。 media_gallery 对象如下所示:

[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 扩展,并且两个项目添加到 media_gallery。

我的问题是如何分别重置产品内部计数器,以便 magento 使用原始文件?

提前致谢。

【问题讨论】:

  • 最好,第二个可能是缩略图,你检查两个图像尺寸是否相同?

标签: image magento product


【解决方案1】:

问题已解决:我用$product->save() 保存了两次产品,似乎$product->addImageToMediaGallery() 也被执行了两次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-24
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 2017-02-26
    相关资源
    最近更新 更多