TL;DR: you need a unique index on the following combination of columns: entity_id
,attribute_id
,store_id
.
Long answer:
On an EAV entity (let's take products for example) your table could never look like that.
You have 2 records for the same combination of attribute_id | store_id | entity_id
.
On the product tables (catalog_product_entity_varchar
for example but it's the same for _int
and others) there is a unique constraint on these 3 columns.
UNIQUE KEY `UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID` (`entity_id`,`attribute_id`,`store_id`),
This is created in the install script (see install-1.6.0.0.php
)
->addIndex(
$installer->getIdxName(
array('catalog/product', 'varchar'),
array('entity_id', 'attribute_id', 'store_id'),
Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
),
array('entity_id', 'attribute_id', 'store_id'),
array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE))
And when saving an attribute value (insert or update) a call to the method insertOnDuplicate
is made.
This method tries to insert the values you provide to it and if there is a unique key duplicate it just updates the values you specify. In the case of the EAV tables only the value
field is updated.
Since you don't have that unique constraint on the table it just inserts an other row.
Try adding that constraint and I have a feeling the problem will go away.
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.
Best Answer
I found a module in Github which has custom EAV Model. I have built custom EAV model successfully by following this module. May be it will help someone.