4

I want to extend the catalog import to support xml files. At this time it only supports csv and zip.

The source adapter is detected inside Magento\ImportExport\Model\Import\Adapter using file extension in the factory method:

$adapterClass = 'Magento\ImportExport\Model\Import\Source\\' . ucfirst(strtolower($type));

    if (!class_exists($adapterClass)) {
        throw new \Magento\Framework\Exception\LocalizedException(
            __('\'%1\' file extension is not supported', $type)
        );
    }
    $adapter = new $adapterClass($source, $directory, $options);

How can I add another adapter type?

At first I tought that a preference could be the right way, but preferences can't be used in this case because you can only specify preferences for injectable classes and this isn't injectable.

Actually this class is essentially a copy paste from Magento 1 Mage_ImportExport_Model_Import_Adapter class.

If I can't rewrite this class, can't use a preference or a plugin to extend this class functionality or functionalities of other classes related to the file type adapter, how to achieve that?

Sure I'm missing something obvious.

3

That's for sure a bug, please create issue on github.

For quick workaround you need create class in namespace Magento\ImportExport\Model\Import\Source. To autoload this class you should declare it the same as registration.php

"autoload": {
    "files": [
        "registration.php",
         "path/to/XmlImportSoure.php"
    ],
0

Here is few free import extensions for Magento 2 on GitHub with active development process, you can see lot of examples and useful code to get started with Magento 2 Import Customisation:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.