我一直在尝试将产品导入Magento和图像。正在导入和创建产品,但图像无法导入。
我知道导入的基础知识,因为我过去已经做过,但无法弄清楚问题是什么以及下一步该做什么。
一些注意到我做了什么和做了什么:
答案 0 :(得分:0)
如果您有Mage_Catalog_Model_Product,您需要做的就是:
$fn = '/absolute/path/to/image.jpg';
$types = array('thumbnail', 'small_image', 'image'); // or null if you already have the product's thumbnail, small image, and image set
$move = true; // move the source file, don't leave it sitting around
$exclude = false; // enabled in product view
$label = 'Turquoise';
$product->addImageToMediaGallery($fn, $types, $move, $exclude); // Strictly speaking, only the first parameter is required
if(!empty($label)) {
$gallery = $product->getData('media_gallery');
$gallery_img = array_pop($gallery);
$gallery_img['label'] = $label;
array_push($gallery['images'], $gallery_img);
$product->setData('media_gallery', $gallery);
}
$product->save();
答案 1 :(得分:0)
我在上传产品图片时遇到了同样的问题。我测试了很多方法来解决这个问题。但没有任何帮助我。最后,在本教程之一中,我看到图像名称和sku名称必须相同。扩展名为。所以我遵循它并且通过上帝的恩典它起作用。你也可以尝试一下。它对我有用。我花了将近一整天的时间才弄明白。