Thursday 18 December 2014

Import csv file with multiple images in magento

First make a copy of


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

  into 

app/code/local/Mage/Catalog/Model/Convert/Adapter/


Edit 

app/code/local/Mage/Catalog/Model/Convert/Adapter/Product.php 

and add the following code after line 778:



if (isset($importData['media_gallery']) && !empty($importData['media_gallery'])) {

        $x = explode(',', $importData['media_gallery']);

        foreach ($x as $file) {

            $imagesToAdd[] = array('file' => trim($file));

        }

        $mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(

            $product,

            $imagesToAdd, Mage::getBaseDir('media') . DS . 'import',

            false,

            false

        );

    }





Now file look like following: 

773        $addedFilesCorrespondence = $mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(
774            $product,
775            $arrayToMassAdd, Mage::getBaseDir('media') . DS . 'import',
776            false,
777            false
778        );


779    if (isset($importData['media_gallery']) && !empty($importData['media_gallery'])) {


780    $x = explode(',', $importData['media_gallery']);

781       foreach ($x as $file) {
782            $imagesToAdd[] = array('file' => trim($file));
783        }
784        $mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(
785            $product,
786            $imagesToAdd, Mage::getBaseDir('media') . DS . 'import',
787            false,
788            false
789        );
790    }




Now add a column *media_gallery* in your  CSV file, and put your other images in /media/import also. 

Add images as following:


media_gallery

-------------


/second_image.png, /third_image.png, /fourth_image.png




3 comments:

  1. Very good to know about to import CSV file with multiple images. This post is very useful and it has lots of information. Thanks for the post and keep updating.
    Febia

    ReplyDelete