Import product with variation


#1

Hi, I’m new with Pimcore and I want to import a data base of products. This products aren’t simple but variant for example a hat contains many colors green, white … How should I edit my csv file so that the PIM display it like this: Capture
And how should I configure my resolver settings?
Could you please help !!


#2

hey,

try this plugin: https://github.com/w-vision/ImportDefinitions

it does imports and exports and could solve your issue.

Cheers


#3

Thanks a lot, I will try it and share the results


#4

Hi, Installed the plugin and unfortunately I didn’t know how to use it, I tried to find the answer but still without answer, Could you please walk me through the steps of this form


#5

Ok, so:

Name: is the name of the import-definition
Provider: The type of input data
Loader: Is how you get if there is already a data-object for the current import-row. the default is primary-key which uses one field from the csv and identifies the data-object by that.
Class: Pimcore Data Object class
Path: The path where the object should be in the object-tree. You can use placeholders here as well: Like /products/%Text(category);/%Text(subcategory); where category and subcategory are fields within the CSV
Key: The key (name) for the data-object, you can also use Placeholders here
Cleaner: Import Definitions logs the last imported object and you can use that information to either: Delete, unpublish or dome something with records that don’t come from the import-source anymore
Filter: Create a service and filter certain rows from the import-source
Runner: A Service that will be called for each row in the data-source.
Relocate Objects: Define if an existing object should be moved if the path information changes
Rename Objects: Define if an existing object should be renamed if the key information changes

The rest should be clear.

Cheers


#6

Hi Dominik,
can you better specify how to achieve variant import with csv datafile?
Regards


#7

Use interpreters for o_parent and o_type.

set the o_parent for the Variant to the Variant “master” and o_type to variant. Example:

The Master/Variant is defined here using a StyleCode which groups the Products together. For each row, I execute the below as a interpreter on o_parent and o_type fields. It finds all products from the CSV with the same style code, and tries to find the first product in Pimcore, if it exists and the current imported object is not the same, it sets that as parent and type to variant

<?php

namespace AppBundle\ImportDefinitions\Interpreter;

use ImportDefinitionsBundle\Interpreter\InterpreterInterface;
use ImportDefinitionsBundle\Model\DataSetAwareInterface;
use ImportDefinitionsBundle\Model\DataSetAwareTrait;
use ImportDefinitionsBundle\Model\DefinitionInterface;
use ImportDefinitionsBundle\Model\Mapping;
use Pimcore\Model\DataObject\Concrete;

class ZyroFisherVariantInterpreter implements InterpreterInterface, DataSetAwareInterface
{
    protected $styleMasterItemCache = [];

    use DataSetAwareTrait;

    public function interpret(Concrete $object, $value, Mapping $map, $data, DefinitionInterface $definition, $params, $configuration)
    {
        $sameStyleCode = array_values(array_filter($this->getDataSet(), function($dataSetEntry) use($data) {
            return ($dataSetEntry['StyleCode'] === $data['StyleCode']);
        }));

        if (count($sameStyleCode) === 1) {
            return $map->getToColumn() === 'o_parent' ? $object->getParent() : Concrete::OBJECT_TYPE_OBJECT;
        }

        if ($sameStyleCode[0]['SKU'] === $data['SKU']) {
            $this->styleMasterItemCache[$sameStyleCode[0]['SKU']] = $object;

            return $map->getToColumn() === 'o_parent' ? $object->getParent() : Concrete::OBJECT_TYPE_OBJECT;
        }

        $parent = null;

        if (array_key_exists($sameStyleCode[0]['SKU'], $this->styleMasterItemCache)) {
            $parent = $this->styleMasterItemCache[$sameStyleCode[0]['SKU']];
        }
        else {
            $parent = $object::getBySupplierItemNumber($sameStyleCode[0]['SKU'], ['limit' => 1]);
        }

        //Fallback
        if (!$parent instanceof $object) {
            return $map->getToColumn() === 'o_parent' ? $object->getParent() : Concrete::OBJECT_TYPE_OBJECT;
        }

        return $map->getToColumn() === 'o_parent' ? $parent : Concrete::OBJECT_TYPE_VARIANT;
    }
}

#8

Thank you so much Domink,
I understood wath you write about… but… to define the new interpreter i must somthing like your file in - /vendor/w-vision/import-definitions/src/ImportDefinitionsBundle/Interpreter and …
In your manual what do you mean about create service, form, and JS ? Can you be clear? Sorry but I’m very newbie to Pimcore and his strucure

Best Regards


#9

Hi @riky973,

Don’t ever manipulate any of the files inside /vendor, otherwise they’ll be overwritten once you update your dependencies via composer. Instead create your custom service inside your own file structure (most likely inside the /src/AppBundle directory. In this specific case I would place the file under /src/AppBundle/ImportDefinitions/Interpreter/MyCustomInterpreter.php and then register it in the service container (here’s the link to the official symfony docs about that).

Hope this helps.


#10

Thank you Aaron fro your help, I’m serching service container of ImportDefinitions but I don’t find it.
Can you help me again?
Regards


#11

please start all the way from the beginning and learn how symfony works:

https://symfony.com/doc/current/index.html