Magento进口商图片

时间:2016-04-21 08:50:29

标签: image magento import

我试图在magento导入器中导入图像,但没有出现。我已经完成了所有的线索,我确信我已经做了我应该做的所有事情,现在我完全不知道问题是什么。

我创建了一个名为" import"的文件夹。在我的媒体"文件夹并放置图像' blog-1.jpg'在其中,我的数据保存在.csv中,它看起来与此类似:(为了便于阅读,我手动复制了这些条目)

sku - test1
name - test1
description - Test
short_description - Test
status - 1
visibility - 4
tax_class - 2
qty - 1
price - 1
weight - 1
image - /blog-1.jpg
image_label - Hello
small_image - /blog-1.jpg
small_image_label - Hello
thumbnail - /blog-1.jpg
thumbnail_label - Hello

当我"检查"我的数据显示数据很好并找到了一个字段。其他所有内容都可以正确导入,但是当我点击"图像"它没有图像。

1 个答案:

答案 0 :(得分:1)

首先,您的图片存储在media>import文件夹中。

然后在你的csv文件中写入图像列/imagename.jpg

如果图像存在,它将在导入文件夹中找到相同的图像名称,然后它将上传图像。

我很遗憾地说,但是幕后还有更多关于magento图像的内容,它只是将文件名放在数据库中并链接到您的图像。仅缓存生成非常复杂。我相信你会很难按照你的方式去做。

话虽如此,我确实有一个建议。由于您的图像已经在服务器上,我建议您编写一个简单的PHP脚本来告诉magento将它们附加到产品图像上。这可以自动化,但我会给你一个小例子......

要附加图片,您只需导航到此http://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();
    }
?>
相关问题