Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 2
Overwrite images during import: a possible hack but an expected standard feature
 
benfrain.com
Sr. Member
 
Total Posts:  142
Joined:  2008-08-15
 

nikola99 - thanks for the contribution - couple of quick questions on this:

I have the gallery field in my CSV for additional product images for each item - does this code accommodate that field? Or is it merely a case of changing line 205 in Product.php to:

$fields = array('image''thumbnail''small_image''gallery');

Also, once done, is there somewhere this needs to be selected/activated in the back-end for it to work?

 
Magento Community Magento Community
Magento Community
Magento Community
 
HectorPN
Member
 
Total Posts:  74
Joined:  2010-03-21
Adelaide, Australia
 

Same question. I have created the module but images are still being duplicated. Is there anything else that needs to be enabled?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikola99
Member
 
Total Posts:  47
Joined:  2010-04-09
 

benfrain.com: I’m not really sure. You’d have to try it.

HectorPN: There’s nothing else that i can think of… Make sure you apply the code fixes JeremyFP mentions and put all your images in /media/import. Then use only the file name in the import with a leading slash (e.g. /image.jpg).

 
Magento Community Magento Community
Magento Community
Magento Community
 
HectorPN
Member
 
Total Posts:  74
Joined:  2010-03-21
Adelaide, Australia
 

Thanks Nikola. I did replace all the ‘NAMESPACE” items.

I have a big tree under /media/import ... such as “/media/import/{BRAND}/thumbnail/{sku}.jpg”

That may be causing the problem?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikola99
Member
 
Total Posts:  47
Joined:  2010-04-09
 

Hector,

I think it should work as long as your image paths are relative to /media/import: “/{BRAND}/thumbnail/{sku}.jpg”. I’d try with a few products in /media/import and then remove them from Magento and try the same file but put images in a sub-direcotry. Check your permissions as well.

 
Magento Community Magento Community
Magento Community
Magento Community
 
emmenko
Sr. Member
 
Total Posts:  96
Joined:  2010-10-20
 

I want to say something about this problem, hoping it will help others with the same problem.

I work with magento 1.4.1.1 with the “famous” Productimport.php that fixes the import for Configurable Product.
I was also able to import image galleries but there was always that f****** problem that, every time I do a new import, the images are duplicated.

After a lot of trials I finally made it, following part of the fixes written in this topic.

So, here is what I did:

1. I made a backup copy (for safety) of the file Media.php in app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/
This is because we’re going to modify a file in the core

2. Go to Media.php and find the following functions _moveImageFromTmp and _copyImage

3. Comment this code

/*
        // <HACK>
        $destFile = dirname($file) . $ioObject->dirsep()
                  . Varien_File_Uploader::getNewFileName($this->_getConfig()->getMediaPath($file));
    // <HACK>
    */

and add this before $ioObject

$destFile $file// <HACK>

4. So, in the end we make 2 times a comment and add 2 times $destFile = $file;

5. Run the import 2-3 times to test it and it should work. ^^

Now I have to fix the same problem with the super product attributes… :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
imwy2cool
Sr. Member
 
Total Posts:  164
Joined:  2009-05-07
 
emmenko - 09 November 2010 02:58 AM

I want to say something about this problem, hoping it will help others with the same problem.

I work with magento 1.4.1.1 with the “famous” Productimport.php that fixes the import for Configurable Product.
I was also able to import image galleries but there was always that f****** problem that, every time I do a new import, the images are duplicated.

After a lot of trials I finally made it, following part of the fixes written in this topic.

So, here is what I did:

1. I made a backup copy (for safety) of the file Media.php in app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/
This is because we’re going to modify a file in the core

2. Go to Media.php and find the following functions _moveImageFromTmp and _copyImage

3. Comment this code

/*
        // <HACK>
        $destFile = dirname($file) . $ioObject->dirsep()
                  . Varien_File_Uploader::getNewFileName($this->_getConfig()->getMediaPath($file));
    // <HACK>
    */

and add this before $ioObject
$destFile $file// <HACK>

4. So, in the end we make 2 times a comment and add 2 times $destFile = $file;

5. Run the import 2-3 times to test it and it should work. ^^


Now I have to fix the same problem with the super product attributes… :(

FIRST: let me say thank you!

SECOND: Please don’t hack at the core. It’s really easy to override a file if need be. Don’t simply make a backup copy and change the core file. Instead, what you need to do is make a LOCAL copy. It’s so easy there is no excuse not to do it.

In app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php: Take this file and make a copy of it for here:

In app/code/local/Mage/Catalog/Model/Product/Attribute/Backend/

Note, you’ll most likely need to add new folders all along that path as they probably don’t yet exist unless you’ve done this before. Make sure they are all created exactly like the core path (I believe they are case sensitive), other than the core/local. This is how you can make changes to a core file WITHOUT touching it (other than copying it there of course).

 
Magento Community Magento Community
Magento Community
Magento Community
 
amartinez
Guru
 
Avatar
Total Posts:  347
Joined:  2008-11-14
Spain
 

Hi, about the image duplication, I always use (from the very beginning) these adaptations in Productcategory.php:

to find and comment out:

/**
            * if ( in_array( $field, $this -> _imageFields ) ) {
            * continue;
            * }
            */

and:

/**
        * uncomment to use magento image system (and allow to: edits via admin, change images)
        * $imageData = array();
        * foreach ( $this -> _imageFields as $field ) {
        * if ( !empty( $data[$field] ) && $data[$field] != 'no_selection' ) {
        * if ( !isset( $imageData[$data[$field]] ) ) {
        * $imageData[$data[$field]] = array();
        * } 
        * $imageData[$data[$field]][] = $field;
        * } 
        * } 
        * 
        * foreach ( $imageData as $file => $fields ) {
        * try {
        * $product -> addImageToMediaGallery( Mage :: getBaseDir( 'media' ) . '/catalog/product' . $file, $fields, false );
        * } 
        * catch ( Exception $e ) {
        * } 
        * } 
        * 
        * if ( !empty( $data['gallery'] ) ) {
        * $galleryData = explode( ',', $data["gallery"] );
        * foreach( $galleryData as $gallery_img ) {
        * try {
        * $product -> addImageToMediaGallery( Mage :: getBaseDir( 'media' ) . '/catalog/product' . $gallery_img, null, false, false );
        * } 
        * catch ( Exception $e ) {
        * } 
        * } 
        * }
        */

the csv image fields must contain the relative path to media/catalog/product/, e.g. “/img_articulos/product01.jpg” link to media/catalog/product/img_articulos/product01.jpg (please observe the field slash at /img_articulos)

in any case, now you can test the new 1.5 script version here: http://www.magentocommerce.com/boards/viewthread/227005

Regards!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Digital Pianism
Member
 
Avatar
Total Posts:  48
Joined:  2010-06-08
 

Thanks Benjamin Bellamy,

I used your code to customize the product image uploading process to avoid the _1 at the end if the image alread exists, it works like a charm (tested on 1.4.2, then I will test on 1.5 / 1.6)

 
Magento Community Magento Community
Magento Community
Magento Community
 
kroeger
Jr. Member
 
Total Posts:  11
Joined:  2012-09-02
 

For a young lady who knows nothing in php , as I am, it is too difficult to understand thiese codes. Basically this post is for those who faced this problem but knows no coding. I found a site with a pretty simple and fast data import. To use it you only need click your mouse and that\’s all.... It was really cool that I found smth without php!!!

Hope that really helps some girl (or boy) tongue laugh

 
Magento Community Magento Community
Magento Community
Magento Community
 
ilightman
Jr. Member
 
Total Posts:  1
Joined:  2010-03-16
 

Will this work on 1.7.0.2?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 2