PartialEntity example

'customFields' => ['test'],
        ]);

        $response = $this->encoder->encode($structnew ResponseFields(null));

        static::assertNull($response['customFields']);
        static::assertSame(['test']$response['translated']['customFields']);
    }

    public function testApiAwareWorksWithPartialEntity(): void
    {
        $entity = new PartialEntity();
        $entity->set('id', Uuid::randomHex());
        $entity->internalSetEntityData('my_entity', new FieldVisibility([]));
        $entity->set('name', 'test');
        $entity->set('description', 'test');
        $entity->set('translated', [
            'name' => 'test',
            'description' => 'test',
        ]);

        $registry = $this->createMock(DefinitionRegistryChain::class);
        $registry->method('has')
            
static::assertSame('foo', $productEntity->getName());

        $extension = $productEntity->getExtension('search');
        static::assertInstanceOf(ArrayEntity::class$extension);
        $search = $extension->jsonSerialize();

        static::assertSame('foo', $search['fullText']);
    }

    public function testSearchPartialEvent(): void
    {
        $product = new PartialEntity();
        $product->setUniqueIdentifier('test');

        $reader = $this->createMock(EntityReaderInterface::class);
        $reader
            ->method('read')
            ->willReturn(new EntityCollection([$product]));

        $eventDispatcher = new EventDispatcher();
        $event = null;
        $eventDispatcher->addListener(EntityLoadedContainerEvent::classstatic function D$inner) use (&$event): void {
            $event = $inner;
        });
new StaticSystemConfigService(),
            null,
        ];

        yield 'It sets cms page id if none is given and default is provided' => [
            (new ProductEntity())->assign(['id' => Uuid::randomHex(), 'cmsPageId' => null]),
            new StaticSystemConfigService([self::CONFIG => 'config-id']),
            'config-id',
        ];

        yield 'It does not set cms page id if already given with partial entity' => [
            (new PartialEntity())->assign(['id' => Uuid::randomHex(), 'cmsPageId' => 'own-id']),
            new StaticSystemConfigService([self::CONFIG => 'config-id']),
            'own-id',
        ];

        yield 'It does not set if no default is given with partial entity' => [
            (new PartialEntity())->assign(['id' => Uuid::randomHex(), 'cmsPageId' => null]),
            new StaticSystemConfigService(),
            null,
        ];

        yield 'It sets cms page id if none is given and default is provided with partial entity' => [
            (
$this->calculator->calculate([$product]$context);

        $price = $product->get('calculatedPrice');

        static::assertInstanceOf(CalculatedPrice::class$price);

        static::assertEquals($expected$price->getTotalPrice());
    }

    public static function taxStateWillBeUsedProvider(): \Generator
    {
        $product = (new PartialEntity())->assign([
            'taxId' => Uuid::randomHex(),
            'price' => new PriceCollection([
                new Price(Defaults::CURRENCY, 10, 20, false),
            ]),
        ]);

        yield 'Gross price will be used for gross state' => [$product, CartPrice::TAX_STATE_GROSS, 20];

        yield 'Net price will be used for net price state' => [$product, CartPrice::TAX_STATE_NET, 10];

        yield 'Net price will be used for tax free state' => [$product, CartPrice::TAX_STATE_FREE, 10];
    }

class ProductListingRouteTest extends TestCase
{
    public function testFiltersAreSetForCategories(): void
    {
        $categoryId = 'categoryId';
        $categoryRepository = new StaticEntityRepository([
            new EntityCollection([
                new PartialEntity([
                    'id' => $categoryId,
                    'productAssignmentType' => CategoryDefinition::PRODUCT_ASSIGNMENT_TYPE_PRODUCT,
                ]),
            ]),
        ]);

        $controller = new ProductListingRoute(
            $this->createMock(ProductListingLoader::class),
            $categoryRepository,
            $this->createMock(ProductStreamBuilderInterface::class),
        );

        
static::assertTrue($p2->hasExtension('stock_data'));
        static::assertSame($stock2$p2->getExtension('stock_data'));
    }

    public function testStockDataIsAppliedFromStorageWithPartialEntities(): void
    {
        $stockStorage = $this->createMock(AbstractStockStorage::class);
        $subscriber = new LoadProductStockSubscriber($stockStorage);

        $ids = new IdsCollection();

        $p1 = (new PartialEntity())->assign(['id' => $ids->get('product-1')]);
        $p2 = (new PartialEntity())->assign(['id' => $ids->get('product-2')]);

        $stock1 = new StockData($ids->get('product-1'), 10, false, 5, null, null);
        $stock1->addArrayExtension('extra', ['arbitrary-data1' => 'foo']);
        $stock2 = new StockData($ids->get('product-2'), 12, true);

        $stockStorage->expects(static::once())
            ->method('load')
            ->willReturn(new StockDataCollection([$stock1$stock2]));

        $event = new SalesChannelEntityLoadedEvent(
            
'translated' => ['name' => 'color'],
                        ]),
                    ]),
                ]),
            ]),
            [
                ['group' => 'color', 'option' => 'red'],
            ],
        ];

        yield 'Test with partial entity' => [
            (new PartialEntity())->assign([
                '_uniqueIdentifier' => Uuid::randomHex(),
                'options' => new EntityCollection([
                    (new PartialEntity())->assign([
                        'id' => Uuid::randomHex(),
                        '_uniqueIdentifier' => Uuid::randomHex(),
                        'translated' => ['name' => 'red'],
                        'group' => (new PartialEntity())->assign([
                            '_uniqueIdentifier' => Uuid::randomHex(),
                            'translated' => ['name' => 'color'],
                        ]),
                    ]),
                ]),
$configService = $this->createMock(SystemConfigService::class);
        $configService->method('getInt')->willReturn(10);
        $this->service = new ProductMaxPurchaseCalculator($configService);
    }

    /** * @dataProvider cases */
    public function testCalculate(array $entityData, int $expected): void
    {
        $entity = new PartialEntity();
        $entity->assign($entityData);

        static::assertSame($expected$this->service->calculate($entity$this->createMock(SalesChannelContext::class)));
    }

    public static function cases(): iterable
    {
        yield 'empty' => [
            [
            ],
            10,
        ];
Home | Imprint | This part of the site doesn't use cookies.