Boilerplate between the Magento API and ImportExport, so that you can do fast Array/XMLRPC/SOAP based product imports.

Overview

What are the main features of ApiImport?

  1. The glaringly obvious one: being able to do imports programmatically rather than manually uploading a CSV file.
  2. Importing bundled products.
  3. Importing categories.
  4. Importing attributes, attribute sets and attribute groups.
  5. Associate attribute(s) with an attribute group in one or more attribute sets you specify.
  6. Reindex products after they are imported.
  7. Automatic creation of dropdown attribute values.
  8. Useful events for enriching your entities from other Magento modules.

Additionally, ApiImport is 100% free from rewrites - making it upgrade-proof and reliable.

How do I install ApiImport?

ApiImport is both modman and composer compatible.

Install directly with modman

./modman clone ApiImport https://github.com/danslo/ApiImport.git

Install through composer

Add something like the following to your composer.json:

{
    "require": {
        "danslo/api-import": "1.1.*"
    },
    "extra": {
        "magento-root-dir": "htdocs/"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/danslo/ApiImport.git"
        },
        {
            "type": "composer",
            "url": "http://packages.firegento.com"
        }
    ]
}

Afterwards, issue the composer install command.

How do I use ApiImport?

Access it directly through Magento models

getMessage(), $e->getCustomMessage()); }">


require_once 'app/Mage.php';

Mage::init('admin');

$api = Mage::getModel('api_import/import_api');
try {
    $api->importEntities($anArrayWithYourEntities, $entityType, $optionalImportBehavior);
} catch (Mage_Api_Exception $e) {
    printf("%s: %s\n", $e->getMessage(), $e->getCustomMessage());
}

Access it through the Magento Webservices API (any SOAP/XMLRPC capable language)



require_once 'app/Mage.php';

Mage::init('admin');

// Get an XMLRPC client.
$client = new Zend_XmlRpc_Client(
    Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . 'api/xmlrpc/');

// For testing, just set an infinite timeout.
$client->getHttpClient()->setConfig(array('timeout' => -1));

// Login to the API and get a session token.
$session = $client->call('login', array($yourApiUser, $yourApiKey));

// Import regular entities (products, categories, customers).
$client->call('call', array(
    $session, 
    'import.importEntities', 
    array($anArrayWithYourEntities, $entityType, $optionalImportBehavior)
));

// Import attribute sets.
$client->call('call', array(
    $session,
    'import.importAttributeSets',
    array($anArrayWithYourAttributeSets, $optionalImportBehavior)
));

// Import attributes.
$client->call('call', array(
    $session, 
    'import.importAttributes', 
    array($anArrayWithYourAttributes, $optionalImportBehavior)
));

// Import attribute assocations.
$client->call('call', array(
    $session, 
    'import.importAttributeAssociations', 
    array($anArrayWithYourAssociations, $optionalImportBehavior)
));

// End our session.
$client->call('endSession', array($session));

Import CSV file

getMessage(), $e->getCustomMessage()); }">


require_once 'app/Mage.php';

Mage::init('admin');

/** @var Danslo_ApiImport_Model_Import_Api $api */
$api = Mage::getModel('api_import/import_api');

try {
    $file = fopen('var/import/products.csv', 'r');
    
    $entities = array();
    $header = fgetcsv($file);
    while ($row = fgetcsv($file)) {
        $entities[] = array_combine($header, $row);
    }

    $api->importEntities($entities);
} catch (Mage_Api_Exception $e) {
    printf("%s: %s\n", $e->getMessage(), $e->getCustomMessage());
}

What kind of data does ApiImport expect?

Entities

Because ApiImport is built as an extension to Magento's Import/Export functionality, it expects the exact same format! The only difference is that you are now supplying ApiImport with the data in an array format, rather than a CSV file. CSV column names are simply array keys, and CSV values are array values.

The Danslo_ApiImport_Helper_Test class provides several examples on how to programmatically generate your entities.

Another useful trick to figure out what to give to ApiImport is to simply use Magento to generate an exported CSV file of some sample entities.

For attributes, attribute sets and associate attributes to attribute groups in an attribute set, you can have a look to test.php, where you can find some example data. It's not the same than CSV because there is no way to import it with CSV in Magento.

Entity types

The second parameter to importEntities specifies what kind of entity is imported. By default it will assume you are importing products. If you want to import a different kind of entity, use the return value of any of these methods:

  1. Mage_ImportExport_Model_Import_Entity_Product::getEntityTypeCode()
  2. Mage_ImportExport_Model_Import_Entity_Customer::getEntityTypeCode()
  3. Danslo_ApiImport_Model_Import_Entity_Category::getEntityTypeCode()

Import behaviors

Magento will choose a replace behavior by default. If you would like to use another import behavior, you can pick one of these:

  1. Mage_ImportExport_Model_Import::BEHAVIOR_APPEND - Tries to append images, related products, etc. instead of replacing them.
  2. Mage_ImportExport_Model_Import::BEHAVIOR_REPLACE - Simply replaces the data in Magento with whatever you have in the entity array. Any data you do not specify in your array will not be deleted!
  3. Mage_ImportExport_Model_Import::BEHAVIOR_DELETE - Deletes every product you have specified. You probably don't want to use this.
  4. Danslo_ApiImport_Model_Import::BEHAVIOR_STOCK - Magento normally requires sku, _type, _attribute_set. This is not useful when you simply want to update stock of existing entities. With this behavior you can simply specify sku and qty!
  5. Danslo_ApiImport_Model_Import::BEHAVIOR_DELETE_IF_NOT_EXIST - Works with attributes, attribute sets and attribute associations import. Any data you do not specify in your array will be deleted! Send your array, data that there are in Magento and not in your array are deleted.

What if I only want to update stock?

Just import using the BEHAVIOR_STOCK behavior. See an example below:



require_once 'app/Mage.php';

Mage::init('admin');

$api = Mage::getModel('api_import/import_api');
$api->importEntities(
    array(
        array(
            'sku' => 'some_sku',
            'qty' => 10
        ),
        array(
            'sku' => 'some_other_sku',
            'qty' => 20
        )
        // etc
    ),
    Mage_ImportExport_Model_Import_Entity_Product::getEntityTypeCode(),
    Danslo_ApiImport_Model_Import::BEHAVIOR_STOCK
);

Obviously you would generate your entities array programmatically.

Where can I see the results?

As long as you have enabled developer mode (see index.php) and logging (see backend), ApiImport will write a log file every time it is run to:

var/log/import_export/%Y/%m/%d/%time%_%operation_type%_%entity_type%.log

There are plans to make this easily available through the backend.

What Magento versions are supported by ApiImport?

ApiImport is intentionally only compatible with Magento 1.6+.

Benchmark

The following is a very simple benchmark run done on a Virtual Machine running Debian, with 1GB RAM and without any MySQL optimizations. Your experience may vary. These are fully indexed results, mind you.

Generating 5000 simple products...
Starting import...
Done! Magento reports 5000 products in catalog.
========== Import statistics ==========
Total duration:      37.475983s
Average per product: 0.007495s
Products per second: 133.418781s
Products per hour:   480307.612782s
=======================================

Generating 5000 configurable products...
Starting import...
Done! Magento reports 10000 products in catalog.
========== Import statistics ==========
Total duration:      68.099526s
Average per product: 0.013620s
Products per second: 73.421950s
Products per hour:   264319.020648s
=======================================

Generating 5000 bundle products...
Starting import...
Done! Magento reports 15000 products in catalog.
========== Import statistics ==========
Total duration:      113.453821s
Average per product: 0.022691s
Products per second: 44.070794s
Products per hour:   158654.859310s
=======================================

Generating 5000 grouped products...
Starting import...
Done! Magento reports 20000 products in catalog.
========== Import statistics ==========
Total duration:      62.553724s
Average per product: 0.012511s
Products per second: 79.931292s
Products per hour:   287752.652192s
=======================================

License

Copyright 2014 Daniel Sloof

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Comments
  • Products import. Adding product to category and root of that category. How to?

    Products import. Adding product to category and root of that category. How to?

    I tried to add products to "Toners" category by specifying "_category => 'Accessories/Toners'" for each product. And it works great. Products are added to "Toners". But "Toners" category is part of "Accessories" category. Is it possible/how to add product not only to "Toners" but also to it's parent called "Accessories"? So when i click "Accessories" i want to see all products of it's sub-categories.

    opened by phpcoder2011 10
  • Add CSV example

    Add CSV example

    As you write:

    The glaringly obvious one: being able to do imports programmatically rather than manually uploading a CSV file.

    It's might be easy to provide an actual example :)

    (Also fixed the Exception, only that type supports the CustomMessage) Also fixes #32

    opened by barryvdh 6
  • Bundled product import

    Bundled product import

    Dear,

    I have an issue importing bundled products. If I add more than one product under 1 "default title" I get a Integrity constraint violation.

    PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (catalog_product_bundle_selection, CONSTRAINT FK_CAT_PRD_BNDL_SELECTION_OPT_ID_CAT_PRD_BNDL_OPT_OPT_ID FOREIGN KEY (option_id) REFERENCES `catalog_product_bundle_option)'

    The issue looks alot like this one: https://github.com/avstudnitz/AvS_FastSimpleImport/issues/55

    For the first product I pass these parameters:

    "_bundle_option_title" "_bundle_option_required" "_bundle_option_type" "_bundle_option_child" "_bundle_option_parent" "_bundle_option_position" "_bundle_product_sku" "_bundle_product_qty" "_bundle_product_can_change_qty" "_bundle_product_position"

    for the second product under the same title I pass these:

    "_bundle_option_title" "_bundle_product_sku" "_bundle_product_qty" "_bundle_product_can_change_qty"

    Are any other parameters required?

    Thanks in advance.

    opened by jensvandorpe 6
  • Enhancement/image support

    Enhancement/image support

    Here is a PR to : Add image support : now you can import image directly via Soap.

    Enhance benchmark :

    • Add a method to benchmark image import.
    • Add a method to benchmark localizable products.
    • Add possibility to send bulk of entities to Magento. That's how I benchmarked that is better to send calls of 2500 rows to be sure to keep a rate of transfer above 70rows/second.
    opened by willy-ahva 6
  • Need help to send products with different store view

    Need help to send products with different store view

    Hello Danslo,

    Can you help me to send to the ApiImport array with products which have different store views ? I tried some combination but no one ran, like : [1] => array(2) { [0] => array(15) { '_attribute_set' => string(7) "Default" 'short_description' => string(22) "Some short description" '_product_websites' => string(4) "base" 'status' => int(1) 'visibility' => int(4) 'tax_class_id' => int(0) 'is_in_stock' => int(1) 'sku' => string(10) "some_sku_1" '_type' => string(6) "simple" 'description' => string(24) "Some description default" 'name' => string(48) "Some attr cust2 product ( 1 ) ; Locale : default" 'price' => int(144) 'weight' => int(652) 'qty' => int(29) 'test_custom_attr' => string(27) "my custom attribute default" } [1] => array(6) { 'sku' => string(10) "some_sku_1" '_store' => string(5) "fr_fr" 'short_description' => string(24) "Courte description fr_fr" 'description' => string(17) "Description fr_fr" 'name' => string(41) "cust2 attr produit ( 1 ) ; Locale : fr_fr" 'test_custom_attr' => string(25) "Mon attribut custom fr_fr" } }

    Thanks for help, Willy

    opened by willy-ahva 6
  • Issue on product import from csv

    Issue on product import from csv

    Hello,

    When I try to import from a csv using the magento import workflow I have this issue :

    Fatal error: Call to undefined method Mage_ImportExport_Model_Import_Entity_Product::getStores() in app/code/local/Danslo/ApiImport/Model/Import/Entity/Product/Type/Bundle.php on line 113

    Any idea?

    opened by sebfie 5
  • Enhancement/attributes

    Enhancement/attributes

    Hi @danslo,

    This time I worked to add a way to import attributes, attribute sets, attribute groups and to associate attributes to attribute groups in one or more attribute sets you specify.

    I added three API methods : importAttributes, importAttributeSets and importAttributeAssociations.

    I added a new behavior : delete_if_not_exist. Works with attributes, attribute sets and attribute associations import. Any data you do not specify in your array will be deleted! Send your array, data that there are in Magento and not in your array are deleted.

    You are free to merge PR #17 which is the base of this one, and then merge this one.

    New stuff begin at #537be07.

    opened by willy-ahva 5
  • Preventing Error if $categoryTableTmp already exists

    Preventing Error if $categoryTableTmp already exists

    Create Temporary Table('catalog_category_entity_tmp') if not Exists, after receiving "Error: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'catalog_category_entity_tmp' already exists", during Category Import.

    opened by bragento 5
  • Stock Import - time consuming

    Stock Import - time consuming

    The stock Import for about 7000 skus is by far the most CPU & DB query time consuming process we have monitored on our system (Mage 1.9.0.1). The analysis through New Relic showed quite clearly how various slow select statements are executed in the process of loading the products by sku. Maybe a threshold would be useful at this point favoring either loading the full collection of stock items with joined skus and iterating through them during the import process against loading each item for itself.

    opened by bragento 5
  • create singleton only when module is enabled

    create singleton only when module is enabled

    Magento has a bug, where an exception is thrown, when you try to load a non existant singleton for the 2nd time.

    The first time, the registry key is created with the value false.

    The 2nd time, it will try to create the key again (because the condition is only if (!self::registry($registryKey)), but should be checking if the key is set) and raise an Exception.

    opened by bragento 4
  • Need some help to add image support in ApiImport

    Need some help to add image support in ApiImport

    Hello @danslo,

    Can you take a look at my improvement on my github ? https://github.com/willy-ahva/ApiImport/compare/enhancement/imageSupport

    I try to add in ApiImport the image support. According to the documentation (http://www.magentocommerce.com/knowledge-base/entry/importing-product-images), the array i send to the api is : http://pastebin.com/uC7FXeeV but I also try : http://pastebin.com/FX3qK210 and some others ...

    Actually, images are well imported in magento in media/import and then moved in media/catalog/product, but I've never been able to associate an image to the product. I tried a lot of things to debug but all seems to be good and I no longer have idea ...

    Maybe, when it will be finished I'll can send you a pull request. I hope you can help me, Thank you !

    opened by willy-ahva 4
  • Product Import improvement

    Product Import improvement

    Hello, Many Thanks for this great Module. I have added a Patch which will allow using the CategoryId for Category-Mapping. It is useful for Importing Products. I got this Improvement from http://www.avs-webentwicklung.de/nc/blog/artikel/magento-import-von-produkten-in-kategorien.html

    opened by EliasKotlyar 0
  • Multi behavior patch

    Multi behavior patch

    Allows to call attributes-related import functions (importAttributes, importAttributeSets and importAttributeAssociations) to be called with a comma-separated list of behaviors (to avoid calling the api twice with large amounts of data and therefore transmitting the same data twice)

    opened by 5b5 0
  • update catalog items

    update catalog items

    I'm trying to import categories in bulk using the Danslo_ApiImport_Model_Import_Entity_Category::getEntityTypeCode(); I'm not able to update the categories. I've been deleting the categories and re-importing.

    opened by bbtb1982 0
  • Meaningful Errors & MultiImageImport

    Meaningful Errors & MultiImageImport

    When some entities contain errors the plugin returned a soapfault with a generic error. This commit returns a success with entity ids that have been migrated and the error message.

    Allow importing _media_image_content columns directly to gallery.

    opened by admiral0 0
  • Cannot import _media_is_disabled value if 0

    Cannot import _media_is_disabled value if 0

    Hello,

    I use Talend to import 1'000 products per API call and I encountered some issues when I tried to import products gallery images.

    The code in ApiImport/code/Model/Import/Api/V2.php line 49 set the value of _media_is_disabled to NULL and it causes an SQL error because this value cannot be NULL.

    Why is it needed to remove empty values?

    Bug 
    opened by matiaso 12
Releases(1.1.4)
Owner
Daniel Sloof
Daniel Sloof
Kick-start you next Laravel based API with this awesome boilerplate 🚀

Laravel API boilerplate ?? An awesome boilerplate for your next Laravel 9 based API. It's only goal is to simply kick-start your API development and p

treblle 130 Dec 23, 2022
The Laravel Boilerplate Project - https://laravel-boilerplate.com

Laravel Boilerplate (Current: Laravel 8.*) (Demo) Demo Credentials Admin: [email protected] Password: secret User: [email protected] Password: secret Offici

Anthony Rappa 5.4k Jan 4, 2023
Generate dummy API endpoints from a simple PHP array.

Laravel Fake API Create placeholder API endpoints from a simple PHP array. LFA utilizes Faker for dummy data. Inspired by JSON Server. Installation To

Andy Abi Haidar 17 May 12, 2022
LaraAdmin is a Open source Laravel Admin Panel / CMS which can be used as Admin Backend, Data Management Tool or CRM boilerplate for Laravel with features like Advanced CRUD Generation, Module Manager, Backups and many more.

LaraAdmin 1.0 LaraAdmin is a Open source CRM for quick-start Admin based applications with features like Advanced CRUD Generation, Schema Manager and

Dwij IT Solutions 1.5k Dec 29, 2022
Hydra is a zero-config API boilerplate with Laravel Sanctum that comes with excellent user and role management API out of the box

Hydra - Zero Config API Boilerplate with Laravel Sanctum Hydra is a zero-config API boilerplate with Laravel Sanctum and comes with excellent user and

Hasin Hayder 858 Dec 24, 2022
A Laravel 5.8 API Boilerplate to create a ready-to-use REST API in seconds.

Laravel API Boilerplate (JWT Edition) for Laravel 5.8 Laravel API Boilerplate is a "starter kit" you can use to build your first API in seconds. As yo

Francesco Malatesta 1.2k Dec 18, 2022
Simple CRUD Product dengan PHP, MySQL & Bootstrap 5

Simple CRUD Product dengan PHP, MySQL & Bootstrap 5 Instalasi Pastikan sudah menginstall XAMPP atau sejenisnya Nyalakan service apache dan mysql buka

Gian Nurwana 1 Jan 3, 2022
A clean integration between Laravel and Expose. ⚡️

A clean integration between Laravel and Expose. This package provides an artisan expose command to quickly share you site via Expose. It will also rep

Ryan Chandler 21 May 23, 2022
Nue Boilerplate - A package for those of you who are tired of coding

Nue Boilerplate Baca Dokumentasi Disini Screenshot Documentation Requirements Installation Configuration Components Alert License Requirements Laravel

Noviyanto Rahmadi 0 Jun 19, 2022
A preconfigured Laravel, React, Typescript, Docker boilerplate to save you time!

Laravel - React - Docker - Boilerplate This repo is built with the following: Laravel 9 React 17 Vite 3 ESLint 8 TypeScript 4.7 Husky/Commit lint PHP

Lockhinator 23 Dec 14, 2022
WP React Plugin Boilerplate - WordPress Setting via React and Rest API

WP React Plugin Boilerplate is a starter WordPress plugin to develop WordPress Plugin via React and Rest API. WP React Plugin Boilerplate WP React Plu

Santosh Kunwar 36 Dec 6, 2022
Rest API boilerplate for Lumen micro-framework.

REST API with Lumen 5.5 A RESTful API boilerplate for Lumen micro-framework. Features included: Users Resource OAuth2 Authentication using Laravel Pas

Hasan Hasibul 484 Sep 16, 2022
A Laravel 8 and Vue 3 SPA boilerplate using tailwind styling and sanctum for authentication :ghost:

Laravel Vue Sanctum SPA Laravel and vue spa using tailwind (laravel/ui looks) for styling and sanctum for authentification Features Laravel 8 Vue + Vu

Hijen EL Khalifi 62 Dec 5, 2022
Laravel and AngularJS Starter Application Boilerplate featuring Laravel 5.3 and AngularJS 1.5.8

?? Zemke/starter-laravel-angular has been upgraded to AngularJS 1.5.8. ?? Zemke/starter-laravel-angular has been upgraded to Laravel 5.3. You can pull

Florian Zemke 372 Nov 21, 2022
Laravel 8 boilerplate in docker-compose with Treafik and SSL setup and github workflow ready for CI/CD pipeline

Laravel8 boilerplate Laravel 8 boilerplate in docker-compose with Treafik and SSL setup with .github workflow ready To start the containers in prod en

Tej Dahal 5 Jul 9, 2022
A simple and clean boilerplate to start a new SPA project with authentication and more features from fortify

A simple and clean boilerplate to start a new SPA project with authentication and more features from fortify. Its like the little sister of Jetstream, but as SPA.

Tobias Schulz 11 Dec 30, 2022
Very simple CRUD project, written in pure php. Designed as framework-agnostic as possible, and with basically no stack overflow if you can believe that

briefly simple CRUD pure php project for self improvement I try to make it purely in github - not only code, but any documentation (wiki), tasks (issu

Michał Jędrasiak 1 Jan 23, 2022
A Laravel 5 package that switchs default Laravel scaffolding/boilerplate to AdminLTE template and Pratt Landing Page with Bootstrap 3.0

AdminLTE template Laravel package A Laravel package that switch default Laravel scaffolding / boilerplate to AdminLTE template with Bootstrap 3.0 and

Sergi Tur Badenas 1.8k Jan 3, 2023
:elephant: A Laravel 6 SPA boilerplate with a users CRUD using Vue.js 2.6, GraphQL, Bootstrap 4, TypeScript, Sass, and Pug.

Laravel Vue Boilerplate A Laravel 6 Single Page Application boilerplate using Vue.js 2.6, GraphQL, Bootstrap 4, TypeScript, Sass and Pug with: A users

Alefe Souza 533 Jan 3, 2023