customField example

$newImplementation = $this->getContainer()->get(EsProductDefinition::class);

        ReflectionHelper::getProperty(EsProductDefinition::class, 'customFieldsTypes')->setValue(
            $newImplementation,
            $customMapping
        );

        $products = [
            (new ProductBuilder($this->ids, 'product-1'))
                ->name('Silk')
                ->category('navi')
                ->customField('testField', 'Silk')
                ->visibility(TestDefaults::SALES_CHANNEL)
                ->tax('t1')
                ->manufacturer('m1')
                ->price(50, 50, 'default', 150, 150)
                ->releaseDate('2019-01-01 10:11:00')
                ->purchasePrice(0)
                ->stock(2)
                ->createdAt('2019-01-01 10:11:00')
                ->category('c1')
                ->category('c2')
                ->property('red', 'color')
                
->add('description', 'A cool pokemon is traveling around the world')
                ->price(50, 50)
                ->build(),
            (new ProductBuilder($ids, 'product-9'))
                ->name('Super Pokemon')
                ->add('description', 'A cool raichu is traveling around the world')
                ->add('customSearchKeywords', ['Raichu'])
                ->price(50, 50)
                ->build(),
            (new ProductBuilder($ids, 'product-10'))
                ->name('Eevee')
                ->customField('evolvesTo', ['Vaporeon', 'Jolteon', 'Flareon'])
                ->price(50, 50)
                ->build(),
        ];

        $this->productRepository->create($products, Context::createDefaultContext());
    }

    private function registerCustomFieldsMapping(): void
    {
        $eventDispatcher = $this->getContainer()->get('event_dispatcher');

        
$mediaIds = $ids->all();

        foreach (['product', 'category', 'order'] as $entity) {
            $this->createMediaCustomField($entity);
            $this->createMediaSelectCustomField($entity);
            $this->createMediaMultiSelectCustomField($entity);
        }

        $product = new ProductBuilder($ids, Uuid::randomHex(), 100);
        $product->price(100);
        $product->customField('custom_field_media_product', $ids->get('media-1'));
        $product->customField('custom_field_media_select_product', $ids->get('media-2'));
        $product->customField('custom_field_media_multi_select_product', [$ids->get('media-2')$ids->get('media-3')$ids->get('media-4')]);
        $products = [$product->build()];

        $this->getContainer()->get('product.repository')->create($products, Context::createDefaultContext());

        $category = new CategoryBuilder($ids, 'Category');
        $category->customField('custom_field_media_category', $ids->get('media-5'));
        $category->customField('custom_field_media_select_category', $ids->get('media-6'));
        $category->customField('custom_field_media_multi_select_category', [$ids->get('media-7')$ids->get('media-8')$ids->get('media-9')]);

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