6

我被他们的产品没有显示的图像所困扰。当我创建产品并通过(管理产品)手动插入带有该产品的图像时,图像显示这很棒。但是我们有超过 1000 张产品图片需要上传,(所有产品信息都已经准备好了,我只需要添加图片)我已经导出了产品 CSV 文件,工作图片地址是 /n/g/image1.jpg然后我复制了它,但将图像更改为 image2.jpg、image3.jpg 等。然后我将新图像上传到我们服务器上的那个文件夹目录中,认为这就足够了。然后,我上传 CSV 文件,清除缓存并重新索引数据,但是没有显示新图像,更糟糕的是,工作图像没有显示。我已经在 CSV 中填写了图像、small_image 和缩略图详细信息。所有图像的大小都正确等。

更多信息可以告诉我在存储所有图像的目录中哪里可以只有 1 个图像文件夹?谢谢

我正在使用 Magento 版本 1.7.0.2

4

4 回答 4

14

First of all your image should store in media>import directory

then in your csv file just write in image column /imagename.jpg

it will find same imagename in import directory, if image exist then it will upload the image

EDIT

if you don't have import directory then simply create it

于 2013-08-28T12:06:40.750 回答
3

I'm sorry to say, but there is more going on behind the scenes with magento images that it simply putting a filename in the database and linking to your image. The cache generation alone is pretty complex. I believe you are going to have a hard time doing it the way you are attempting.

That being said, I do have a suggestion. Since your images are already on the server, I suggest you write a simple php script to tell magento to attach them to the product image. This could be automated, but i'll give you a small example below...

To attach an image, you would simply navigate to the url like this http://yoursite.com/imageattacher.php?sku=YOURSKU&image=yourimagefilename.jpg

The script would be like this... create a file in your magento ROOT and call it imageattacher.php. Upload your images to the magento media import directory. I have not tested this but it should work.

<?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();
    }

?>

See this http://www.danneh.org/2012/05/creating-products-programmatically-magento/

于 2013-08-28T12:21:45.610 回答
0

最后的问题是媒体目录下没有导入文件夹。图像已上传到此文件夹。CSV 中的图像列更改为 /image1.jpg,从而允许它们显示在网站上。

于 2013-09-16T10:00:48.480 回答
0

最近我不得不导入一堆 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 "\r\n\r\nSorry, I wasn't able to upload the following image files in " . $this->_uploadDir . "\r\n\r\n<pre>\r\n";
        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 \r\n";
               return true;
           }
        } catch (Exception $e) {
            echo "Exception thrown for {$sku}: " . $e->getMessage() . "\r\n";
        }
        echo " (FAILED) \r\n";
       return false;
    }

    private function _moveImage($path) {
        // rename($path, 'loaded' . DS . $path);
        unlink($path);
    }

    public function import() {
        echo "<pre>\r\n";
        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();
?>
于 2014-07-22T04:53:26.203 回答