Skip to content

Instantly share code, notes, and snippets.

@wedancedalot
Last active December 28, 2019 15:29
Show Gist options
  • Save wedancedalot/7f2d6e355c8e745be044 to your computer and use it in GitHub Desktop.
Save wedancedalot/7f2d6e355c8e745be044 to your computer and use it in GitHub Desktop.
SQL queries used to dump data from prestashop 1.4. The output format is ready to be imported via prestashop 1.6 csv import out of box.
-------------------------------------------------
-- DUMP CATEGORIES
-- Fields to be imported: 'ID', 'Active (0/1)', 'Name *', 'Parent category', 'Root category (0/1)', 'Description', 'Meta title', 'Meta keywords', 'Meta description', 'URL rewritten', 'Image URL',
-------------------------------------------------
SELECT a.id_category, a.active, b.name, c.name as parent_name, 0 as is_root,
b.description, b.meta_title, b.meta_keywords, b.meta_description, b.link_rewrite, "" as image_url
FROM ps_category AS a
JOIN ps_category_lang AS b ON a.id_category = b.id_category
LEFT JOIN ps_category_lang AS c ON a.id_parent = c.id_category
GROUP by a.id_category;
-------------------------------------------------
-- DUMP PRODUCTS
-- Fields to be imported: 'ID', 'Active (0/1)', 'Name *', 'Categories (x,y,z...)', 'Price tax excluded or Price tax included', 'Tax rules ID', 'Wholesale price', 'On sale (0/1)', 'Discount amount', 'Discount percent', 'Discount from (yyyy-mm-dd)', 'Discount to (yyyy-mm-dd)', 'Reference #', 'Supplier reference #', 'Supplier', 'Manufacturer', 'EAN13', 'UPC', 'Ecotax', 'Width', 'Height', 'Depth', 'Weight', 'Quantity', 'Minimal quantity', 'Visibility', 'Additional shipping cost', 'Unity', 'Unit price', 'Short description', 'Description', 'Tags (x,y,z...)', 'Meta title', 'Meta keywords', 'Meta description', 'URL rewritten', 'Text when in stock', 'Text when backorder allowed', 'Available for order (0 = No, 1 = Yes)', 'Product available date', 'Product creation date', 'Show price (0 = No, 1 = Yes)', 'Image URLs (x,y,z...)', 'Delete existing images (0 = No, 1 = Yes)', 'Feature(Name:Value:Position)', 'Available online only (0 = No, 1 = Yes)', 'Condition', 'Customizable (0 = No, 1 = Yes)', 'Uploadable files (0 = No, 1 = Yes)', 'Text fields (0 = No, 1 = Yes)', 'Out of stock', 'ID / Name of shop', 'Advanced stock management', 'Depends On Stock', 'Warehouse',
-------------------------------------------------
SELECT p.id_product, p.active, pl.name AS 'Name',
GROUP_CONCAT(DISTINCT(cl.name) SEPARATOR ',') AS 'Categories (x,y,z...)',
p.price AS 'Price tax excluded or Price tax included',
p.id_tax_rules_group AS 'Tax rules ID',
p.wholesale_price AS 'Wholesale price',
p.on_sale AS 'On sale (0/1)',
IF(pr.reduction_type = 'amount', pr.reduction, '') AS 'Discount amount',
IF(pr.reduction_type = 'percentage', pr.reduction, '') AS 'Discount percent',
pr.from AS 'Discount from (yyyy-mm-dd)',
pr.to AS 'Discount to (yyyy-mm-dd)',
p.reference AS 'Reference #',
p.supplier_reference AS 'Supplier reference #',
ps.name AS 'Supplier',
pm.name AS 'Manufacturer',
p.ean13 AS 'EAN13',
p.upc AS 'UPC',
p.ecotax AS 'Ecotax',
p.width AS 'Width',
p.height AS 'Height',
p.depth AS 'Depth',
p.weight AS 'Weight',
p.quantity as 'Quantity',
p.minimal_quantity AS 'Minimal quantity',
'both' AS 'Visibility',
p.additional_shipping_cost AS 'Additional shipping cost',
p.unity AS 'Unity',
p.unit_price_ratio AS 'Unit price',
pl.description_short AS 'Short description',
pl.description AS 'Description',
IF(t.name IS NOT NULL, GROUP_CONCAT(DISTINCT(t.name) SEPARATOR ','), '') AS 'Tags (x,y,z...)',
pl.meta_title AS 'Meta title',
pl.meta_keywords AS 'Meta keywords',
pl.meta_description AS 'Meta description',
pl.link_rewrite AS 'URL rewritten',
pl.available_now AS 'Text when in stock',
pl.available_later AS 'Text when backorder allowed',
p.available_for_order AS 'Available for order (0 = No, 1 = Yes)',
'' AS 'Product available date',
p.date_add 'Product creation date',
p.show_price AS 'Show price (0 = No, 1 = Yes)',
GROUP_CONCAT(DISTINCT(concat('http://yoursite.com/img/p/', pi.id_product , '-', pi.id_image, '.jpg'))) AS image_urls,
0 AS 'Delete existing images (0 = No, 1 = Yes)',
GROUP_CONCAT(DISTINCT(CONCAT((fl.name), ':', (fvl.value), ':0')) SEPARATOR ',') AS 'Feature (Name:Value:Position)',
p.online_only AS 'Available online only (0 = No, 1 = Yes)',
p.condition AS 'Cond',
0 AS 'Customizable (0 = No, 1 = Yes)',
0 AS 'Uploadable files (0 = No, 1 = Yes)',
0 AS 'Text fields (0 = No, 1 = Yes)',
p.out_of_stock as 'Out of stock',
'1' AS 'ID',
null AS 'Action when out of stock',
null AS 'Depends on stock',
null AS 'Warehouse'
FROM ps_product p
LEFT JOIN ps_product_lang pl ON(p.id_product = pl.id_product)
LEFT JOIN ps_category_product cp ON(p.id_product = cp.id_product)
LEFT JOIN ps_category_lang cl ON(cp.id_category = cl.id_category)
LEFT JOIN ps_specific_price pr ON(p.id_product = pr.id_product)
LEFT JOIN ps_product_tag pt ON(p.id_product = pt.id_product)
LEFT JOIN ps_tag t ON(pt.id_tag = t.id_tag)
LEFT JOIN ps_image pi ON(p.id_product = pi.id_product)
LEFT JOIN ps_manufacturer pm ON(p.id_manufacturer = pm.id_manufacturer)
LEFT JOIN ps_supplier ps ON(p.id_supplier = ps.id_supplier)
LEFT JOIN ps_configuration conf ON conf.name = 'PS_SHOP_DOMAIN'
LEFT JOIN ps_feature_product fp ON p.id_product = fp.id_product
LEFT JOIN ps_feature_lang fl ON fp.id_feature = fl.id_feature
LEFT JOIN ps_feature_value_lang fvl ON fp.id_feature_value = fvl.id_feature_value
LEFT JOIN ps_feature f ON fp.id_feature = f.id_feature
LEFT JOIN ps_feature_value fv ON fp.id_feature_value = fv.id_feature_value
WHERE pl.id_lang = 1
AND cl.id_lang = 1
GROUP BY p.id_product;
-------------------------------------------------
-- DUMP ATTRIBUTES COMBINATIONS
-------------------------------------------------
-- Fields to be imported: 'Product ID*', 'Product Reference', 'Attribute (Name:Type:Position)*', 'Value (Value:Position)*', 'Supplier reference', 'Reference', 'EAN13', 'UPC', 'Wholesale price', 'Impact on price', 'Ecotax', 'Quantity', 'Minimal quantity', 'Impact on weight', 'Default (0 = No, 1 = Yes)', 'Combination available date', 'Image position', 'Image URL'
-------------------------------------------------
SELECT
p.id_product,
null,
GROUP_CONCAT(
DISTINCT concat(agl.public_name, ":", if(ag.is_color_group = 1, "color", "select"))
ORDER BY a.id_attribute_group
SEPARATOR ", "
) as combo,
GROUP_CONCAT(
DISTINCT al.name ORDER BY a.id_attribute_group SEPARATOR ", "
) as combo_val,
pa.supplier_reference,
pa.reference,
pa.ean13,
pa.upc,
pa.wholesale_price,
pa.unit_price_impact, -- not sure this one is correct, but our db has 0.00 everywhere
pa.ecotax,
pa.quantity,
pa.minimal_quantity,
pa.weight , -- not sure this one is correct
pa.default_on,
null as combo_avail_date,
null as image_pos,
GROUP_CONCAT(DISTINCT(concat("http://yoursite.com/img/p/", p.id_product , "-", pai.id_image, ".jpg"))) as img
FROM ps_product p
JOIN ps_product_attribute AS pa ON (p.id_product = pa.id_product)
LEFT JOIN ps_product_attribute_image AS pai ON (pa.id_product_attribute = pai.id_product_attribute AND pai.id_image > 0)
JOIN ps_product_attribute_combination AS pac ON (pac.id_product_attribute = pa.id_product_attribute)
JOIN ps_attribute AS a ON (pac.id_attribute = a.id_attribute)
JOIN ps_attribute_group AS ag ON (a.id_attribute_group = ag.id_attribute_group)
JOIN ps_attribute_group_lang AS agl ON (a.id_attribute_group = agl.id_attribute_group AND agl.id_lang = 1)
JOIN ps_attribute_lang AS al ON (pac.id_attribute = al.id_attribute AND al.id_lang = 1)
GROUP BY pac.id_product_attribute;
-------------------------------------------------
-- DUMP MANUFACTURERS
-- Fields to be imported: 'ID', 'Active (0/1)', 'Name *', 'Description', 'Short description', 'Meta title', 'Meta keywords', 'Meta description', 'Image URL'
-------------------------------------------------
SELECT m.id_manufacturer, m.active, m.name, ml.description, ml.short_description, ml.meta_title, ml.meta_keywords, ml.meta_description, concat("http://yoursite.com/img/m/", m.id_manufacturer, ".jpg") as img_url
FROM ps_manufacturer AS m
JOIN ps_manufacturer_lang AS ml ON (m.id_manufacturer = ml.id_manufacturer AND id_lang = 1)
GROUP BY m.id_manufacturer;
@bmsimo
Copy link

bmsimo commented Aug 29, 2017

Thank god i landed at this post , you just made me go from 2 weeks (probably) of work to a few minutes :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment