Jump to content

Prestashop Auto Add Categories from CSV Perl Script (Free)


carpealexdiem

Recommended Posts

This is the first version of my perl script for automating the Prestashop from the linux shell.

Any feedback and suggestion is appreciated but please keep in mind that this is only the first version and that it's FREE as in Freedom :)

For now it will only add the categories from a specified CSV file but as soon as I'll finish the whole script I will post it here(For adding categories,products,update prices,update quantities,download csv from remote server with curl and add,update or delete products).

 

Instructions:

 

1. First of all the script gets the Category->SubCategory->SubSubCategory from the CSV first second and third column like this:

 

cat catalog.csv

Laptop;Netbook;Asus
Laptop;Notebook;Sony
Smarthphone;Sony;Xperia

 

It really doesn't matter what goes after the third column because it only checks the first three. If a category or subcategory or subsubcategory doesn't exist it will add it. Use only ";" after each column in the CSV file or feel free to modify the script.

 

2. You must have a conf.ini file containing your mysql server, your user and password, your database and your website link( Es: www.myprestashop.com without the http:// ).

 

cat conf.ini


[mysql]
DBNAME = prestashop
DBUSER = root
DBPASS = password
DBHOST = www.myprestashop.com

[website]
LINK = www.myprestashop.com

 

3. You must put the following code in a file named cat.php in your prestashop modules folder and chmod it to 777. It is used by the script to rebuilt the CategoryTree( Credit goes to Terragg for this ):

 

 

<?php
// Pull in basic settings
require( dirname( __FILE__ ).'/../config/config.inc.php');
// Regenerate the pre-ordered node sets
Category::regenerateEntireNtree();
echo "done\n";
?>

 

4. You must install the following perl modules:

 

 

use DBI;
use Config::Tiny;
use Text::CSV;
use LWP::Simple;

 

WARNING: This script only inserts categories for the italian language because it's the one I use. In order to suit it for your own prestashop language please change all the "6" in the script or contact me.

 

ToDo: Chosing language from conf.ini

Adding,Updating or Deleting products

Updating Prices

Other things like this :)

 

Usage: perl categories.pl File.CSV

categories.zip

  • Like 1
Link to comment
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...