Jump to content

problem error cvs import product with numbers


Recommended Posts

hello,

 

hi i'm wim wensink from the netherlands, i'm using prestashop now for about 3 months and its working great now

i'm building a machinery parts webshop.

 

now my problem is this: i have uploaded category's by csv files no problems there, second i would like to upload products also with ftp filezilla in csv format no problem there. 

 

the probem is: i have category names like 254, 2503, 329 with only numbers.

prestashop makes new categorys for these number categorys, i do not know why they already excist.

prestashop makes these categorys and give an error message and stops without importing any product.

 

if i delete these "only numbers categorys" from the csv fie i have no problem importing products.

 

but i have to import the products to these categrys otherwise i have to do about 1800 by hand.

 

does anybody has a solution for this?

 

thank in advance

 

 

Link to comment
Share on other sites

Hallo Wim,

 

You're right, the problem comes from the fact your categories have numbers as name. Then, the importer searches for a category with the given value as database identifier and not as name. If the category id is not found, it creates a category with the value as name, but with a different identifier (standard increment). So, when importing the next product, the category is not found again and one is re-created, and so on...

 

As a quick and specific fix, you can edit controllers/admin/AdminImportController.php as following (only 2 lines to change, the ones marked with //EDITED):

    public function productImport()
    {
        (...)
        for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++)
        {
            (...)
            if (isset($product->category) && is_array($product->category) && count($product->category))
            {
                $product->id_category = array(); // Reset default values array
                foreach ($product->category as $value)
                {
                    if (false /*is_numeric($value)*/) // EDITED
                    {
                        (...)
                    }
                    elseif (/*is_string($value) &&*/ !empty($value)) // EDITED
                    {
                        $category = Category::searchByPath($default_language_id, trim($value), $this, 'productImportCreateCat');
                        if ($category['id_category'])
                            $product->id_category[] = (int)$category['id_category'];
                        else
                            $this->errors[] = sprintf(Tools::displayError('%1$s cannot be saved'), trim($value));
                    }
                }
                $product->id_category = array_values(array_unique($product->id_category));
            }
            (...)
        }
        $this->closeCsvFile($handle);
    }
 

The importer will now consider only category names, and never search for ids. If the category already exists it will be reused, otherwise it will be created. It works also with mulitple categories allocation (category names separated by comma ,)

 

Regards

--

Eric

Edited by erouvier29 (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...