我被他们的产品无法显示的图像所困扰。当我创建一个产品并通过(管理产品)手动插入该产品的图像时,图像显示了这一点。然而,我们有1000多张产品图片需要上传,(所有的产品信息都已经准备好了,我只需要添加图片)我已导出产品CSV文件,工作图像地址为/n/g/image1.jpg然后我复制了它,但将图像更改为image2.jpg、image3.jpg等。然后我将新图像上传到我们服务器上的文件夹目录中,认为这就足够了。然后,我上传CSV文件,刷新缓存并重新索引数据,但没有显示新的图像,更糟糕的是,工作图像也没有显示。我已经在CSV中填写了图像、small_image和缩略图的详细信息。所有图像大小正确等。
此外,还可以告诉我,在存储我所有图像的目录中,哪里可以只有1个图像文件夹?感谢
我使用的是Magento版本1.7.0.2
首先,您的图像应该存储在media>import
目录中
然后在您的csv文件中只需写入image column/imagename.jpg
它会在导入目录中找到相同的图像名称,如果图像存在,它会上传图像
编辑
如果您没有导入目录,那么只需创建它
我很抱歉,但magento图像的幕后还有更多的事情,它只是在数据库中放入一个文件名并链接到您的图像。仅缓存生成就相当复杂。我相信你会很难按照你所尝试的方式去做。
话虽如此,我确实有一个建议。由于您的图像已经在服务器上,我建议您编写一个简单的php脚本,告诉magento将它们附加到产品图像上。这可能是自动化的,但我在下面给你举一个小例子。。。
要附加图像,只需导航到如下urlhttp://yoursite.com/imageattacher.php?sku=YOURSKU&image=yourimagefilename.jpg
剧本应该是这样的。。。在您的magento ROOT中创建一个文件,并将其命名为imageattacher.php。将您的图像上传到magento媒体导入目录。我还没有对此进行测试,但它应该有效。
<?php
// Initialize magento for use outside of core
umask(0);
require_once 'app/Mage.php';
Mage::app('admin');
// Get the variables from the URL
$sku = $_GET["sku"];
$imageName = $_GET["image"];
// get the image from the import dir
$import = Mage::getBaseDir('media') . DS . 'import/' . $imageName;
// Load the product by sku
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
// if the product exists, attempt to add the image to it for all three items
if ($product->getId() > 0)
{
// Add the images and set them for their respective usage (the radio button in admin)
$product->addImageToMediaGallery($import,array('image', 'small_image', 'thumbnail'),false,false);
// Make the changes stick
$product->save();
}
?>
看看这个http://www.danneh.org/2012/05/creating-products-programmatically-magento/
最终的问题是媒体目录下没有导入文件夹。图像已上载到此文件夹。CSV中的图像列被更改为/image1.jpg,这允许它们在网站上显示。
我最近不得不导入一堆Magento产品图像,这些图像都是按SKU命名的(例如123456.jpg)。这是我用来导入它们的脚本,其中部分基于CarComp的答案。它只适用于数字SKU(如123456),但可以很容易地修改以适应字母数字SKU。
<?php
require_once(__DIR__ . "/app/Mage.php");
Mage::app('admin');
class Sku_ImageLoader {
private $_uploadDir;
private $_imagePaths;
public function setUploadDirectory($dir = null) {
if (empty($dir)) {
if (isset($this->_uploadDir)) return $this;
$dir = 'upload';
}
$this->_uploadDir = Mage::getBaseDir('media') . DS . $dir;
// mkdir($this->_uploadDir . DS . "/loaded", 0770);
return $this;
}
public function load() {
$this->setUploadDirectory();
// Match product images like 123456.jpg
$pattern = '[0-9][0-9][0-9][0-9][0-9][0-9].{jpg,gif,png}';
chdir($this->_uploadDir);
$this->_imagePaths = glob($pattern, GLOB_BRACE);
return $this;
}
public function showFiles() {
$this->load();
echo "rnrnSorry, I wasn't able to upload the following image files in " . $this->_uploadDir . "rnrn<pre>rn";
print_r($this->_imagePaths);
return $this;
}
private function _addImage($path) {
$sku = (string)intval($path);
try {
echo "Loading SKU: {$sku} ... ";
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
// if the product exists, attempt to add the image to it for all three items
if (strpos(get_class($product), 'Catalog_Model_Product') !== false && $product->getId() > 0) {
$product->addImageToMediaGallery($path,array('image', 'small_image', 'thumbnail'),false,false);
$product->save();
echo " ok rn";
return true;
}
} catch (Exception $e) {
echo "Exception thrown for {$sku}: " . $e->getMessage() . "rn";
}
echo " (FAILED) rn";
return false;
}
private function _moveImage($path) {
// rename($path, 'loaded' . DS . $path);
unlink($path);
}
public function import() {
echo "<pre>rn";
if (!isset($this->_imagePaths)) $this->load();
foreach ($this->_imagePaths as $path) {
if ($this->_addImage($path)) {
$this->_moveImage($path);
}
}
return $this;
}
}
$u = new Sku_ImageLoader();
$u->import()->showFiles();
?>