This article will detail how to adjust the Magento Batch Import (Dataflow) to allow uploading multiple gallery images, and also how to add a way to remove all images during Import/Update.
These are the accompaning files: (Please reference this file if you have any quetion about the code examples below. The WYSIWYG editor was messing things up. mainly “&’s” and “empty()’s” )
1. Full Code Example
First we are going to have to modify the the adapter used to save/update products during the import process. The file used is located here: “/app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php“. Since we are going to be modifying this file we should extend it so we don’t change any core files. There are plenty of articles that detail how to extend/customize Magento files so I will not go into it.
First lets tackle adding multiple gallery images. These are images that appear on the products detail page below the main image. We will be making all our edits in the Product.php file mentioned in the previous paragraph. Find the SaveRow method. In this method find the code where Magento saves the products images(should be similar to the following code and around line 630).
First thing we will do is change the addImageToMediaGallery so that when it saves the image it is not excluded(saves you from having to re-edit the products after import to make the images appear.).
Now we can add the code to import multiple gallery images. Just below the code above add this new code:
Now that was not too hard was it?
Now we can address removing images during the import/update process. In order to remove all the images you will need to continue modifying the saveRow method. Add the following code just above the code we previously edited.
To utilize the code we just created you will need to add the “remove_all_images” column to your spreadsheet and set the value to “yes”.
This was written using Magento version 1.2.1 so your files could be slightly different, but should still work if you follow the instruction. If you have any problems please leave a productive comment and I will see how I can help.