Prestashop / CSV Import
Discover how to easily connect Prestashop
Import CSV in Prestashop
Brief description of the prestashop Import CSV
Prestashop offers a CSV import functionality to import data like categories, products, variants (called combinations in Prestashop), customers, etc.
You can find more information about this functionality in the Prestashop documentation, f.ex http://doc.prestashop.com/display/PS17/Import.
The import functionality can be found under “Advanced Parameters” and Import.
We will mainly use 3 CSV files, in this order:
To import the categories
To import the products
To import the combinations (variants)
It is possible to download sample CSV files for each of these objects.
Unfortunately, the CSV import files of Prestashop require using the Prestashop internal id’s. The good news though is that it is possible to force the internal id’s with our own id’s. These id’s must be integers and so we cannot use the standard Stanley/Stella codes (like stylecode or sku reference). The other good news is that Prestashop takes care of identifying during import if it is a creation or an update based on this internal id.
If you are already using Prestashop with products from other brands than Stanley/Stella be sure to select a range for the Stanley/Stella product id’s that is separate from your current product id’s.
If you are already using Prestashop with Stanley/Stella products, be sure to first download the current product set in order to retrieve the internal product id’s for each styles and variants, as well as for the categories.
How to import CSV's in Prestashop
When importing CSV’s in Prestashop, it is important to select the right settings.
Select the right object you want to import (f.ex Products)
Select the corresponding CSV file
Select the language you will import (each language must be separately imported)
Be sure to define the right column separator of your CSV. It can be a comma ‘,’ or a semi-colon ‘;’. In our case, we use the semi-colon.
Be sure to define the right value separator of your CSV. In our case, we use the comma.
In the selectors, there are 2 important selectors to be set:
Use product reference as key (This will only be used if the product reference is an integer, which is not the case at Stanley/Stella)
Force all ID numbers (This one is important)
If everything is correct, click ‘Next’.
In the next screen, Prestashop shows you the mapping between your CSV columns and the data in Prestashop. Our example PHP programs generate the CSV in the standard import format for Prestashop 1.7.
Be sure to fill in “1” in the field “Rows to skip” since we use the first line of the CSV for the headers of the columns.
If everything is correct, click “Import”.
Creating the categories
You can either create the categories manually or import these categories via CSV.
We created the categories manually and noted then the internal id’s. We used these internal id’s in the product CSV import file.
Generating the product CSV import file
The Product CSV import file has 1 line per style. So, we first call the Stanley/Stella Product API, with grouped styles. We then loop on all styles.
For each style:
We map the “Gender” and “Type” to the right Prestashop category and get the corresponding internal id.
We specify the internal id, with a counter, that we want to force in Prestashop. In our case, the first id is for example 22. (See comments in section “Next step: Automation”)
In Prestashop, the price is first defined at the product level. Variations on the price per variants are then defined as differences with the product price (see generating the combination CSV import file). What we did is to take the price of the first variant and use this as the product price.
We then add a row with all data at style level.
Generating the Combination CSV import file
The Combination CSV import file has 1 line per variant.
So, again, we first call the Stanley/Stella Product API, with grouped styles and sorted by colors and sizes. We then loop on all styles and all variants.
The Combination CSV file does not have the issue with the id’s of the categories. But it requires the internal id of the style to which the combination must be attached.
During the generation of the combination CSV file, we also take care of the pictures. Therefore, for each style, we call the Stanley/Stella Product Image API to retrieve the URL’s of the related pictures. We sort them by color code.
For each style and each variant:
We calculate the difference between the price selected for the product (price of the first variant) and the price of the current variant.
We concatenate the URL’s of the pictures, separated by a comma, and fill this in the CSV line.
We then add a row with all data at variant level.