Magento imports images

I am obsessed with images that are not displayed with their products. When I create a product and insert the image with this product manually (managing products), the image shows that is great. However, we have more than 1000 images of products that need to be downloaded, (all product information is already uploaded, I just need to add images) I exported the CSV file of the products, and the working address of the image is / n / g / image1.jpg Then I copied this but changed the image to image2.jpg, image3.jpg, etc. Then I uploaded new images to the directory of this folder on our server, thinking that this is enough. Then I download the CSV file, deleting the cache and retelling the data, however, no new images are visible, and the degradation of the working image is not displayed. I filled the image, small_image and thumbnails in CSV. All images have the desired size, etc.

Could tell me even more, where can I just have 1 image folder in the directory where all my images are stored? Thanks

I am using Magento version 1.7.0.2

+6
source share
4 answers

First of all, your image should be stored in the media>import directory

then in your csv file just write in the image column /imagename.jpg

it will find the same name in the import directory, if the image exists, then it will load the image

EDIT

if you don't have an import directory just create it

+14
source

I'm sorry to say, but behind the scenes with magento images, there is more to it than just pasting the file name into the database and linking to your image. Generating a cache in itself is quite complicated. I find it difficult for you to do it the way you try.

Having said that, I have a suggestion. Since your images are already on the server, I suggest you write a simple php script to tell magento to attach them to the product image. It can be automated, but I will give you a small example below ...

To attach an image, you simply go to a URL like this http://yoursite.com/imageattacher.php?sku=YOURSKU&image=yourimagefilename.jpg

The script will look like this: create a file in your purple ROOT and name it imageattacher.php. Upload images to the magento media import directory. I have not tested this, but it should work.

 <?php // Initialize magento for use outside of core umask(0); require_once 'app/Mage.php'; Mage::app('admin'); // Get the variables from the URL $sku = $_GET["sku"]; $imageName = $_GET["image"]; // get the image from the import dir $import = Mage::getBaseDir('media') . DS . 'import/' . $imageName; // Load the product by sku $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku); // if the product exists, attempt to add the image to it for all three items if ($product->getId() > 0) { // Add the images and set them for their respective usage (the radio button in admin) $product->addImageToMediaGallery($import,array('image', 'small_image', 'thumbnail'),false,false); // Make the changes stick $product->save(); } ?> 

See http://www.danneh.org/2012/05/creating-products-programmatically-magento/

+3
source

In the end, the problem was that there was no import folder in the media directory. Images have been uploaded to this folder. The image column in CSV was changed to / image 1.jpg, which allowed them to display on the website.

0
source

I had to import a bunch of images of the Magento product, which were all named SKU (e.g. 123456.jpg). This is the script I used to import them, part of which is based on CarComp's answer. It will only work for numeric SKUs (e.g. 123456), but can be quite easily modified to handle alphanumeric characters.

 <?php require_once(__DIR__ . "/app/Mage.php"); Mage::app('admin'); class Sku_ImageLoader { private $_uploadDir; private $_imagePaths; public function setUploadDirectory($dir = null) { if (empty($dir)) { if (isset($this->_uploadDir)) return $this; $dir = 'upload'; } $this->_uploadDir = Mage::getBaseDir('media') . DS . $dir; // mkdir($this->_uploadDir . DS . "/loaded", 0770); return $this; } public function load() { $this->setUploadDirectory(); // Match product images like 123456.jpg $pattern = '[0-9][0-9][0-9][0-9][0-9][0-9].{jpg,gif,png}'; chdir($this->_uploadDir); $this->_imagePaths = glob($pattern, GLOB_BRACE); return $this; } public function showFiles() { $this->load(); echo "\r\n\r\nSorry, I wasn't able to upload the following image files in " . $this->_uploadDir . "\r\n\r\n<pre>\r\n"; print_r($this->_imagePaths); return $this; } private function _addImage($path) { $sku = (string)intval($path); try { echo "Loading SKU: {$sku} ... "; $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku); // if the product exists, attempt to add the image to it for all three items if (strpos(get_class($product), 'Catalog_Model_Product') !== false && $product->getId() > 0) { $product->addImageToMediaGallery($path,array('image', 'small_image', 'thumbnail'),false,false); $product->save(); echo " ok \r\n"; return true; } } catch (Exception $e) { echo "Exception thrown for {$sku}: " . $e->getMessage() . "\r\n"; } echo " (FAILED) \r\n"; return false; } private function _moveImage($path) { // rename($path, 'loaded' . DS . $path); unlink($path); } public function import() { echo "<pre>\r\n"; if (!isset($this->_imagePaths)) $this->load(); foreach ($this->_imagePaths as $path) { if ($this->_addImage($path)) { $this->_moveImage($path); } } return $this; } } $u = new Sku_ImageLoader(); $u->import()->showFiles(); ?> 
0
source

Source: https://habr.com/ru/post/952653/


All Articles