0

How do I add my table model to the list of valid entity types when extending Magento's Import functionality?

I have created a custom module which integrates into the admin panel and stores data in a custom table.

What I am trying to do is extend the Magento > System > Import/Export > Import feature to allow a custom CSV upload with data only for this custom table.

I have added the following to my config.xml file to create custom entities:

<importexport module="importexport">
  <import_entities>
    <my_entity translate="label">
      <model_token>{package}/import_entity_{package}</model_token>
      <label>My Entity</label>
    </my_entity>
  </import_entities>
</importexport>

and created an import entity class based on AvS FastSimpleImport file.

However, when I run the import I am getting the error message "Invalid entity model". I have changed the getEntityTypeCode() to everything I can think of but this does not appear to be the solution.

Looking into the code, the issue stems from Mage_ImportExport_Model_Import::_getEntityAdapter() line 95:

$this->_entityAdapter = Mage::getModel($validTypes[$this->getEntity()]['model']);

My entity model is not located in $validTypes so this is throwing the exception.

How do I add my table model to the list of valid entity types?

[edit]

Throwing a lot of var_dumps everywhere I have learned that my entity model IS being loaded, but Mage::getModel is throwing the exception because my model has an Invalid entity_type specified, stemming from the function getEntityTypeCode. At the moment I have entered the same name in here as the model_token value in my xml file. What is Magento expecting for this value?

[edit]

<?xml version="1.0"?>
<config>
    <modules>
        <Rich_Mines>
            <version>0.1.0</version>
        </Rich_Mines>
    </modules>
    <frontend>
        <routers>
            <mines>
                <use>standard</use>
                <args>
                    <module>Rich_Mines</module>
                    <frontName>mines</frontName>
                </args>
            </mines>
        </routers>
    </frontend>
    <global>
        <blocks>
                <mines>
                    <class>Rich_Mines_Block</class>
                </mines>
        </blocks>
        <models>
                <mines>
                    <class>Rich_Mines_Model</class>
                    <resourceModel>mines_resource</resourceModel>
                </mines>
                <mines_resource>
                    <class>Rich_Mines_Model_Mysql4</class>
                    <entities>
                        <mines><table>mines</table></mines>
                    </entities>
                </mines_resource>
        </models>
    <resources>
            <mines_setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </mines_setup>
            <mines_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </mines_write>
            <mines_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </mines_read>
    </resources>
        <helpers>
                <mines>
                        <class>Rich_Mines_Helper</class>
                </mines>
        </helpers>
        <events>
            <controller_front_init_routers>
                <observers>
                    <mines>
                        <class>Rich_Mines_Controller_Router</class>
                        <method>initControllerRouters</method>
                    </mines>
                </observers>
            </controller_front_init_routers>
        </events>

    <importexport module="importexport">
      <import_entities>
        <first_import translate="label">
          <model_token>mines/import_entity_mine</model_token>
                    <method>first_import</method>
          <label>First Import</label>
        </first_import>
        <second_import translate="label">
          <model_token>mines/import_entity_mine</model_token>
                    <method>second_import</method>
          <label>First Import</label>
        </second_import>
        ...
      </import_entities>
    </importexport>
    </global>
    <adminhtml>
        <layout>
            <updates>
                <mines>
                    <file>mines.xml</file>
                </mines>
            </updates>
        </layout>
        <events>
            <catalog_product_save_after>
                <observers>
                    <rich_save_product_data>
                        <type>singleton</type>
                        <class>mines/observer</class>
                        <method>saveProductTabData</method>
                    </rich_save_product_data>
                </observers>
            </catalog_product_save_after>
        </events>
        <acl>
                <resources>
                        <all>
                                <title>Allow Everything</title>
                        </all>
                        <admin>
                                <children>
                                        <Rich_Mines>
                                                <title>Mines Module</title>
                                                <sort_order>10</sort_order>
                                        </Rich_Mines>
                                </children>
                        </admin>
                </resources>
        </acl>
    </adminhtml>
    <admin>
        <routers>
            <!-- Includes our controller, so when we add the adminhtml menu item below, it is found! -->
            <adminhtml>
                <args>
                    <modules>
                        <mines before="Mage_Adminhtml">Rich_Mines_Adminhtml</mines>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>
2
  • Can you update the question with your complete config.xml? Jun 3, 2014 at 11:40
  • @DavidManners I have added my config.xml file. Jun 3, 2014 at 13:08

2 Answers 2

2
+100

This is not actually a solution to your problem, but it may be a bump in the right direction.
The import/export functionality works only for entities listed in the eav_entity_type table.
By default it has catalog_product and customer. There is also an importer that imports customer_address entities but that's not visible in the dropdown. It is called internally by the importer for customer entity.

So what you need to do is to insert a line in the eav_entity_type table for your entity.
I don't know all the fields you have to fill in but for entity_type_code enter the same value as is returned by the method getEntityTypeCode from your import model.

For the entity_model column put in the alias for the main model of your entity.
For example if your entity is called Article then put mines/article.

For starters you can leave the rest of the fields blank and see where that goes.
If I find something else I will let you know.

5
  • Doing the above changed the error message to Input entity code is not equal to entity adapter code. I changed the node names in the xml, for the node that I was trying to import, to the same as entity_type_code, and am now getting the success message for the 'check file' button on import. Is it possible to specify more than one importexport node (see my config file above) so that this works for any node "adapter code"? I am marking this the solution as it told me how to get my custom import entity recognised :) Jun 3, 2014 at 13:54
  • @RichardParnaby-King. You can use multiple importers, but each one must have it's own model (you are using the same one for both right now) and you also need a line in the eav_entity_type table for each entity you want to import.
    – Marius
    Jun 3, 2014 at 13:57
  • I am doing a dozen different CSV imports from a dozen different providers, all for the same type of data. Each CSV needs it's own importer function to format into a consistent state for import. What I have done is extend my import model for each of these import nodes, and include an entity type code for each in the database pointing to the same model, and do some preimport processing for each csv. It appears to be working ok at the moment (with two different CSVs). Jun 3, 2014 at 14:59
  • Marius, how to resolve the same error for Magento2x, i just overridden CatalogImportExport in etc di..i get this error and in getEntityTypeCode() i have used custom entity name as used in import.xml as return 'custom_dataflow_profiles'
    – Sushivam
    Jul 28, 2016 at 11:23
  • @SachinS Sorry, but I didn't dig yet in this part of M2. I have no solution for it.
    – Marius
    Jul 28, 2016 at 12:09
1

Getting the error "Invalid entity model" implies to me that you are getting inside the test of isset($validTypes[$this->getEntity]), but are unable to instantiate the model. Thus your entity config is found, but the model can't be loaded. Does the model {package}/import_entity_{package} actually exist? Is {package} a node inside <global><models>?

1
  • Thank you for your comment. Yes, the file actually exists. The problem appears to be in the public function 'getEntityTypeCode'. Is this something I need to set up in my config.xml file under models => entities? Jun 3, 2014 at 11:35

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.