ProductManufacturerEntity example

$this->manufacturerLogoCmsElementResolver->enrich($slot$resolverContext$result);

        /** @var ManufacturerLogoStruct|null $manufacturerLogoStruct */
        $manufacturerLogoStruct = $slot->getData();
        static::assertInstanceOf(ManufacturerLogoStruct::class$manufacturerLogoStruct);
        static::assertNull($manufacturerLogoStruct->getManufacturer());
    }

    public function testEnrichEntityResolverContext(): void
    {
        $manufacturer = new ProductManufacturerEntity();
        $manufacturer->setId('manufacturer_01');
        $product = new SalesChannelProductEntity();
        $product->setId('product_01');
        $product->setManufacturer($manufacturer);
        $resolverContext = new EntityResolverContext($this->createMock(SalesChannelContext::class)new Request()$this->getContainer()->get(SalesChannelProductDefinition::class)$product);
        $result = new ElementDataCollection();

        $media = new MediaEntity();
        $media->setId('media_01');

        $result->add('media_id', new EntitySearchResult(
            
/** @var ImageStruct|null $imageStruct */
        $imageStruct = $slot->getData();
        static::assertInstanceOf(ImageStruct::class$imageStruct);
        static::assertEmpty($imageStruct->getUrl());
        static::assertSame('media123', $imageStruct->getMediaId());
        static::assertSame($media$imageStruct->getMedia());
    }

    public function testUrlWithLocal(): void
    {
        $manufacturer = new ProductManufacturerEntity();
        $manufacturer->setLink('http://shopware.com');

        $product = new ProductEntity();
        $product->setManufacturer($manufacturer);

        $resolverContext = new EntityResolverContext($this->createMock(SalesChannelContext::class)new Request()$this->createMock(ProductDefinition::class)$product);

        $result = new ElementDataCollection();

        $fieldConfig = new FieldConfigCollection();
        $fieldConfig->add(new FieldConfig('url', FieldConfig::SOURCE_MAPPED, 'manufacturer.link'));

        
$tempProductMedia->setMedia($mediaEntity);
            $tempProductMedia->setPosition($i);

            $productMedia[] = $tempProductMedia;
        }

        return new ProductMediaCollection($productMedia);
    }

    protected function getResolverContext(ProductMediaCollection $productMediaCollection, ?string $coverId = null): EntityResolverContext
    {
        $manufacturer = new ProductManufacturerEntity();
        $manufacturer->setId('manufacturer_01');

        $product = new SalesChannelProductEntity();
        $product->setId('product_01');
        $product->setManufacturer($manufacturer);
        $product->setMedia($productMediaCollection);

        if ($coverId) {
            $product->setCoverId($coverId);
        }

        
public function testExtensionAreSupported(): void
    {
        $registry = new StaticDefinitionInstanceRegistry(
            [ExtensionDefinition::class],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        $product = new ProductEntity();
        $product->internalSetEntityData('product', new FieldVisibility([]));

        $manufacturer = (new ProductManufacturerEntity())->assign(['name' => 'foo']);
        $product->addExtension('exposedExtension', $manufacturer);
        $product->addExtension('notExposedExtension', $manufacturer);
        $product->setName('test');

        $product->addExtension('foreignKeys', new ArrayStruct(['exposedFk' => 'exposed', 'notExposedFk' => 'not_exposed'], 'product'));
        $product->addExtension('search', new ArrayEntity(['score' => 2000]));

        $serializer = new Serializer([new StructNormalizer()][new JsonEncoder()]);

        $encoded = (new StructEncoder($this->getChainRegistry($registry)$serializer))->encode($productnew ResponseFields(null));

        
public function testGetDecoratedShouldThrowException(): void
    {
        static::expectException(DecorationPatternException::class);
        $this->searchIndexer->getDecorated();
    }

    public function testGlobalData(): void
    {
        $context = Context::createDefaultContext();
        $repository = $this->createMock(EntityRepository::class);
        $productManufacturer = new ProductManufacturerEntity();
        $productManufacturer->setUniqueIdentifier(Uuid::randomHex());
        $repository->method('search')->willReturn(
            new EntitySearchResult(
                'product_manufacturer',
                1,
                new EntityCollection([$productManufacturer]),
                null,
                new Criteria(),
                $context
            )
        );

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