Alexenn Posted April 19, 2016 Share Posted April 19, 2016 (edited) Bonjour à tous, je rencontre actuellement un problème avec les images liées aux produits. En effet j'ai d'ors-et-déjà fait l'import de mes articles dans ma base prestashop, et maintenant j'aimerais pouvoir ajouter chaque images d'un produit, et lié tel produit à telle image. Après plusieurs recherches j'en suis arrivé au script suivant : $url = str_replace(' ', '%20', 'http://***/prototype/img/p/2/0/20.jpg'); $image = new Image(); $image->id_product = 7; $image->position = Image::getHighestPosition(7) + 1; $image->cover = false; if (@fopen($url, 'r') == false) $error = true; else if (($field_error = $image->validateFields(false, true)) === true && ($lang_field_error = $image->validateFieldsLang(false, true)) === true && $image->add()) { $image->associateTo($shops); if (!AdminImportController::copyImg($object->id, $image->id, $url)) { $image->delete(); $this->errors[] = sprintf(Tools::displayError('Error copying image: %s'), $url); } } else $error = true; Ainsi quand je l'exécute il m'ajoute bien un champ dans la table ps_image, ainsi que ps_image_lang et ps_image_shop, mais malgré ça l'image ne semble pas liée au produit possédant l'id numéro 7 (dans l'exemple ci-dessus). Ainsi je viens poser ma question à certaines personnes qui connaîtraient bien ce procédé sous prestashop, me manque-t-il quelque chose, une étape pour lié l'image à l'article ? Edited June 16, 2016 by Alexenn (see edit history) Link to comment Share on other sites More sharing options...
Eolia Posted April 19, 2016 Share Posted April 19, 2016 Il ne manquerait pas un $image->save() ou $image->update() par hasard ? Je dis ça, je n'ai rien dit Link to comment Share on other sites More sharing options...
Alexenn Posted April 20, 2016 Author Share Posted April 20, 2016 Arf, effectivement ça peut être intéressant d'enregistrer mon ajout 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