AvS_FastSimpleImport

Wrapper for Magento ImportExport functionality which imports data from arrays

View the Project on GitHub avstudnitz/AvS_FastSimpleImport

Usage

Basic Usage

After installation, call the module like this to import a single product:

// Import product:
$data = array(
    array(
        'sku' => '1234567',
        '_type' => 'simple',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'name' => 'Default',
        'price' => 0.99,
        'description' => 'Default',
        'short_description' => 'Default',
        'weight' => 0,
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'qty' => 76,
    ),
    // add more products here
);
    
/** @var $import AvS_FastSimpleImport_Model_Import */
$import = Mage::getModel('fastsimpleimport/import');
try {
    $import->processProductImport($data);
} catch (Exception $e) {
    print_r($import->getErrorMessages());
}

Dry run

You can check if your import data is correct with the following code:

$importer = Mage::getModel('fastsimpleimport/import');

$result = $importer->dryrunProductImport($data);

echo ($result  ? 'Input is OK' : 'Input has Errors');

echo "Messages: " . PHP_EOL;
echo $importer->getErrorMessage();

# for categories
Mage::getModel('fastsimpleimport/import')
    ->dryrunCategoryImport($data);

# for customers
Mage::getModel('fastsimpleimport/import')
    ->dryrunCustomerImport($data);

Just replace the word "process" in the above calls with "dryrun".

Where to add this code?

The above code is designed to be included into your own module. It can be called from a shell script as well, see our example.