Question

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>

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top