Jump to content
Daresh

[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
  • Like 6
  • Thanks 1
  • Haha 1

Share this post


Link to post
Share on other sites

Works very good with 1.6.1.4. 

Thank you. :) 

  • Like 1

Share this post


Link to post
Share on other sites

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

It tells you exactly what is wrong: Parent category does not exist

Share this post


Link to post
Share on other sites

Can export product info of the selected categories ?

 

What product info would you like to have exported?

Share this post


Link to post
Share on other sites

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

Maybe the home category has a different ID. You need to take a look at the exported file and check if parent ID is OK everywhere.

Share this post


Link to post
Share on other sites

ah, i have to skip the first two lines. Now it works! 

 

Great Work!

Edited by Lausli
  • Like 1

Share this post


Link to post
Share on other sites

Greetings, Daresh,

 

Can I have html head tags in category descriptions in categories.csv?
 
I want to add head tags, bold, italics, etc.
 
Does this need a new forum question?
 
Thanks!
Edited by pause4paws

Share this post


Link to post
Share on other sites

Maybe it needs, cause I don't quite understand what do you need.

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

Share this post


Link to post
Share on other sites

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

Thanks for the module, but following the prestashop categories import file, there's some informations missing like meta description, meta title, meta keyword, url rewrite, category image, root category (0/1)

Share this post


Link to post
Share on other sites

Tried it on PS version 1.6.1.4: blank page after upload. 

 

I uploaded it and just nothing showed up in the modules list, the search didn't found.

V 1.6.1.4.

 

Thanks for any help! :)

Share this post


Link to post
Share on other sites

This module is so extremely simple that I can't think of anything that can cause a blank page there. Any error when turning on the debug mode?

Share this post


Link to post
Share on other sites

After upload, there is no module in my list. Disabled/enabled modules, doesn't matter where I search, there is no module GM export.

Share this post


Link to post
Share on other sites

And no message with debug turned on? I know that the module is not yet installed, but it's the only thinkg that comes to my mind to debug this.

Share this post


Link to post
Share on other sites

Hi Daresh, probably has something to do with the write permissions, my bad. I check, install the module and I will let you know!

Share this post


Link to post
Share on other sites

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
  • Like 1

Share this post


Link to post
Share on other sites

Hi

Do you have a simple module to import products. i just cant get my CVS to workl

Share this post


Link to post
Share on other sites

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

Hello, is they a  way of modify this to work with orders with specifik order status.

Share this post


Link to post
Share on other sites

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

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

This module runs on 1.7.5.1

Edited by Belena

Share this post


Link to post
Share on other sites

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

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

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

×

Important Information

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