zoukankan      html  css  js  c++  java
  • [转]解决Magento批量导入带图片的商品的问题

    本文转自:http://www.phpstudio.info/show-121-791-1.html

    一般来说,Magento后台管理里的CSV批量导入,可以解决我们商品批量上传的大部分问题,我们只要根据导出的属性字段,设置好格式,可以实现大部分商品的导入,但是有时候使用Magento批量导入带图片的商品却是十分的麻烦,我们只需要注意以下几点,就可以基本实现Magento产品图片的批量导入和显示了。

    一、导出Magento CSV商品属性

    我们要上传前,先在Magento中创建几个商品,再在System->Import/Export->Export All Product->Save and Continue Editing->Run Profile,运行之后,就会在Magento目录下的var/export里创建个CSV,我们可以把这个CSV格式下载到本地,用CSV编辑工具来创建Magento批量上传的商品,Magento笔记推荐使用Open Office来编辑CSV文件格式。

    二,设置CSV图片文件字段属性

    我们在编辑CSV图片文件路径字段时候要注意,一定要在图片文件路径钱加入斜杠(/),例如:

    /imagefilename.jpg

    三,上传图片并导入

    我们在导入MagentoCSV文件之前,一定要将所有要导入的商品图片,先上传到

    /media/import

    目录里,再上传并运行CSV文件,否则不能把图片导入到Magento数据库里!

    四,批量导入后 前台不显示问题的修复

    有时候,我们通过MagentoCSV批量导入商品之后,前台的商品的默认图片显示为空,我们只需要修改Magento Product文件里的一个参数,就可以解决Magento批量导入之后,前台商品不显示默认图片的问题,

    打开:

    app/code/core/Mage/Catalog/Model/Product.php

    找到函数addImageToMediaGallery:

    public function addImageToMediaGallery($file, $mediaAttribute=null, $move=false, $exclude=true)
    {
        $attributes = $this->getTypeInstance(true)->getSetAttributes($this);
        if (!isset($attributes['media_gallery'])) {
            return $this;
        }
        $mediaGalleryAttribute = $attributes['media_gallery'];
        /* @var $mediaGalleryAttribute Mage_Catalog_Model_Resource_Eav_Attribute */
        $mediaGalleryAttribute->getBackend()->addImage($this, $file, $mediaAttribute, $move, $exclude);
        return $this;
    }
    将$exclude=true修改成$exclude=false,修改之后的结果如下:

    public function addImageToMediaGallery($file, $mediaAttribute=null, $move=false, $exclude=false)
    {
        $attributes = $this->getTypeInstance(true)->getSetAttributes($this);
        if (!isset($attributes['media_gallery'])) {
            return $this;
        }
        $mediaGalleryAttribute = $attributes['media_gallery'];
        /* @var $mediaGalleryAttribute Mage_Catalog_Model_Resource_Eav_Attribute */
        $mediaGalleryAttribute->getBackend()->addImage($this, $file, $mediaAttribute, $move, $exclude);
        return $this;
    }
    修改之后,前台就可以正常显示图片了,

    总之,我们在批量导入Magento商品的时候,要注意,先上传产品到/media/import目录,CSV的图片路径字段要加斜杠(/),导入之后修改Product.php文件,只要操作时候仔细点,基本上可以正常使用Magento的导入功能。

  • 相关阅读:
    算法描述》关于LIS的nlogn方法
    简单tarjan》一道裸题(BZOJ1051)(easy)
    值得一做》关于数学与递推 BZOJ1002 (BZOJ第一页计划)(normal+)
    值得一做》关于一道DP+SPFA的题 BZOJ1003 (BZOJ第一页计划) (normal-)
    图论算法》关于最大流转最短路两三事
    刷题向》图论》BZOJ1001 平面图最大流、平面图最小割、单源最短路(easy+)
    c++中结构体的使用
    c++的标准流入流出和使用例子
    小知识 ——引用
    小知识——关于数组指针和指针数组
  • 原文地址:https://www.cnblogs.com/freeliver54/p/9146358.html
Copyright © 2011-2022 走看看