yaserch123 Posted March 22 Share Posted March 22 (edited) Bonjour, J’ai tenté d’exporter la base de données de mes produits sur PrestaShop en utilisant une requête MySQL. Cette requête vise à extraire les noms des produits, leur description, leur identifiant, les catégories et les liens des images. Cependant, après l’exécution de la requête et le téléchargement du fichier exporté, je constate que les liens des images ne fonctionnent pas. Une solution à me proposer s'il vous plait ? Edited March 23 by yaserch123 (see edit history) Link to comment Share on other sites More sharing options...
Mediacom87 Posted March 22 Share Posted March 22 Il y a 2 heures, yaserch123 a dit : Bonjour, J’ai tenté d’exporter la base de données de mes produits sur PrestaShop en utilisant une requête MySQL. Cette requête vise à extraire les noms des produits, leur description, leur identifiant, les catégories et les liens des images. Cependant, après l’exécution de la requête et le téléchargement du fichier exporté, je constate que les liens des images ne fonctionnent pas. Une solution à me proposer s'il vous plait ? La génération des liens des images n'est pas bon Link to comment Share on other sites More sharing options...
yaserch123 Posted March 22 Author Share Posted March 22 2 hours ago, Mediacom87 said: La génération des liens des images n'est pas bon Une solution à me proposer ? Link to comment Share on other sites More sharing options...
Mediacom87 Posted March 23 Share Posted March 23 Il y a 2 heures, yaserch123 a dit : Une solution à me proposer ? Oui, il faut coder les URL des images sconvenablement en décomposant leur ID en sous répertoire du répertoire img/p/. Par exemple, l'image ayant l'id 1695 a pour URL : /img/p/1/6/9/5/1695.jpg Link to comment Share on other sites More sharing options...
Mediacom87 Posted March 23 Share Posted March 23 Un truc dans ce style : SELECT p.id_product, pl.name AS product_name, pl.link_rewrite, pl.description_short, p.reference, p.price, -- Catégories associées GROUP_CONCAT(DISTINCT cl2.name SEPARATOR ', ') AS categories, -- Image 1 (SELECT CONCAT( 'https://ton-domaine.com/img/p/', MID(pi1.id_image,1,1), '/', IF(LENGTH(pi1.id_image) > 1, CONCAT(MID(pi1.id_image,2,1), '/'), ''), IF(LENGTH(pi1.id_image) > 2, CONCAT(MID(pi1.id_image,3,1), '/'), ''), IF(LENGTH(pi1.id_image) > 3, CONCAT(MID(pi1.id_image,4,1), '/'), ''), IF(LENGTH(pi1.id_image) > 4, CONCAT(MID(pi1.id_image,5,1), '/'), ''), pi1.id_image, '.jpg') FROM ps_image pi1 WHERE pi1.id_product = p.id_product ORDER BY pi1.position ASC LIMIT 0,1) AS image1, -- Image 2 (SELECT CONCAT( 'https://ton-domaine.com/img/p/', MID(pi2.id_image,1,1), '/', IF(LENGTH(pi2.id_image) > 1, CONCAT(MID(pi2.id_image,2,1), '/'), ''), IF(LENGTH(pi2.id_image) > 2, CONCAT(MID(pi2.id_image,3,1), '/'), ''), IF(LENGTH(pi2.id_image) > 3, CONCAT(MID(pi2.id_image,4,1), '/'), ''), IF(LENGTH(pi2.id_image) > 4, CONCAT(MID(pi2.id_image,5,1), '/'), ''), pi2.id_image, '.jpg') FROM ps_image pi2 WHERE pi2.id_product = p.id_product ORDER BY pi2.position ASC LIMIT 1,1) AS image2, -- Image 3 (SELECT CONCAT( 'https://ton-domaine.com/img/p/', MID(pi3.id_image,1,1), '/', IF(LENGTH(pi3.id_image) > 1, CONCAT(MID(pi3.id_image,2,1), '/'), ''), IF(LENGTH(pi3.id_image) > 2, CONCAT(MID(pi3.id_image,3,1), '/'), ''), IF(LENGTH(pi3.id_image) > 3, CONCAT(MID(pi3.id_image,4,1), '/'), ''), IF(LENGTH(pi3.id_image) > 4, CONCAT(MID(pi3.id_image,5,1), '/'), ''), pi3.id_image, '.jpg') FROM ps_image pi3 WHERE pi3.id_product = p.id_product ORDER BY pi3.position ASC LIMIT 2,1) AS image3, -- Image 4 (SELECT CONCAT( 'https://ton-domaine.com/img/p/', MID(pi4.id_image,1,1), '/', IF(LENGTH(pi4.id_image) > 1, CONCAT(MID(pi4.id_image,2,1), '/'), ''), IF(LENGTH(pi4.id_image) > 2, CONCAT(MID(pi4.id_image,3,1), '/'), ''), IF(LENGTH(pi4.id_image) > 3, CONCAT(MID(pi4.id_image,4,1), '/'), ''), IF(LENGTH(pi4.id_image) > 4, CONCAT(MID(pi4.id_image,5,1), '/'), ''), pi4.id_image, '.jpg') FROM ps_image pi4 WHERE pi4.id_product = p.id_product ORDER BY pi4.position ASC LIMIT 3,1) AS image4, -- Image 5 (SELECT CONCAT( 'https://ton-domaine.com/img/p/', MID(pi5.id_image,1,1), '/', IF(LENGTH(pi5.id_image) > 1, CONCAT(MID(pi5.id_image,2,1), '/'), ''), IF(LENGTH(pi5.id_image) > 2, CONCAT(MID(pi5.id_image,3,1), '/'), ''), IF(LENGTH(pi5.id_image) > 3, CONCAT(MID(pi5.id_image,4,1), '/'), ''), IF(LENGTH(pi5.id_image) > 4, CONCAT(MID(pi5.id_image,5,1), '/'), ''), pi5.id_image, '.jpg') FROM ps_image pi5 WHERE pi5.id_product = p.id_product ORDER BY pi5.position ASC LIMIT 4,1) AS image5 FROM ps_product p JOIN ps_product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = 1) LEFT JOIN ps_category_product cp ON p.id_product = cp.id_product LEFT JOIN ps_category_lang cl2 ON cp.id_category = cl2.id_category AND cl2.id_lang = 1 WHERE p.active = 1 GROUP BY p.id_product; 🛠️ À adapter : • Remplace https://ton-domaine.com par ton nom de domaine. • id_lang = 1 pour la langue (français par défaut). • Si tu veux plus de 5 images, je peux t’ajouter les colonnes correspondantes. Link to comment Share on other sites More sharing options...
yaserch123 Posted March 23 Author Share Posted March 23 12 hours ago, Mediacom87 said: Un truc dans ce style : SELECT p.id_product, pl.name AS product_name, pl.link_rewrite, pl.description_short, p.reference, p.price, -- Catégories associées GROUP_CONCAT(DISTINCT cl2.name SEPARATOR ', ') AS categories, -- Image 1 (SELECT CONCAT( 'https://ton-domaine.com/img/p/', MID(pi1.id_image,1,1), '/', IF(LENGTH(pi1.id_image) > 1, CONCAT(MID(pi1.id_image,2,1), '/'), ''), IF(LENGTH(pi1.id_image) > 2, CONCAT(MID(pi1.id_image,3,1), '/'), ''), IF(LENGTH(pi1.id_image) > 3, CONCAT(MID(pi1.id_image,4,1), '/'), ''), IF(LENGTH(pi1.id_image) > 4, CONCAT(MID(pi1.id_image,5,1), '/'), ''), pi1.id_image, '.jpg') FROM ps_image pi1 WHERE pi1.id_product = p.id_product ORDER BY pi1.position ASC LIMIT 0,1) AS image1, -- Image 2 (SELECT CONCAT( 'https://ton-domaine.com/img/p/', MID(pi2.id_image,1,1), '/', IF(LENGTH(pi2.id_image) > 1, CONCAT(MID(pi2.id_image,2,1), '/'), ''), IF(LENGTH(pi2.id_image) > 2, CONCAT(MID(pi2.id_image,3,1), '/'), ''), IF(LENGTH(pi2.id_image) > 3, CONCAT(MID(pi2.id_image,4,1), '/'), ''), IF(LENGTH(pi2.id_image) > 4, CONCAT(MID(pi2.id_image,5,1), '/'), ''), pi2.id_image, '.jpg') FROM ps_image pi2 WHERE pi2.id_product = p.id_product ORDER BY pi2.position ASC LIMIT 1,1) AS image2, -- Image 3 (SELECT CONCAT( 'https://ton-domaine.com/img/p/', MID(pi3.id_image,1,1), '/', IF(LENGTH(pi3.id_image) > 1, CONCAT(MID(pi3.id_image,2,1), '/'), ''), IF(LENGTH(pi3.id_image) > 2, CONCAT(MID(pi3.id_image,3,1), '/'), ''), IF(LENGTH(pi3.id_image) > 3, CONCAT(MID(pi3.id_image,4,1), '/'), ''), IF(LENGTH(pi3.id_image) > 4, CONCAT(MID(pi3.id_image,5,1), '/'), ''), pi3.id_image, '.jpg') FROM ps_image pi3 WHERE pi3.id_product = p.id_product ORDER BY pi3.position ASC LIMIT 2,1) AS image3, -- Image 4 (SELECT CONCAT( 'https://ton-domaine.com/img/p/', MID(pi4.id_image,1,1), '/', IF(LENGTH(pi4.id_image) > 1, CONCAT(MID(pi4.id_image,2,1), '/'), ''), IF(LENGTH(pi4.id_image) > 2, CONCAT(MID(pi4.id_image,3,1), '/'), ''), IF(LENGTH(pi4.id_image) > 3, CONCAT(MID(pi4.id_image,4,1), '/'), ''), IF(LENGTH(pi4.id_image) > 4, CONCAT(MID(pi4.id_image,5,1), '/'), ''), pi4.id_image, '.jpg') FROM ps_image pi4 WHERE pi4.id_product = p.id_product ORDER BY pi4.position ASC LIMIT 3,1) AS image4, -- Image 5 (SELECT CONCAT( 'https://ton-domaine.com/img/p/', MID(pi5.id_image,1,1), '/', IF(LENGTH(pi5.id_image) > 1, CONCAT(MID(pi5.id_image,2,1), '/'), ''), IF(LENGTH(pi5.id_image) > 2, CONCAT(MID(pi5.id_image,3,1), '/'), ''), IF(LENGTH(pi5.id_image) > 3, CONCAT(MID(pi5.id_image,4,1), '/'), ''), IF(LENGTH(pi5.id_image) > 4, CONCAT(MID(pi5.id_image,5,1), '/'), ''), pi5.id_image, '.jpg') FROM ps_image pi5 WHERE pi5.id_product = p.id_product ORDER BY pi5.position ASC LIMIT 4,1) AS image5 FROM ps_product p JOIN ps_product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = 1) LEFT JOIN ps_category_product cp ON p.id_product = cp.id_product LEFT JOIN ps_category_lang cl2 ON cp.id_category = cl2.id_category AND cl2.id_lang = 1 WHERE p.active = 1 GROUP BY p.id_product; 🛠️ À adapter : • Remplace https://ton-domaine.com par ton nom de domaine. • id_lang = 1 pour la langue (français par défaut). • Si tu veux plus de 5 images, je peux t’ajouter les colonnes correspondantes. Je tiens à vous remercier énormément pour votre aide précieuse, elle m'a été d'une grande utilité. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now