Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento importing images

I am getting stuck with images not displaying with their products. When I create a product and insert an image with that product manually through (manage products) the image shows which is great. However we have over 1000 product images which need to be uploaded, (all the product information is already up I just need to add the images) I have exported the products CSV file and the working image address is /n/g/image1.jpg I have then copied that but change the image to image2.jpg, image3.jpg etc. I then uploaded the new images into that folder directory on our server thinking that's enough. I then upload the CSV file blow the cache and reindex the data however no new images show and worse the working image doesn't display. I have filled in image, small_image and thumbnail details in the CSV. All images are correctly sized etc.

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

I'm using Magento version 1.7.0.2

like image 577
user1035650 Avatar asked Aug 28 '13 11:08

user1035650


People also ask

How do I import an image into Magento?

Upload product image files on local server. Upload the image files to the default folder for importing product images. Normally, you may use this path: pub/media/import. However, a different folder can be specified for the files on Magento server and the new path can be defined during the importing process.

Where does Magento store product images?

All the images are stored under the pub/media/catalog/product folder in the Magento root. If the product image name is abc. jpg then it's stored under the above folder with an a/b/abc.


2 Answers

First of all your image should store in media>import directory

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

it will find same imagename in import directory, if image exist then it will upload the image

EDIT

if you don't have import directory then simply create it

like image 66
Keyur Shah Avatar answered Sep 30 '22 18:09

Keyur Shah


I'm sorry to say, but there is more going on behind the scenes with magento images that it simply putting a filename in the database and linking to your image. The cache generation alone is pretty complex. I believe you are going to have a hard time doing it the way you are attempting.

That being said, I do 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. This could be automated, but i'll give you a small example below...

To attach an image, you would simply navigate to the url like this http://yoursite.com/imageattacher.php?sku=YOURSKU&image=yourimagefilename.jpg

The script would be like this... create a file in your magento ROOT and call it imageattacher.php. Upload your 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 this http://www.danneh.org/2012/05/creating-products-programmatically-magento/

like image 20
CarComp Avatar answered Sep 30 '22 17:09

CarComp