0

Is it possible to import Magento products using MAGMI from a script by specifying a single profile, but with multiple import files?

For example, I have hundreds of brands - each with their own import file. Can I write a simple script that will loop through the list of my import files and call magmi.php with my single profile (all of my new imports use the same profile) and use the respective brand import file as a parameter?

Instead having to create a profile for each brand...:

php magmi.cli.php -profile=brand1importnew -mode=xcreate

I would like to use a single profile, loop through each brand in the script and specify the brand (or an import file) as an parameter:

php magmi.cli.php -profile=importnew -mode=xcreate -file=brand1.csv

Does this ability exist within magmi?

ctroyp
  • 1
  • 3

1 Answers1

0

Magmi can only import one file at a time. You can instead use a simple bash script to loop through a set of CSV files and run the Magmi CLI for each file.

  1. Create a file named import.sh
  2. In the file, paste the following:

    #!/bin/bash
    
    FILES=/path/to/import/*.csv
    for f in $FILES
    do
         echo "Running Magmi import with file: $f"
         php magmi.cli.php -profile=importnew -mode=xcreate -CSV:filename="${f}"
         wait
    done
    
  3. Change the /path/to/import/ to the directory containing your CSV import files.
  4. Save import.sh in the same directory as magmi.cli.php
  5. Now run the file by using the command sh import.sh from shell.

The file will loop through the CSV files and run the php magmi.cli.php ... command for each file it finds.

Axel
  • 10,732
  • 2
  • 30
  • 43
  • The -CSV parameter is what I was looking missing. Building a script for this is what I desired. Sorry, noob here so I am unable to vote you but! – ctroyp Oct 07 '14 at 14:48
  • BTW, how can I assure that it will only run one execution (import) a a time? Will it wait to loop to the next iteration until the current import is complete? – ctroyp Oct 07 '14 at 15:01
  • I've added `wait` below the PHP call which should in theory wait for the process to finish before continuing. It's untested though. – Axel Oct 07 '14 at 18:02
  • This is what I have located in the cli direcctory. When I exeute it, I get no errors, but nothing is imported at all: --------- #!/bin/bash FILES=/home/user1/public_html/var/import/TEMP/new_products_m*.csv for f in $FILES do date echo "Running Magmi import with file: $f" FILEPATH=${FILES}${f} php-cli magmi.cli.php -profile=ppwd_import_new -mode=xcreate -CSV:filename=$FILEPATH wait date echo "Completed import of $f" echo "" done ------ The profile exists and the paths are echo'ing correctly. Also tried with 'php' and 'php-cli'. – ctroyp Oct 09 '14 at 03:19
  • RESOLVED: php magmi.cli.php -profile=importnew -mode=xcreate -CSV:filename="${f}" instead of php magmi.cli.php -profile=importnew -mode=xcreate -CSV:filename="${FILES}${f}" Found the answer by looking in magmi/state/progress.txt Hope this helps someone else! – ctroyp Oct 09 '14 at 14:52