AvS_FastSimpleImport

Wrapper for Magento ImportExport functionality which imports data from arrays

View the Project on GitHub avstudnitz/AvS_FastSimpleImport

Product Import

Simple Products

Sample code:

$data = array(
    array(
        'sku' => '1234567',
        '_type' => 'simple',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'name' => 'Simple Product',
        '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());
}

Grouped Products

Sample code:

$data = array(
    array(
        'sku' => 'simple1',
        '_type' => 'simple',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'name' => 'Simple Product 1',
        'description' => 'Default',
        'short_description' => 'Default',
        'price' => 10,
        'weight' => 0,
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'qty' => 99,
        'is_in_stock' => 1,
    ),
    array(
        'sku' => 'simple2',
        '_type' => 'simple',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'name' => 'Simple Product 2',
        'description' => 'Default',
        'short_description' => 'Default',
        'price' => 10,
        'weight' => 0,
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'qty' => 99,
        'is_in_stock' => 1,
    ),
    array(
        'sku' => 'grouped',
        '_type' => 'grouped',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'name' => 'Grouped Product',
        'description' => 'Default',
        'short_description' => 'Default',
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'is_in_stock' => 1,
        '_associated_sku' => array('simple1', 'simple2'),
        '_associated_position' => array('1', '2'),
    ),
);

try {
    /** @var $import AvS_FastSimpleImport_Model_Import */
    $import = Mage::getModel('fastsimpleimport/import');
    $import
        ->setUseNestedArrays(true)
        ->processProductImport($data);
} catch (Exception $e) {
    print_r($import->getErrorMessages());
}

Configurable Products

Sample code:

$data = array(
        array(
        'sku' => 'simple1',
        '_type' => 'simple',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'name' => 'Simple Product 1',
        'description' => 'Default',
        'short_description' => 'Default',
        'price' => 10,
        'weight' => 0,
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'qty' => 99,
        'is_in_stock' => 1,
        'color' => 'red',
    ),
    array(
        'sku' => 'simple2',
        '_type' => 'simple',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'name' => 'Simple Product 2',
        'description' => 'Default',
        'short_description' => 'Default',
        'price' => 10,
        'weight' => 0,
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'qty' => 99,
        'is_in_stock' => 1,
        'color' => 'green',
    ),
    array(
        'sku' => 'configurable',
        '_type' => 'configurable',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'price' => 10,
        'name' => 'Configurable Product',
        'description' => 'Default',
        'short_description' => 'Default',
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'is_in_stock' => 1,
        '_super_products_sku' => array('simple1', 'simple2'),
        '_super_attribute_code' => 'color',
    ),
);

try {
    /** @var $import AvS_FastSimpleImport_Model_Import */
    $import = Mage::getModel('fastsimpleimport/import');
    $import
        ->setUseNestedArrays(true)
        ->processProductImport($data);
} catch (Exception $e) {
    print_r($import->getErrorMessages());
}

Bundle Products

Sample code:

$data = array(
    array(
        'sku' => 'simple1',
        '_type' => 'simple',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'name' => 'Simple Product 1',
        'description' => 'Default',
        'short_description' => 'Default',
        'price' => 10,
        'weight' => 0,
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'qty' => 99,
        'is_in_stock' => 1,
    ),
    array(
        'sku' => 'simple2',
        '_type' => 'simple',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'name' => 'Simple Product 2',
        'description' => 'Default',
        'short_description' => 'Default',
        'price' => 20,
        'weight' => 0,
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'qty' => 99,
        'is_in_stock' => 1,
    ),
    array(
        'sku' => 'bundle',
        '_type' => 'bundle',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'price' => 10,
        'name' => 'Bundle Product',
        'description' => 'Default',
        'short_description' => 'Default',
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'is_in_stock' => 1,
        'price_view' => 'as low as',
        'price_type' => 1,
        '_bundle_option_title' => array('Option 1', 'Option 1'),
        '_bundle_option_type' => 'select',
        '_bundle_option_position' => 1,
        '_bundle_option_required' => 1,
        '_bundle_product_sku' => array('simple1', 'simple2'), 
        '_bundle_product_position' => array(1, 2), 
        '_bundle_product_is_default' => array(true, false), 
        '_bundle_product_qty' => array(1, 2), 
        '_bundle_product_price_value' => array(10, 20), 
        '_bundle_product_can_change_qty' => array(1, 0), 
        '_bundle_option_store' => array(4, 5, 6),
        '_bundle_option_store_title' => array('Opción 1', 'Opţiune 1', 'Optsioon 1')
    )
);
        
try {
    /** @var $import AvS_FastSimpleImport_Model_Import */
    $import = Mage::getModel('fastsimpleimport/import');
    $import
        ->setUseNestedArrays(true)
        ->processProductImport($data);
} catch (Exception $e) {
    print_r($import->getErrorMessages());
}

Deletion of products

$data = array(
    array(
        'sku' => '1234567',
    ),
    array(
        'sku' => '1234568',
    ),
    // add more products here
);

/** @var $import AvS_FastSimpleImport_Model_Import */
$import = Mage::getModel('fastsimpleimport/import');
try {
    $import
        ->setBehavior(Mage_ImportExport_Model_Import::BEHAVIOR_DELETE)
        ->processProductImport($data);
} catch (Exception $e) {
    print_r($import->getErrorMessages());
}

Download external Images

You can now define the target filename of downloaded images, they can differ from the source url. Example:
'_media_image' => 'http://upload.wikimedia.org/wikipedia/meta/6/6d/Wikipedia_wordmark_1x.png',
'_media_target_filename' => 'wikipedia.jpg',
'image' => 'wikipedia.jpg',
'small_image' => 'wikipedia.jpg',
'thumbnail' => 'wikipedia.jpg',

Notes