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

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

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

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

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

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
 

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 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

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

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

 

 

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