Contact Contact Show All Awards & Recognition
Contact
Show All Awards & Recognition

tbachert/pimcore-importbundle

not-reviewed

No Category

No author set

Version

Last updated

Contact

-

No  Reviewer

tbachert/pimcore-importbundle

No Category

Project Summary

Allows to import structured data into pimcore


Readme


This bundle is intended for internal use - there might be backwards compatibility breaking changes at any time.

If you are looking for a stable import/export bundle, you should use the w-vision/import-definitions bundle instead.


Pimcore import bundle

Bundle used to import structured data into pimcore.

Getting started

Installation

composer require tbachert/pimcore-importbundle

Usage

Example

Define the pimcore classes
Product

ProductType

Allowed classes of Product::productType: ProductType

Example data
$product1 = [
    'puid' => 431247,
    'ean' => '4406381333939',
    'productType' => [
        'id' => 17,
        'name' => 'Product Type X',
    ],
    'productName' => 'Product name',
    'productNameDE' => 'Produkt Name',
    'deeplink' => 'direct/link/to/product',
    'rank' => 254434,
];

$products = [$product1];
Define the import mapping
# mapping.yml
Product:
    config:
        primaryKey: puid
    mapping:
        puid:
            value: puid
        ean:
            value: ean
        productType:
            value: productType
        productName~en:
            value: productName
        productName~de:
            value: productNameDE
        deeplink:
            value: deeplink
            config:
                type: direct
        rank:
            value: rank
            versioning: false
        published:
            value: true
        key:
            value: "[puid, ean, productName] | [] | join(' | ', [].to_string(@))"
        parent:
            value: "'product'"

ProductType:
    config:
        primaryKey: productTypeId
    mapping:
        productTypeId:
            value: id
        name:
            value: name
        published:
            value: true
        key:
            value: "[id, name] | [] | join(' | ', [].to_string(@))"
        parent:
            value: "'productType'"
Run the import
$builder = Pimcore::getContainer()->get(Definition\Builder::class);
$definitions = $builder->load(
    Yaml::parseFile('mapping.yml')
);

$productDefinition = $definitions->get('Product');
foreach ($products as $product) {
    $productDefinition->import($product);
}
Result
Product ('/product/431247 | 4406381333939 | Product name')

ProductType ('/productType/17 | Product Type X')

Mapping definition

ImportDefinition:     # Required

    # Prototype
    key:
        key:                  ~ # Required
        class:                ~ # Required
        cache:                null
        omitMandatoryChecks:  false
        disableVersion:       false
        loader:               null
        config:               []
        mapping:              # Required

            # Prototype
            property:
                enabled:              true
                property:             ~ # Required
                value:                ~ # Required
                extractor:            null
                versioning:           true
                override:             true
                overrideWithEmpty:    true
                mandatory:            false
                failOnError:          true
                interpreter:          null
                config:               []
                kind:                 null

Adding support for new types

Support for new types is added by tagging the implementing service with the corresponding service registry tag.

<<implementing class>>:
    tags:
        - { name: <<service registry tag>>, type: <<type>> }

See service.yml for the registry tags and examples.

Copyright

Copyright (c) Tobias Bachert. All Rights Reserved.

Review status

not-reviewed

?>

No author set

Version

Last updated

Contact

-

No  Reviewer