Jump to content

ASTUCE: Requete SQL exportation produits CSV toutes les images et plus


Recommended Posts

Bonjour,
Voici une requete SQL export produit que j'utilise pour export csv de tout ce que j'ai besoin... Je n'en ai pas trouvé pour exporter toutes les images produits alors j'en ai crée une.
Fonctionne sur prestashop 1.6.1
Enjoy

SELECT 
p.`id_product` AS `ID`,
b.name as `Nom`,`reference`,
cl.`id_category` AS `ID Cat defaut`,
cl.`name` AS `Cat defaut`,
GROUP_CONCAT(DISTINCT(c.id_category) SEPARATOR ",") as categories,
GROUP_CONCAT(DISTINCT(case
    when length(im.`id_image`)=6 then
     concat('http://www.monsite.com/img/p/',insert(insert(insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),8,0,'/'),10,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=5 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),8,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=4 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=3 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=2 then
     concat('http://www.MONSITE.com/img/p/',insert(im.`id_image`,2,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=1 then
     concat('http://www.MONSITE.comm/img/p/',insert(im.`id_image`,2,0,'/'),im.`id_image`,'.jpg')  
     
    else ''
    end) SEPARATOR ",") as "Images",
sa.`price`,
ml.meta_title AS 'Marque',
ml.id_manufacturer AS 'Marque ID',
p.price as price,
sa.active as active,
p.ean13 AS 'EAN13',
p.upc AS 'UPC',
sav.`quantity` AS `quantite`,
p.visibility, 
p.indexed, 
pl.description_short, 
pl.description, 
pl.meta_title, 
pl.meta_keywords, 
pl.meta_description,
MAX(image_shop.id_image) id_image,

concat(pl.`link_rewrite`,'-',p.`id_product`,'.html') as "ProductURL google",
case
    when length(im.`id_image`)=6 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),8,0,'/'),10,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=5 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),8,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=4 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=3 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=2 then
     concat('http://www.MONSITE.com/img/p/',insert(im.`id_image`,2,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=1 then
     concat('http://www.MONSITE.comm/img/p/',insert(im.`id_image`,2,0,'/'),im.`id_image`,'.jpg')  
     
    else ''
    end as "ImgURL_1"
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_category c ON (cp.id_category = c.id_category)
LEFT JOIN `ps_product_lang` b ON (b.`id_product` = p.`id_product` AND b.`id_lang` = 1 AND b.`id_shop` = p.id_shop_default) 
LEFT JOIN `ps_image` i ON (i.`id_product` = p.`id_product`) 
LEFT JOIN `ps_manufacturer_lang` ml ON (p.id_manufacturer = ml.id_manufacturer)
LEFT JOIN `ps_stock_available` sav ON (sav.`id_product` = p.`id_product` AND sav.`id_product_attribute` = 0 AND sav.id_shop_group = 0  AND sav.id_shop = 1 )  JOIN `ps_product_shop` sa ON (p.`id_product` = sa.`id_product` AND sa.id_shop = p.id_shop_default) 
LEFT JOIN `ps_shop` shop ON (shop.id_shop = p.id_shop_default) 
LEFT JOIN `ps_image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop = p.id_shop_default) 
LEFT JOIN `ps_product_download` pd ON (pd.`id_product` = p.`id_product`) 
LEFT JOIN `ps_image` im on im.`id_product`= p.`id_product`

WHERE 1 AND pl.id_lang = 1 
GROUP BY sa.id_product 
ORDER BY p.`id_product` ASC

Edited by Alexandre-KM (see edit history)
  • Like 1
Link to comment
Share on other sites

 

Bonjour,

Voici une requete SQL export produit que j'utilise pour export csv de tout ce que j'ai besoin... Je n'en ai pas trouvé pour exporter toutes les images produits alors j'en ai crée une.

Fonctionne sur prestashop 1.6.1

Enjoy

SELECT 
p.`id_product` AS `ID`,
b.name as `Nom`,`reference`,
cl.`id_category` AS `ID Cat defaut`,
cl.`name` AS `Cat defaut`,
GROUP_CONCAT(DISTINCT(c.id_category) SEPARATOR ",") as categories,
GROUP_CONCAT(DISTINCT(case
    when length(im.`id_image`)=6 then
     concat('http://www.monsite.com/img/p/',insert(insert(insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),8,0,'/'),10,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=5 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),8,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=4 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=3 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=2 then
     concat('http://www.MONSITE.com/img/p/',insert(im.`id_image`,2,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=1 then
     concat('http://www.MONSITE.comm/img/p/',insert(im.`id_image`,2,0,'/'),im.`id_image`,'.jpg')  
     
    else ''
    end) SEPARATOR ",") as "Images",
sa.`price`,
ml.meta_title AS 'Marque',
ml.id_manufacturer AS 'Marque ID',
p.price as price,
sa.active as active,
p.ean13 AS 'EAN13',
p.upc AS 'UPC',
sav.`quantity` AS `quantite`,
p.visibility, 
p.indexed, 
pl.description_short, 
pl.description, 
pl.meta_title, 
pl.meta_keywords, 
pl.meta_description,
MAX(image_shop.id_image) id_image,

concat(pl.`link_rewrite`,'-',p.`id_product`,'.html') as "ProductURL google",
case
    when length(im.`id_image`)=6 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),8,0,'/'),10,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=5 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),8,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=4 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),6,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=3 then
     concat('http://www.MONSITE.com/img/p/',insert(insert(im.`id_image`,2,0,'/'),4,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=2 then
     concat('http://www.MONSITE.com/img/p/',insert(im.`id_image`,2,0,'/'),'/',im.`id_image`,'.jpg')
    when length(im.`id_image`)=1 then
     concat('http://www.MONSITE.comm/img/p/',insert(im.`id_image`,2,0,'/'),im.`id_image`,'.jpg')  
     
    else ''
    end as "ImgURL_1"
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_category c ON (cp.id_category = c.id_category)
LEFT JOIN `ps_product_lang` b ON (b.`id_product` = p.`id_product` AND b.`id_lang` = 1 AND b.`id_shop` = p.id_shop_default) 
LEFT JOIN `ps_image` i ON (i.`id_product` = p.`id_product`) 
LEFT JOIN `ps_manufacturer_lang` ml ON (p.id_manufacturer = ml.id_manufacturer)
LEFT JOIN `ps_stock_available` sav ON (sav.`id_product` = p.`id_product` AND sav.`id_product_attribute` = 0 AND sav.id_shop_group = 0  AND sav.id_shop = 1 )  JOIN `ps_product_shop` sa ON (p.`id_product` = sa.`id_product` AND sa.id_shop = p.id_shop_default) 
LEFT JOIN `ps_shop` shop ON (shop.id_shop = p.id_shop_default) 
LEFT JOIN `ps_image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop = p.id_shop_default) 
LEFT JOIN `ps_product_download` pd ON (pd.`id_product` = p.`id_product`) 
LEFT JOIN `ps_image` im on im.`id_product`= p.`id_product`

WHERE 1 AND pl.id_lang = 1 
GROUP BY sa.id_product 
ORDER BY p.`id_product` ASC

Bonjour, Merci pour ce partage s.t.p le code il faut le mettre ou ? www.MONSITE.com Remplacer uniquement cette adresse ? Amitiés

Edited by Soyons Solidaires (see edit history)
Link to comment
Share on other sites

  • 6 months later...
  • 5 months later...
  • 1 year later...

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