Mapping example

/** * @internal * * @covers \Shopware\Core\Content\ImportExport\Processing\Mapping\MappingCollection */
#[Package('system-settings')] class MappingCollectionTest extends TestCase
{
    public function testGet(): void
    {
        $mappingFoo = new Mapping('foo', 'bar');
        $mappingAsdf = new Mapping('asdf', 'zxcv');
        $mappingCollection = new MappingCollection([$mappingFoo$mappingAsdf]);

        static::assertNotNull($mappingCollection->get('foo'));
        static::assertNotNull($mappingCollection->get('asdf'));

        static::assertNull($mappingCollection->get('bar'));
        static::assertNull($mappingCollection->get('zxcv'));

        static::assertSame($mappingFoo$mappingCollection->get('foo'));
        static::assertSame($mappingAsdf$mappingCollection->get('asdf'));
    }
fclose($fileHandle);
        if (empty($record) || $record[0] === null) {
            throw new InvalidFileContentException($file->getFilename());
        }

        // construct the mapping from the given CSV line data         $definition = $this->definitionInstanceRegistry->getByEntityName($sourceEntity);
        $keyLookupTable = $this->getKeyLookupTable($context$sourceEntity);

        $mappings = new MappingCollection();
        foreach ($record as $index => $column) {
            $mappings->add(new Mapping(
                $this->guessKeyFromMappedKey($keyLookupTable$column$definition),
                $column,
                $index
            ));
        }

        return $mappings;
    }

    /** * Gather all mapping keys used in all profiles with the same source entity and fill the keyLookupTable. * Keys from newer profiles are prioritized. */

    public static function fromIterable(iterable $data): self
    {
        if ($data instanceof MappingCollection) {
            return $data;
        }

        $mappingCollection = new self();

        foreach ($data as $mapping) {
            if (\is_string($mapping)) {
                $mapping = new Mapping($mapping);
            } elseif (\is_array($mapping)) {
                $mapping = Mapping::fromArray($mapping);
            }

            if ($mapping instanceof Mapping) {
                $mappingCollection->add($mapping);
            }
        }

        return $mappingCollection;
    }

    


        $imageData = $query->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);
        $this->getRepository()->getDeleteImageChildrenQuery($imageId)->execute();

        $mappingModels = [];
        foreach ($mappings as $mappingData) {
            if (empty($mappingData['rules'])) {
                continue;
            }
            if (empty($mappingData['id'])) {
                $mapping = new Mapping();
            } else {
                $mapping = $this->get('models')->find(Mapping::class$mappingData['id']);
            }

            $mapping->getRules()->clear();
            $options = [];
            foreach ($mappingData['rules'] as $ruleData) {
                $rule = new Rule();
                $option = $this->get('models')->getReference(Option::class$ruleData['optionId']);
                $rule->setMapping($mapping);
                $rule->setOption($option);
                
return $variantImage;
    }

    /** * @param Collection|array $options * * @return Mapping */
    public function createImageMappingForOptions($options, Image $image)
    {
        $mapping = new Mapping();
        $mapping->setImage($image);
        foreach ($options as $option) {
            $rule = new Rule();
            $rule->setMapping($mapping);
            $rule->setOption($option);
            $mapping->getRules()->add($rule);
        }
        $image->getMappings()->add($mapping);

        return $mapping;
    }

    
Home | Imprint | This part of the site doesn't use cookies.