Images not imported
-
Just installed a fresh version of WordPress. Still running stock 2014 theme. Only plugins are Woocommerce and Woocommerce Import.
All items have imported, but none of the images.
No errors were presented. Successful completion messages were shown.
Did I miss something? Are the images supposed to import?
https://wordpress.org/plugins/woocommerce-oscommerce-import/
-
Found and fixed my problems.
- My client’s Non-std OSC installation had images in a different folder than the importer expected. Edited the importer to correct this.
- The importer was importing dummy files with 654k in size, none of which contains anything, because the target URL didn’t point to a real file. Added a cURL function to check for the actual existence of the file in the URL. If it doesn’t existing, nothing is processed.
If this plugin gets updated, I recommend placing a field where a user could indicate the location of their respective image folders. This would have solved my problem.
Can i please have a copy of your script ?
Kind regards. Thomas.
Here is what worked for me. Please note that I hard-coded the name of our images folder, rather than taking the time to create an options field where you could indicate the images folder input field [recommended]. You may need to modify that to match yours.
// new function to validate url for image to import function woocommerce_osc_validate_url($url){ $ch = curl_init($url); $opts = array(CURLOPT_RETURNTRANSFER => true, // do not output to browser CURLOPT_URL => $url, // set URL CURLOPT_NOBODY => true, // do a HEAD request only CURLOPT_TIMEOUT => 5); // set timeout curl_setopt_array($ch, $opts); $retval = curl_exec($ch); // do it! if ($retval !== FALSE){ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $retval = ($code == 200 ? TRUE : FALSE); // check if HTTP OK curl_close($ch); // close handle } // END IF return $retval; }
// modified the import_image function to use the CURL validator above function woocommerce_osc_import_image($url){ $attach_id = 0; $wp_upload_dir = wp_upload_dir(); $filename = $wp_upload_dir['path'].'/'.basename($url); if(file_exists($filename)) $url = $filename; // checking two folders because some fool stuffed some of our images in each // first look in default /img/ folder. $enc_url = rtrim($_POST['store_url'],'/').'/img/'.rawurlencode(basename($url)); // if not found, look in /images/ folder if (woocommerce_osc_validate_url($enc_url)===FALSE) $enc_url = rtrim($_POST['store_url'],'/').'/images/'.rawurlencode(basename($url)); // using CURL again, to copy file, for efficiency and to detect success/failure $fp = fopen($filename,'w'); $ch = curl_init($enc_url); curl_setopt($ch, CURLOPT_FILE, $fp); $data = curl_exec($ch); curl_close($ch); fclose($fp); // only create attachment information if the file copied successfully if ( $data === TRUE){ // the file copied correctly $wp_filetype = wp_check_filetype(basename($filename), null ); $attachment = array( 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit' ); // Not sure why '37' but it is working, so I'll leave it... $attach_id = wp_insert_attachment( $attachment, $filename, 37 ); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data ); } return $attach_id; }
Hope this helps!
Thank you very much. I will look in to it when i get the time 🙂
Kind regards.
Can not get i working.
Maybe i will try again later.Thanks 🙂
Check to see if you have CURL running on your PHP5 server. If so, but still not working, let me know. I can post the entire file via download URL, with instructions on what to look for and what to modify. If not, you’ll know what to ask of your web host. 🙂
Hello mvbaxter
Would be nice to see the entire file. Think Thomas_69 and I are wondering where everything goes.
Looks a good contribution.
I imported over 700 products but no photos 🙁
I also did this locally. Just downloaded the mySQL file from one server and placed it on the server it was going to be imported to rather than doing a remote connection as suggested by another member on here.
Your recommendation of placing a field where a user could indicate the location of their respective image folders would be brilliant!
I also see that someone has made a contribution regarding categories listing twice.
http://wordpress.org/support/topic/categories-listing-twice?replies=7
Just a thought that maybe this could be integrated into the file too?
Thanks and all the best from UK
Andrew
You can download my modified version of this plugin here:
http://baxterfun.com/uploads/woocommerce-oscommerce-import.zipSorry, but I didn’t put much effort into documenting my changes. You’ll see the code indicated above within the .php file. I also haven’t added the field to indicate where the files are located. I didn’t see myself using this often enough to justify the effort.
To answer your question regarding where the files to … They go to your configured wp_upload_dir folder, so they blend with your other graphics, just as they would if you manually uploaded them.
Good luck!
- The topic ‘Images not imported’ is closed to new replies.