infrangible / m2-import-entity
Technical groundwork for imports of Magento records such as products or categories, including attributes, option values and related data.
Package info
github.com/infrangible-dev/m2-import-entity
Type:magento2-module
pkg:composer/infrangible/m2-import-entity
Requires
- php: >=8.1
- fewedev/base: ~2.4.3
- infrangible/m2-core: ~5.0.5
- infrangible/m2-foundation: ~3.0.1
- infrangible/m2-import: ~2.0.0
- magento/framework: ~103.0.6
- magento/module-eav: ~102.1.0
- magento/module-import-export: ~101.0.0
- magento/module-store: ~101.1.0
- psr/log: ~2.0.0||~3.0.0
Requires (Dev)
- infrangible/phpstan-magento: ~1.2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The base of imports of Magento entities, for example products, categories or customers. It extends
Infrangible Import with the steps that write the elements into the
entity and attribute tables. The module imports nothing by itself; import routines extend its class Model\Entity.
Steps of an import
On top of the steps of Infrangible\Import\Model\Import, Model\Entity:
- finds the entities of the source and transformed elements by their
entity_idor their key (getSourceElementKey(),getTransformedElementKey(),findSourceDataEntityIds(),findTransformedDataEntityIds()), - determines the store of every transformed element:
store_id, else the default store of the website given aswebsite_idorwebsite(['id' => …]or['name' => <code>]), else the admin store, - replaces, prepares and validates the values of the elements (see below),
- creates the missing entities (
getCreateEntityData(); an entity created for a key is reused for later elements with the same key) and saves the changed attribute values, per store, in chunks ofsetChunkSize()elements, each in a transaction, - records the changed entities (
getImportedEntities()).
Unchanged values are not written; an element without changed values is marked as unchanged. setUpdateAdminStore()
also saves the values of existing entities in the admin store; addCreateDateAttributeCode() and
addUpdateDateAttributeCode() set date attributes of created or changed entities.
Values
- Attributes: values of attributes with options are replaced by the IDs of the options (separated by commas for
multiselect attributes); unknown options can be added (
setAddUnknownAttributeOptionValues()). Unknown attributes are removed (setIgnoreUnknownAttributes()) and reported as debug messages or errors (setUnknownAttributesWarnOnly()). Admin store values can be forced, prohibited or given as default (addForceAdminEavAttributeValue(),addProhibitAdminEavAttributeValue(),addDefaultAdminEavAttributeValue()). - Columns of the entity table:
addSpecialAttribute()with the type of the column.store_idis one by default (the customer table has it); routines of entities without this column, like products, calladdIgnoreAttribute('store_id'). Model\Replace(addReplaceAttributeModel()): replaces a value with another attribute, for example a name with an ID.Model\SpecialAttribute(addSpecialAttributeModel()): saves the value of an attribute by itself.Model\Associated(addAssociatedItemModel()): data that is saved in its own tables, for example images, given as array or as text separated by|.Model\Prepare(addAssociatedItemPrepareModel()) prepares the associated data of all entities of a chunk.
Requirements
- Magento Open Source or Adobe Commerce 2.4.6 or newer
- PHP 8.1 or newer
Installation
composer require infrangible/m2-import-entity bin/magento module:enable Infrangible_ImportEntity bin/magento setup:upgrade
In production mode, also run bin/magento setup:di:compile.
License
Infrangible Import Entity is licensed under the MIT License - see the LICENSE file for details.