【发布时间】:2012-09-19 02:57:33
【问题描述】:
在 Magento 中,以下代码将以编程方式将图片添加到产品的图片库中
//set store to admin id so we can save a product
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
//load a product with an id of 2514
$product = Mage::getModel('catalog/product')->load('2514');
//add the image
$product->addImageToMediaGallery('/tmp/test.png','image',false,false);
正如预期的那样,这会将图片添加到产品的媒体库中,并且该图片将被选为产品的“基础图片”。但是,不会为此图像选择“small_image”和“thumbnail”图像。
如果使用以下代码
$product->addImageToMediaGallery('/tmp/test.png','image',false,false);
$product->addImageToMediaGallery('/tmp/test.png','small_image',false,false);
$product->addImageToMediaGallery('/tmp/test.png','thumbnail',false,false);
Magento 将向媒体库添加 三个 新图像。一张选择了基本图片,一张选择了小图片,第三张选择了缩略图。
当你打电话时是否可以向 Magento 发出信号
$product->addImageToMediaGallery('/tmp/test.png','image',false,false);
它应该自动生成小图像和缩略图?
【问题讨论】: