Impor Produk dan Gambar secara Massal di Magento

Banyak klien kami yang mendesain ulang e-commerce atau memindahkan e-commerce lama mereka ke platform Magento baru, ingin mengekspor produk dari e-commerce lama (lama) mereka ke yang baru. Di bawah ini kami menguraikan langkah-langkah untuk mengimpor data produk dan juga mengimpor gambar produk secara massal.

Mengimpor data produk

Pertama, Anda perlu mengetahui format data yang diperlukan oleh Magento untuk impor. Cara paling sederhana untuk melakukan ini adalah membuat sampel produk di Magento dan mengekspor semua produk. Caranya:

  1. Pergi ke System > Import/Export > DataFlow – Profiles
  2. Edit Export All Products profile dan Run Profile

File CSV yang diekspor akan ditempatkan di folder /var/ekspor. Anda perlu FTP ke hosting Magento Anda untuk mengambil file.

Buka file ini di aplikasi spreadsheet. Saya menggunakan OpenOffice Calc karena CSV bisa disimpan sebagai UTF-8 yang merupakan syarat yang diperlukan oleh Magento. Baris pertama menunjukkan nama field produk yang diperlukan oleh Magento. Anda akan membutuhkan semua field ini , bahkan jika nilainya kosong. Salin dan tempel kolom data dari CSV yang diekspor dari inventaris lama Anda ke Magento CSV. Anda tidak membutuhkan semua kolom, jika ragu biarkan saja dengan nilai yang sama dengan produk sampel Anda. Field yang harus Anda miliki adalah:

  • sku – ini adalah ID produk yang unik dan digunakan oleh Magento untuk mengalokasikan data ke produk yang benar dalam basis datanya. Impor dengan sku yang sama akan memperbarui data. Nama produk yang dikonversi menjadi huruf kecil dan dengan spasi diganti dengan tanda hubung bisa dijadikan sku.
  • type – wajib diatur. Saya menggunakan “simple”.
  • category_ids – mengganti ID kategori lama ke ID kategori baru. Cek ID kategori baru di Catalog > Manage Categories – ID akan kelihatan di bagian atas jika Anda sudah klik kategorinya. Jika Anda memiliki banyak kategori, Anda dapat mengekspornya dari phpMyAdmin menggunakan kueri SQL berikut:
    SELECT ccev.entity_id AS categoryID, cce.path, ccev.value FROM catalog_category_entity cce JOIN catalog_category_entity_varchar ccev ON ( cce.entity_id = ccev.entity_id )  GROUP BY ccev.entity_id ORDER BY path
    Saya kemudian menempatkan nilai-nilai ini dalam spreadsheet yang terpisah, dan secara manual memasukkan ID kategori lama yang sesuai di kolom berikutnya. Sekarang saya bisa menggunakan fungsi LOOKUP Calc untuk memetakan setiap ID kategori lama ke yang baru di Magento CSV. Ini menghemat banyak waktu ketika melakukan perubahan pada alokasi kategori, dan juga mencegah saya harus secara manual memasukkan ID kategori baru untuk setiap produk.
  • image, small_image, thumbnail – biarkan kosong. Lebih baik mengimpor gambar secara terpisah (lihat di bawah) karena Magento tidak akan mengimpor produk jika tidak dapat menemukan gambar yang direferensikan (misalnya jika nama file gambar salah).

Setelah Anda memiliki semua data produk di kolom yang benar, simpan spreadsheet sebagai CSV, pastikan untuk menggunakan ‘quotes‘ di setiap field teks dan simpan dengan format UTF-8.

Sekarang Anda dapat mengimpor data produk dengan menjalankan Import All Products DataFlow profile. Unggah CSV Anda yang sudah diedit dan jalankan profil. Cukup lambat, silahkan ditunggu.

Mengimpor gambar produk

Setelah produk Anda ada di database Magento, Anda dapat melakukan impor terpisah untuk melampirkan gambar Anda ke produk.

  1. Pertama, masukkan gambar produk Anda ke folder /media/impor lewat FTP. Magento akan mengubah ukuran gambar Anda ke dimensi yang benar saat impor, jadi cukup unggah gambar kualitas terbaik yang Anda miliki untuk setiap produk.
  2. Buat spreadsheet baru dengan kolom berikut: sku, image.
  3. Salin kolom sku dari CSV data produk Anda.
  4. Salin nama file gambar dari data lama yang sudah diekspor ke kolom gambar. Nama file harus memiliki format:
    /<namafile>.jpg

    (perhatikan slashnya).

  5. Simpan CSV sebagai import-product-images.csv di UTF-8.
  6. Buat profil DataFlow baru yang disebut Import Product Images dengan pengaturan berikut:
    • Entity Type: Products
    • Direction: Import
    • Data Transfer: Interactive
    • Type: CSV/Tab Separated
    • Field Mapping: sku > sku, image > image
  7. Unggah import-product-images.csv Anda dan Run Profil.

Voila! Produk Anda sekarang sudah memiliki gambar.

Catatan

Magento DataFlow tidak memiliki pesan kesalahan yang sangat membantu, misalnya ada pemberitahuan “Image not found” tetapi sistem tidak memberi tahu Anda gambar mana yang tidak ditemukan. Pesan “Product type not set” mungkin karena field teks tidak disertai dengan tanda kutip.

Menghapus gambar yang duplikat

 

Setiap kali Anda melakukan impor gambar produk, Magento menyalin gambar dari /media/import ke subdirektori folder /media/catalog/product. Hal itu tidak menggantikan gambar melainkan menambahkannya ke produk dan membuat salinan <filename>_2.jpg dll. Jadi setelah beberapa impor, Anda akan memiliki beberapa salinan dari setiap gambar di folder media Anda dan menggandakan gambar pada setiap produk . Anda dapat menghapus gambar duplikat dari data produk dengan skrip ini, dan menghapus gambar duplikat yang tidak digunakan dengan ekstensi ini. Namun, ketika mengimpor katalog beberapa kali, saya merasa cara ini lebih mudah untuk dilakukan:

  • Hapus folder /media/catalog/product.
  • Hapus referensi gambar produk di database Magento menggunakan SQL berikut:
    DELETE FROM catalog_product_entity_media_gallery
    DELETE FROM catalog_product_entity_media_gallery_value

Hati-hati! Lakukan hal ini untuk menghapus semua gambar produk dan import ulang lagi. Setelah Anda berhasil mengimpor semua gambar, Anda dapat dengan aman menghapus gambar di /media/import untuk meringankan ruang server.



 

Magento Bulk Product Import with Images

Most commonly when a client approach us with an ecommerce redesign or moving their old ecommerce to a new Magento platform, they want to export products from their legacy (old) ecommerce to a new one. Below we outline the steps to import product data and also importing product images by bulk.

Importing product data

First, you will need to know the data format required by Magento for import. The simplest way to do this is to create a sample product in Magento and export all products. To do this:

  1. Go to System > Import/Export > DataFlow – Profiles
  2. Edit the Export All Products profile and Run Profile

The exported CSV file will be placed in the /var/export folder. You will need to FTP into your Magento hosting to retrieve the file.

Open this file in a spreadsheet application. I used OpenOffice Calc as it allows the CSV to be saved as UTF-8 which is required by Magento. The first row shows the product field names required by Magento – for your first import, you will need all these fields to be present, even if the values are blank. Copy and paste the columns of data from the CSV exported from your old inventory into the Magento CSV. You don’t need all the columns, if in doubt just leave them with the same values as your sample product. The values you must have are:

  • sku – this is the unique product ID and is used by Magento to allocate the data to the correct product in its database. Any subsequent imports with the same sku will update the data. I didn’t have unique skus from my previous inventory so I created them using the product names converted to lowercase and with spaces replaced by hyphens.
  • type – this must be set. I used “simple”.
  • category_ids – these will need to be mapped from your old categories to the new categories in Magento. You can look up the Magento category IDs in Catalog > Manage Categories by clicking on the category – the ID will be shown at the top. If you have a lot of categories like I did, you can export them from phpMyAdmin using the following SQL query:
    SELECT ccev.entity_id AS categoryID, cce.path, ccev.value FROM catalog_category_entity cce JOIN catalog_category_entity_varchar ccev ON ( cce.entity_id = ccev.entity_id )  GROUP BY ccev.entity_id ORDER BY path
    I then placed these values in a separate spreadsheet, and manually entered the corresponding old category ID in the next column. Now I could use Calc’s LOOKUP function to map each old category ID to the new one in the Magento CSV. This saved a lot of time when making changes to category allocations, and also prevented me having to manually enter the new category IDs for each product.
  • image, small_image, thumbnail – leave these blank. It’s better to import the images separately (see below) because Magento will not import the product if it can’t find the referenced image (for instance if the image filename is wrong).

Once you have all your product data in the correct columns, save the spreadsheet as a CSV, making sure to use quotes around text fields and to save in UTF-8.

Now you can import the product data by running the Import All Products DataFlow profile. Upload your edited CSV and run the profile. It’s pretty slow, taking about a second a product, so now may be a good time for a cup of tea.

Importing product images

Now that your products exist in the Magento database, you can perform a separate import to attach your images to the products.

  1. First, FTP your product images to the /media/import folder of your Magento installation. Magento will resize your images to the correct dimensions on import, so just upload the best quality image you have for each product.
  2. Create a new spreadsheet with the following columns: sku, image.
  3. Copy the sku column from your product data CSV.
  4. Copy the image filenames from your old inventory export to the image column. The filenames should have the format:
    /<filename>.jpg

    (note the leading slash).

  5. Save the CSV as import-product-images.csv in UTF-8.
  6. Create a new DataFlow profile called Import Product Images with the following settings:
    • Entity Type: Products
    • Direction: Import
    • Data Transfer: Interactive
    • Type: CSV/Tab Separated
    • Field Mapping: sku > sku, image > image
  7. Upload your import-product-images.csv and Run Profile.

Voila! Your products should now have images.

Notes

Magento DataFlow does not have very helpful error messages, for example it will tell you “Image not found” but not tell you which image. The mysterious “Product type not set” message is probably because a text field is not enclosed in quotes.

Removing duplicate images

Every time you run a product image import, Magento copies the image from /media/import into a subdirectory of the /media/catalog/product folder. Annoyingly, it does not replace the image but rather adds it to the product and creates a copy <filename>_2.jpg etc. So after several imports, you will have several copies of each image in your media folder and duplicate images on each product. You can remove the duplicate images from the product data with this script, and delete unused duplicate images with this extension. However, when importing the complete catalog several times, I found it simpler to:

  • Delete the /media/catalog/product folder.
  • Delete the product image references in the Magento database using the following SQL:
    DELETE FROM catalog_product_entity_media_gallery
    DELETE FROM catalog_product_entity_media_gallery_value

Be warned! Only do this to clear all product images and start again.
Once you have successfully imported all images, you can safely delete any images in /media/import to free up server space.