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

product images are duplicated on every CSV import
 
wjcstp
Jr. Member
 
Total Posts:  30
Joined:  2008-11-11
 

I’m currently using 1.3.2.2, and I have my product image routine customized to use the Gallery column mod detailed on the forums, and that is working great for me. The problem is that each time the CSV of the client’s product spreadsheet is imported, the image names are added to the product, rather than replacing the existing images. This client wants to be able to regularly update product pricing and info (including images) via CSV upload, and this works great for all parts of the product except for images (and custom options*). When a new file is uploaded, every product has multiple copies of all product images, which is unacceptable.

Does anyone have a way to remove existing product images on import? I can’t see how to do this in the Products.php file, that seems to be all about parsing the new data. Excluding existing images would be a workaround, but still messy; it’s really tedious to remove images through the product edit screen.

* a different problem, but also DataFlow-related: when new products are imported, the custom options aren’t added to the product unless i go into the product admin and manually add a custom field and resave. When that’s done, the imported fields and values show up fine, and one subsequent uploads, they’re updated fine as well, but never for new products. Anyone have a way around this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
vikshu
Member
 
Total Posts:  69
Joined:  2009-04-09
Noida
 

Did anyone find solution to this problem? I too am having repetition of product image on every csv upload. Apart from that i want the old image to go away when new one is added to the product via csv. Please suggest. Its creating mess.

 
Magento Community Magento Community
Magento Community
Magento Community
 
wjcstp
Jr. Member
 
Total Posts:  30
Joined:  2008-11-11
 

I ended up using this solution to the multiplying uploads:
http://www.magentocommerce.com/boards/viewthread/18248/#t75775

I cleaned out the unwanted images from the database table - i don’t know that it was the best way, but i had over 8500 to remove, days of work through the item edit window. It looks like images are not getting duplicated now on update. This is another area (among many) that is really messy when trying to make regular product updates via CSV in Magento. The whole dataflow system needs some real improvement.

 
Magento Community Magento Community
Magento Community
Magento Community
 
frostbytes
Sr. Member
 
Total Posts:  114
Joined:  2008-11-05
Edmonton, Alberta, Canada
 

One of my clients keeps running into his web host’s inode limits because of this problem.  Approximately 7500 products has resulted in 85,000+ duplicated images.

I really hope there’s a faster way of removing duplicated images than doing it by hand.  If anyone has a better way of doing this, please speak up.  grin

[L]

 
Magento Community Magento Community
Magento Community
Magento Community
 
trogfish
Member
 
Total Posts:  42
Joined:  2008-12-03
 

I created a wiki to explain how I am dealing with it.  (Delete, re-import, repeat, when needed.)
It is far from ideal, but at least it’s not ‘by hand’.

http://www.magentocommerce.com/wiki/doc/webservices-api/using_soap_api_to_delete_all_products_in_a_category

 
Magento Community Magento Community
Magento Community
Magento Community
 
frostbytes
Sr. Member
 
Total Posts:  114
Joined:  2008-11-05
Edmonton, Alberta, Canada
 

Thanks trogfish.  I’ll have a look at that.

[L]

 
Magento Community Magento Community
Magento Community
Magento Community
 
coolshop
Sr. Member
 
Total Posts:  121
Joined:  2009-08-28
 

Here is a hack to avoid duplicated file in the first place:

Modified a core Magento file (please create a local module for seamless future Magento upgrade)

/home/ecoulib1/public_html/lib/Varien/File/Uploader.php
Commented the lines as indicated below around line 420.

static public function getNewFileName($destFile)
{
$fileInfo = pathinfo($destFile);
if( file_exists($destFile) ) {
$index = 1;
$baseName = $fileInfo[’filename’] . ‘.’ . $fileInfo[’extension’];
//ITQ remove so file not duplicated
//while( file_exists($fileInfo[’dirname’] . DIRECTORY_SEPARATOR . $baseName) ) {
// $baseName = $fileInfo[’filename’]. ‘_’ . $index . ‘.’ . $fileInfo[’extension’];
// $index ++;
//}
$destFileName = $baseName;
} else {
return $fileInfo[’basename’];
}

return $destFileName;
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
frostbytes
Sr. Member
 
Total Posts:  114
Joined:  2008-11-05
Edmonton, Alberta, Canada
 

> (please create a local module for seamless future Magento upgrade)

I’ve never done that before.  Can you point out step-by-step instructions on how to do that?

Thanks coolshop!  Much appreciated.

[L]

 
Magento Community Magento Community
Magento Community
Magento Community
 
coolshop
Sr. Member
 
Total Posts:  121
Joined:  2009-08-28
 

Come to think about it given that the modified file is not an app/core file but a library file (/lib/Varien/File/Uploader.php), I am wondering if the custom module creation described below would work. I have not tested that. So please backup you work before testing and do not test on a production environment. However this works any core file that that need to be modified.

Here is the automated way:
http://www.magentocommerce.com/wiki/custom_module_with_custom_database_table

Here is a extract from the following Wiki:
http://www.magentocommerce.com/wiki/groups/174/changing_and_customizing_magento_code

Custom Modules

Most likely you will want to make a module that represent’s your company to hold all your specific changes. Start off by making a new directory like so:

app/
     
code/
            
core/
            
community/
            
local/
                    
XyzCorp/

Now, if you need to make changes to the Magento file, Mage/Catalog/Block/Breadcrumbs.php, you can add a new directory for the “Catalog” module under your XyzCorp directory, then a blocks directory and copy the file into this new directory. Also you need to create config.xml of your module.

app/
     
code/
            
core/
            
community/
            
local/
                    
XyzCorp/
                               
Catalog/
                                          
Block/
                                                 
Breadcrumbs.php
                                          etc
/
                                                 
config.xml

Change the class name inside the file by starting off with “XyzCorp” instead of “Mage”.

Strip out all the code you don’t need, and make it subclass the original class name (”Mage_Catalog_Block_Breadcrumbs”).

Now, you must activate your module so Magento understands that there is new code in the “local” directory.

In app/etc/modules/XyzCorp_Catalog.xml, add the following lines

<?xml version="1.0"?>
<config>
     <
modules>
        <
XyzCorp_Catalog>
            <
active>true</active>
            <
codePool>local</codePool>
        </
XyzCorp_Catalog>
     </
modules>
</
config>

It is crucial that the same prefix XyzCorp is used throughout files, class names, directories, and XML tag names.

Now, your own catalog module is activated, but when will it actually be called by the system? Ahh, we need a special rewrite tag to instruct Magento to use this one file (Breadcrumbs.php) instead of its default.

Now we should rewrite block using your module’s config file.
Blocks

Edit app/code/local/XyzCorp/Catalog/etc/config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
XyzCorp_Catalog>
            <
version>0.1.0</version>
        </
XyzCorp_Catalog>
    </
modules>
    <global>
        <
blocks>
            <
catalog>
                <
rewrite>
                        <
breadcrumbs>XyzCorp_Catalog_Block_Breadcrumbs</breadcrumbs>
                </
rewrite>
            </
catalog>
        </
blocks>
    </global>
</
config>

We need to add a “blocks” tag, or edit inside an existing blocks tag, depending on your XML file. Then we add a rewrite tag after our module name, which is “catalog” in this case. Then, we throw in the word “breadcrumbs”. This “breadcrumbs” name must help magento to find the Block class you want to extend. In our example here, breadcrumbs is the core class file name (which will be overwritten): app/code/core/Mage/Catalog/Block/Breadcrumbs.php. If you have more levels below the Block directory, include it on that tag, using underscores to separate it from the class file name. Ex:

<blocks>
          <
catalog>
              <
rewrite>
                      <
category_view>XyzCorp_Catalog_Block_Category_View</category_view>
              </
rewrite>
          </
catalog>
      </
blocks>

In this case, the class being overwritten is app/code/core/Mage/Catalog/Block/Category/View.php.

The data inside the breadcrumbs (same for category_view) tag is the name of your classfile, and Magento knows how to find it because the class name is the same as it’s directory path and filename. Remember that the underscore means another folder level on the file structure, and Magento won’t find your class in case the Folder structure doesn’t reflect the classname properly.

For instance:

XyzCorp_Catalog_Block_Breadcrumbs → /app/code/local/XyzCorp/Catalog/Block/Breadcrumbs.php XyzCorp_Catalog_Block_Category_View → /app/code/local/XyzCorp/Catalog/Block/Category/View.php

 
Magento Community Magento Community
Magento Community
Magento Community
 
frostbytes
Sr. Member
 
Total Posts:  114
Joined:  2008-11-05
Edmonton, Alberta, Canada
 

Thanks very much, coolshop!  I’ll have a look at this shortly.

[L]

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top