lsv/magento2-magmi-dump v3.0.1

Magmi datapump API for Magento 2





Requires (dev)










Magento 2 - Magmi data dump

Using object oriented methods to use with Magmi for Magento 2


composer require lsv/magento2-magmi-dump


You can see a working magento2 module here.

use Lsv\Datapump\Configuration;
use Lsv\Datapump\ItemHolder;
use Lsv\Datapump\Logger;
use Lsv\Datapump\Product\ConfigurableProduct;use Monolog\Handler\StreamHandler;
use Lsv\Datapump\Product\SimpleProduct;use Symfony\Component\Console\Output\NullOutput;

// First we need to create a logger, due to Magmi is using a non standardized method, we need to make a little of a work around
$stream = __DIR__ . '/logfile.log';
$monologHandler = new StreamHandler($stream);
$monolog = new Monolog\Logger('default', [$monologHandler]);
$logger = new Logger($monolog);

// Next we need a configuration
$configuration = new Configuration(
    'path/to/magento/root', // Path to the root of your magento installation
    'databse name', // The name of the database
    'database host', // The host of the database
    'database username', // The username to the database
    'database password' // The password to the database

// Now we need a instance of Magmi

// Now we can create our ItemHolder which will hold the product we gonna import
$magmi = \Magmi_DataPumpFactory::getDataPumpInstance('productimport');

// If you want to have progressbar on the import, you can change $output to your OutputInterface 
$output = new NullOutput();

// As magmi have troubles doing indexing on the fly, I have opted to turn it off, you can turn it with a true
$useMagmiIndexer = false;

$holder = new ItemHolder($configuration, $logger, $magmi, $output, $useMagmiIndexer);

// Now we can start by adding products to the item holder
$simpleProduct = (new SimpleProduct())
    ->setName('Simple product')
    ->setDescription('Product description')
    ->setTaxClass('tax name')

// This is the minimum data required for a simple product
// We can ofcourse add other attributes to the product
// But first you will need to manually add the attribute to the attribute set in magento backend, before it can be used

$simpleProduct->set('name_of_your_attribute', 'the_value');

// Now we have our simple product, we can now add it to our ItemHolder


// And we can now import it

// We have the option to create a "dry-run" which will not write to the database, but it will send the data to the console
// $holder->import(true) 

// Configurable product

// A configurable product must have a list of attributes to create the configurable product from the simple products
// Here we use both color and size as attributes we will create the configurable product out of

$configurable = new ConfigurableProduct(['color', 'size']);
// A configurable product also need some magento data
    ->setName('Configurable product')
    ->setQuantity(0, true); // With 0 and true, we will set the configurable product to always be in stock

// The configurable product price will automatically be generated out of the prices on the simple products

// Now we need to add simple products to our configurable product
$simple1 = new SimpleProduct();
$simple1->setTaxClass('tax name');
$simple1->set('color', 'blue');
$simple1->set('size', 'L');
// We need to set color and size on the simple product, because it is required by the configurable product

// And add another simple product to our configurable
$simple2 = new SimpleProduct();
$simple2->setTaxClass('tax name');
$simple2->set('color', 'green');
$simple2->set('size', 'M');

// If you already have created the simple products, you can also add them to the configurable product by using

// And lets add our configurable product to our itemHolder
// Only the configurable product should be added to the itemHolder as the simple products will automatically be imported and checked for missing attributes


  • [ ] Grouped products
  • [ ] Bundle products
  • [ ] Warehouse inventory
  • [x] Use Magento to copy media files, so its not hardcoded to media folder, and maybe can use correct storage
  • [ ] Add video to product
  • [ ] Delete products
  • [ ] Other things?