variant example

->write($this->getContainer());
        /** @var array{id: string, children: array<int, array{id: string}>, categories: array<int, array{id: string, name:string}>} $product */
        $product = $builder->build();
        $products[$name] = $product['id'];
        /** @var list<string> $categories */
        $categories = \array_column($product['categories'], 'id');
        \sort($categories);

        $name = 'testable-product';
        $builder = new ProductBuilder($ids$name);
        $builder->price(100)
            ->variant(
                (new ProductBuilder($ids, 'variant-testable-product'))
                ->price(100)->build()
            )
            ->write($this->getContainer());

        $product = $builder->build();
        $products[$name] = $product['id'];
        $products['variant-testable-product'] = $product['children'][0]['id'];

        static::assertEquals(
            0,
            
->manufacturer('Shopware')
                ->price(50, 50)
                ->build(),
            (new ProductBuilder($ids, 'product-5'))
                ->name('Cycle Suave')
                ->price(50, 50)
                ->tag('Smarthome')
                ->build(),
            (new ProductBuilder($ids, 'product-6'))
                ->name('T-Shirt')
                ->price(50, 50)
                ->variant(
                    (new ProductBuilder($ids, 'product-6-1'))
                        ->option('green', 'color')
                        ->build()
                )
                ->build(),
            (new ProductBuilder($ids, 'product-7'))
                ->name('Keyboard')
                ->price(50, 50)
                ->property('Wireless', 'Connectivity')
                ->build(),
            (new ProductBuilder($ids, 'SW5686779889'))
                
->build(),
            (new ProductBuilder($ids, 'p2'))
                ->price(100)
                ->visibility()
                ->prices('rule-A', 50)
                ->prices('rule-A', 30, 'default', null, 10)
                ->prices('rule-A', 15, 'default', null, 20)
                ->build(),
            (new ProductBuilder($ids, 'p3'))
                ->price(100)
                ->visibility()
                ->variant((new ProductBuilder($ids, 'p3.1'))->price(50)->build())
                ->variant((new ProductBuilder($ids, 'p3.2'))->price(40)->build())
                ->build(),
        ];

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

        $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        $salesChannelContext->getContext()->setRuleIds([$ids->get('rule-A')]);

        
private function init(): IdsCollection
    {
        $this->ids = new IdsCollection();
        $products = [
            (new ProductBuilder($this->ids, 'p1'))
                ->price(100)
                ->visibility()
                ->build(),
            (new ProductBuilder($this->ids, 'p2'))
                ->price(100)
                ->variant(
                    (new ProductBuilder($this->ids, 'v2.1'))
                        ->option('red', 'color')
                        ->build()
                )
                ->visibility()
                ->build(),
        ];

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

        
$document = $documents->first();
        static::assertNotNull($document->getOrder());
        static::assertEquals('00000000000000000000000000000000', $document->getOrder()->getVersionId());
    }

    public function testManyToOneInheritedWorks(): void
    {
        $ids = new TestDataCollection();
        $p = (new ProductBuilder($ids, 'p1'))
            ->price(100)
            ->cover('cover')
            ->variant(
                (new ProductBuilder($ids, 'p2'))
                    ->price(200)
                    ->build()
            );

        $connection = $this->getContainer()->get(Connection::class);
        $productRepo = $this->getContainer()->get('product.repository');

        $context = Context::createDefaultContext();
        $productRepo->create([$p->build()]$context);

        
false,
            $ids,
        ];

        yield 'complex filter correctly invalidates' => [
            'my-product-' . $ids->get('v4.1'),
            function DContainerInterface $container) use ($ids): void {
                $productRepo = $container->get('product.repository');

                $product4 = (new ProductBuilder($ids, 'p4'))
                    ->price(100)
                    ->variant(
                        (new ProductBuilder($ids, 'v4.1'))
                            ->build()
                    );

                $productRepo->create([$product4->build()], Context::createDefaultContext());
            },
            true,
            $ids,
        ];

        yield 'complex filter does not invalidate wrong operation' => [
            
static::assertTrue($page->hasExtension('myProductAggregations'));
        $extension = $page->getExtension('myProductAggregations');
        static::assertInstanceOf(ArrayStruct::class$extension);
        static::assertEquals(600, $extension->get('sum'));
    }

    private function createProducts(): void
    {
        $product1 = (new ProductBuilder($this->ids, 'p1'))
            ->price(100)
            ->manufacturer('m1')
            ->variant(
                (new ProductBuilder($this->ids, 'v1.1'))
                ->build()
            );

        $product2 = (new ProductBuilder($this->ids, 'p2'))
            ->price(200)
            ->active(false);

        $product3 = (new ProductBuilder($this->ids, 'p3'))
            ->price(300);

        
'id' => Uuid::randomBytes(),
            'route_name' => TestProductSeoUrlRoute::ROUTE_NAME,
            'entity_name' => ProductDefinition::ENTITY_NAME,
            'template' => '{{ product.translated.name }}/{{ product.productNumber }}',
            'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
        ]);

        $ids = new IdsCollection();
        $product = (new ProductBuilder($ids, 'parent'))
            ->price(100)
            ->visibility($this->salesChannelId)
            ->variant(
                (new ProductBuilder($ids, 'red'))
                    ->tax(null)
                    ->name('red')
                    ->build()
            )
            ->variant(
                (new ProductBuilder($ids, 'green'))
                    ->name(null)
                    ->build()
            );

        
private function prepareTestDataWithInheritedAndVersionized(): Context
    {
        $context = Context::createDefaultContext();

        $products = [
            (new ProductBuilder($this->ids, 'p1'))
                ->price(100)
                ->visibility()
                ->build(),
            (new ProductBuilder($this->ids, 'p2'))
                ->price(100)
                ->variant(
                    (new ProductBuilder($this->ids, 'v2.1'))
                        ->option('red', 'color')
                        ->build()
                )
                ->variant(
                    (new ProductBuilder($this->ids, 'v2.2'))
                        ->option('green', 'color')
                        ->build()
                )
                ->visibility()
                ->build(),
            (
'Fantastic Concrete Comveyer' => '834157484',
            'Fantastic Copper Ginger Vitro' => '9095345345',
        ];

        $products = [
            (new ProductBuilder($this->ids, 'bmw'))
                ->name(Uuid::randomHex())
                ->visibility($this->ids->get('sales-channel'))
                ->price(10, 9)
                ->manufacturer('shopware AG')
                ->add('customSearchKeywords', ['bmw'])
                ->variant(
                    (new ProductBuilder($this->ids, 'bmw.1'))
                        ->visibility($this->ids->get('sales-channel'))
                        ->build()
                )
                ->build(),
            // same as above, but has mercedes as variant             (new ProductBuilder($this->ids, 'mercedes'))
                ->name(Uuid::randomHex())
                ->visibility($this->ids->get('sales-channel'))
                ->price(10, 9)
                ->manufacturer('shopware AG')
                
'code' => Uuid::randomHex(),
                        'name' => 'Test locale',
                        'territory' => 'test',
                    ],
                ],
            ],
            Context::createDefaultContext()
        );

        $product = (new ProductBuilder($ids, 'parent'))
            ->price(100)
            ->variant(
                (new ProductBuilder($ids, 'child'))
                    ->translation($ids->get('language'), 'description', 'update')
                    ->build()
            )
            ->build();

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

        $behavior = new CloneBehavior(['productNumber' => 'new-parent'], false);

        $this->getContainer()->get('product.repository')->clone(
            


    private function prepareTestData(): void
    {
        $products = [
            (new ProductBuilder($this->ids, 'p.1'))
                ->price(900)
                ->property('rot', 'Farbe')
                ->property('grĂ¼n', 'Farbe')
                ->visibility(TestDefaults::SALES_CHANNEL)
                ->prices('rule-a', 220, 'default', null, 3, true)
                ->variant(
                    (new ProductBuilder($this->ids, 'v.1.1'))
                        ->build()
                )
                ->variant(
                    (new ProductBuilder($this->ids, 'v.1.2'))
                        ->prices('rule-a', 210, 'default', null, 3, true)
                        ->prices('rule-b', 501, 'default', null, 3, true)
                        ->build()
                )
                ->build(),
            (new ProductBuilder($this->ids, 'p.2'))
                


    private function createProducts(): void
    {
        $taxId = $this->getExistingTaxId();
        $this->ids->set('t1', $taxId);

        $product1 = (new ProductBuilder($this->ids, 'p1'))
            ->price(100)
            ->visibility()
            ->manufacturer('m1')
            ->variant(
                (new ProductBuilder($this->ids, 'v1.1'))
                    ->build()
            );

        $product2 = (new ProductBuilder($this->ids, 'p2'))
            ->price(200)
            ->visibility()
            ->active(false);

        $product3 = (new ProductBuilder($this->ids, 'p3'))
            ->visibility()
            
->media('m-2', 2)
                ->media('m-3', 3);
        }

        if (str_contains($type, 'variant')) {
            $variant
                ->media('v-1', 1)
                ->media('v-2', 2)
                ->media('v-3', 3);
        }

        $product->variant($variant->build());

        $context = Context::createDefaultContext();

        $productRepository = $this->getContainer()->get('product.repository');
        $productRepository->create([
            $product->build(),
        ]$context);

        $criteria = new Criteria([$ids->get('p1.1')]);
        $media = $criteria->getAssociation('media');
        $media->addSorting(new FieldSorting('position', FieldSorting::ASCENDING));
        
'1000', // productNumber                     'Hersteller', // manufacturer name                     'product', // part of name                     'test', // part of name                 ],
            ],
            'test it uses correct translation from parent' => [
                (new ProductBuilder($idsCollection, '1001'))
                    ->name('Test product')
                    ->translation('de-DE', 'name', 'Test produkt')
                    ->price(5)
                    ->variant(
                        (new ProductBuilder($idsCollection, '1000'))
                            ->price(10)
                            ->name(null)
                            ->build()
                    )
                    ->build(),
                $idsCollection,
                [
                    '1000', // productNumber                     'product', // part of name                     'test', // part of name
Home | Imprint | This part of the site doesn't use cookies.