Jump to content

[Free Module] Export Categories To Csv


Recommended Posts

As we all know, the default category export in Prestashop is far from useful, as it exports only the current visible category table, not the whole tree.

 

This module allows you to export all categories to a CSV file.

post-653890-0-07553500-1457640565_thumb.png

gmexport.zip

 

(for PS 1.6, first release so please test and give feedback)

Edited by Daresh (see edit history)
  • Like 8
  • Thanks 3
  • Haha 1

Share this post


Link to post
Share on other sites
  • 2 weeks later...

Hi! 

Thanks a lot for this module, but it does not work for me. :(

 

When trying to import the categories/subcategories into an empty Prestashop installation I get this error.

 

"The category ID cannot be the same as the Root category ID or the Home category ID."

 

Anybody knows what the issue might be here?

 

Regards!

Share this post


Link to post
Share on other sites

The module exports all your categories, so the Home category will also get exported, just delete this one row from the file and it should work.

  • Like 1

Share this post


Link to post
Share on other sites

Hi Daresh!

 

Thanks for your quick reply. Unfortunately when deleting the first line this error message comes up instead when trying to import the file:

 

[PrestaShopException]

Parent category does not exist
at line 397 in file classes/Category.php

392. return 0;
393. }
394.
395. $parent_category = new Category((int)$this->id_parent);
396. if (!Validate::isLoadedObject($parent_category)) {
397. throw new PrestaShopException('Parent category does not exist');
398. }
399. return $parent_category->level_depth + 1;
400. }
401.
402. /**
 
Any ideas of what the issue might be now? 
 
Regards!

Share this post


Link to post
Share on other sites
  • 3 months later...
  • 2 months later...
  • 1 month later...
  • 2 weeks later...

From here

https://www.prestashop.com/forums/topic/566670-how-i-can-export-all-categories-and-import-them-vrom-1619-to-1619/

 

Thak you, it works but i cant import it. Becaus i get 69 Errors like this:

69 Fehler 
Die ID der Kategorie kann nicht die gleiche sein wie die ID der Root-Kategorie, bzw. die ID der Home-Kategorie.
Kleidung & Accessoires (ID: 15) kann nicht gespeichert werden
Damenmode (ID: 16) kann nicht gespeichert werden
Leggings (ID: 65) kann nicht gespeichert werden
Dessous/Unterwäsche (ID: 17) kann nicht gespeichert werden
Slips,Strings & Pants (ID: 79) kann nicht gespeichert werden
[...]

I installed a freash new prestashop Installation but i cant import the export. Di you have a solution ?

Share this post


Link to post
Share on other sites

In my csv for categories, in the description field, I want to add H1, H2, etc tags. This was a question about importing and I was told by TemplateMonster to just add the html to the description, so I did and it works. When I reach the point where I need to export the categories, I'll try your solution, Daresh. Thank you. :)

Edited by pause4paws (see edit history)

Share this post


Link to post
Share on other sites
  • 2 weeks later...

Works perfectly!
(would love the same easy way to import the same file! ;) 

Thank you!

PrestaShop version: 1.6.1.7      
PHP version: 7.0.13     
shop with SSL
 

  • Like 1

Share this post


Link to post
Share on other sites
  • 1 month later...
  • 3 weeks later...
  • 4 weeks later...

This is adjusted version of this script that will display on the screen the category tree with IDs.

It will display as table with format:

<ID>   Category

<ID>   -SubCategory 

<ID>   --SubSubCategory

etc.

<?php
require_once('../config/config.inc.php');

    $ids = array();
//idLang is set to 1 directly in the script
//idShop is set to 1 directly in the script
    $iso = Language::getIsoById($idLang);
    $row = array('id', 'name', 'parent', 'description');
    generateCategoryCsvList();


echo '<table>';
foreach ($csvRow as $row){
    if ($row["id"] != 2){
        echo '<tr>';
            echo '<td>'.$row["id"].'</td>';
            echo '<td>'.$row["name"].'</td>';
        echo '</tr>';
    }
}
echo '</table>';



function generateCategoryCsvList($parent = 0)
{
    global $ids;
    global $csvRow;
    $idLang = 1;
    $idShop = 1;
    if ($parent == 0) {
        $results = Db::getInstance()->ExecuteS("SELECT c.id_parent, c.id_category, CONCAT ( REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(level_depth,1,''),2,''),3,'-'),4,'--'),5,'---'),6,'----'),cl.name) as name, cl.description, cl.link_rewrite,cs.position ,level_depth
					FROM "._DB_PREFIX_."category c
					LEFT JOIN "._DB_PREFIX_."category_lang cl ON (c.id_category = cl.id_category AND id_lang = 1)
					LEFT JOIN "._DB_PREFIX_."category_group cg ON (cg.`id_category` = c.id_category)
					LEFT JOIN `"._DB_PREFIX_."category_shop` cs ON (c.`id_category` = cs.`id_category` )
					WHERE c.id_category <> '1'
                    AND cs.id_shop = 1
					GROUP BY c.id_category
					ORDER BY c.`id_parent` ASC, level_depth ASC");
        foreach ($results as $row) {
            if (!in_array($row['id_category'], $ids)) {
                $csvRow[] = ['id' => $row['id_category'], 'name' => $row['name']];
                array_push($ids, $row['id_category']);
                generateCategoryCsvList($row['id_category']);
            }
        }
    } else {
        $results = Db::getInstance()->ExecuteS("SELECT c.id_parent, c.id_category, CONCAT ( REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(level_depth,1,''),2,''),3,'-'),4,'--'),5,'---'),6,'----'),cl.name) as name, cl.description, cl.link_rewrite,cs.position ,level_depth
					FROM "._DB_PREFIX_."category c
					LEFT JOIN "._DB_PREFIX_."category_lang cl ON (c.id_category = cl.id_category AND id_lang = 1)
					LEFT JOIN "._DB_PREFIX_."category_group cg ON (cg.`id_category` = c.id_category)
					LEFT JOIN `"._DB_PREFIX_."category_shop` cs ON (c.`id_category` = cs.`id_category` )
					WHERE c.id_category <> '1'
					AND c.id_parent = '".$parent."'
                    AND cs.id_shop = 1
					GROUP BY c.id_category
					ORDER BY cs.position ASC, c.`id_parent` ASC, level_depth ASC");
        if (!empty($results) > 0) {
            foreach ($results as $row) {
                if (!in_array($row['id_category'], $ids)) {
                    $csvRow[] = ['id' => $row['id_category'], 'name' => $row['name']];
                    array_push($ids, $row['id_category']);
                    generateCategoryCsvList($row['id_category']);
                }
            }
        }
    }
}
Edited by petr@petrpanek.cz (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites
  • 2 weeks later...
  • 5 months later...

bibi -  assume v 1.7+ with built in import.
Make sure CTV is UTF 8 (which is NOT default on either Open Office or MS Office) and also use ; as delimiter.  I tried , and tab etc but it failed for unknown reasons.

On regards to this module - just tried on 1.7.2.2 with the above config.php and it installs.  Goes to Configure BUT returns blank page when you attempt to use.

A bit astonished that EXPORT isn't part of the default.
Didnt use to be?
 

Will just use SQL to export for now.

Share this post


Link to post
Share on other sites
  • 4 weeks later...
  • 1 month later...
  • 4 weeks later...
  • 2 months later...
  • 2 months later...
  • 1 month later...
  • 2 months later...

Hi Daresh, I have ps 1.7.3.1.

I installed the module on my localhost and on the server; worked perfect on my localhost, however is giving me an error on the server . . . any ideas how to solve this issue?

Thank you, Gerry

gmexport error.PNG

Share this post


Link to post
Share on other sites
  • 1 month later...
  • 3 months later...

I was able to export all categories and subcategories using the SQL manager in prestashop. (version 1.6).

The code I used is:

 

SELECT
a.`id_category`, `active`, `name`, `link_rewrite`, a.`id_parent`, a.`is_root_category`, `description`, `meta_title`, `meta_description`, a.`id_shop_default`
FROM `ps_category` a
LEFT JOIN `ps_category_lang` b ON (b.`id_category` = a.`id_category`)
LEFT JOIN `ps_category_shop` sa ON (a.`id_category` = sa.`id_category`)  
WHERE 1


ORDER BY a.`id_category` ASC

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites
  • 1 month later...
  • 1 month later...

To EXPORT Categories in the ORIGINAL format like the sample file given by Prestashop, and ready to IMPORT at the moment the ONLY SOLUTION I found is:

Go tho the PHPmyAdmin of your database and make this query:

select
cl.id_category as "ID",
c.active as "Active (0/1)",
cl.name as "Name",
cl2.name as "Parent Category",
c.is_root_category as "Root category (0/1)",
cl.description as "Description",
cl.meta_title as "Meta title",
cl.meta_keywords as "Meta keywords",
cl.meta_description as "Meta description",
cl.link_rewrite as "URL rewritten",
concat('http://', ifnull(conf.value,'example.com'), '/img/c/', c.id_category, '.jpg') as "Image URL"
from ps_category c
inner join ps_category_lang cl on cl.id_category = c.id_category
inner join ps_category_lang cl2 on cl2.id_category = c.id_parent and cl2.id_lang = cl.id_lang
left join ps_configuration conf on conf.name = 'PS_SHOP_DOMAIN'
WHERE 1 AND cl.id_lang = 1
order by cl.id_lang, c.level_depth

(the language you want to export is defined at penultimate line as a number, usually 1 is your primary language)

Enjoy!

 

Share this post


Link to post
Share on other sites
  • 3 weeks later...

That is great thank you
My sql knowledge is very limited and I need lower levels, the subs below a specific category e.g.

root> home> cat id 3 list multiple

Can you help with that please?

Share this post


Link to post
Share on other sites
  • 8 months later...
On 4/12/2019 at 12:06 PM, airiscreative said:

To EXPORT Categories in the ORIGINAL format like the sample file given by Prestashop, and ready to IMPORT at the moment the ONLY SOLUTION I found is:

Go tho the PHPmyAdmin of your database and make this query:

select
cl.id_category as "ID",
c.active as "Active (0/1)",
cl.name as "Name",
cl2.name as "Parent Category",
c.is_root_category as "Root category (0/1)",
cl.description as "Description",
cl.meta_title as "Meta title",
cl.meta_keywords as "Meta keywords",
cl.meta_description as "Meta description",
cl.link_rewrite as "URL rewritten",
concat('http://', ifnull(conf.value,'example.com'), '/img/c/', c.id_category, '.jpg') as "Image URL"
from ps_category c
inner join ps_category_lang cl on cl.id_category = c.id_category
inner join ps_category_lang cl2 on cl2.id_category = c.id_parent and cl2.id_lang = cl.id_lang
left join ps_configuration conf on conf.name = 'PS_SHOP_DOMAIN'
WHERE 1 AND cl.id_lang = 1
order by cl.id_lang, c.level_depth

(the language you want to export is defined at penultimate line as a number, usually 1 is your primary language)

Enjoy!

 

Thanks for this! The only thing is, it doesn't export the description or Meta data from category_lang? How do we do this?

 

Thanks

Share this post


Link to post
Share on other sites
  • 1 month later...
  • 4 months later...
On 10/3/2016 at 21:10, Daresh said:

Como todos sabemos, la exportación de categoría predeterminada en Prestashop está lejos de ser útil, ya que exporta solo la tabla de categoría visible actual, no todo el árbol.

 

Este módulo le permite exportar todas las categorías a un archivo CSV.

post-653890-0-07553500-1457640565_thumb.png

gmexport.zip 28.73 kB · 279 descargas

 

(para PS 1.6, primer lanzamiento, así que por favor pruebe y envíe sus comentarios)

hola gracias por la info, pero en mi caso utilizo prestashop 1.7.6.3 y la exportación no me funciona, que puedo hacer? muchas gracias!!

Share this post


Link to post
Share on other sites
  • 6 months later...

Gracias por el modulo, me has salvado, en prestashop 1.7.7.0 funciona correctamente

 

Thanks for the module, you save me, in prestashop 1.7.7.0 works correctly

Share this post


Link to post
Share on other sites
On 2/12/2021 at 9:47 PM, Saky0333 said:

Gracias por el módulo. salvando que no saca bien los acentos... En la versión 1.7.7.1 funciona correcto y me saca el árbol que es lo que necesito.

 

Share this post


Link to post
Share on other sites
  • 1 month later...

Thanks for the module, in prestashop 1.7.7.3 it's works correctly.

Do you have something the same for the products. 

I can export it with the standard prestashop but is will not let me see the combinations 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More