SalesChannelEntityLoadedEvent example

static::assertEquals($expectedEvents, CategorySubscriber::getSubscribedEvents());
    }

    /** * @dataProvider entityLoadedEventDataProvider */
    public function testEntityLoadedEvent(SystemConfigService $systemConfigService, CategoryEntity $categoryEntity, ?string $cmsPageIdBeforeEvent, ?string $cmsPageIdAfterEvent, ?string $salesChannelId): void
    {
        $categorySubscriber = new CategorySubscriber($systemConfigService);

        if ($salesChannelId) {
            $event = new SalesChannelEntityLoadedEvent(new CategoryDefinition()[$categoryEntity]$this->getSalesChannelContext($salesChannelId));
        } else {
            $event = new EntityLoadedEvent(new CategoryDefinition()[$categoryEntity], Context::createDefaultContext());
        }

        static::assertEquals($cmsPageIdBeforeEvent$categoryEntity->getCmsPageId());
        $categorySubscriber->entityLoaded($event);
        static::assertEquals($cmsPageIdAfterEvent$categoryEntity->getCmsPageId());
    }

    /** * @return array<string, array{SystemConfigService, CategoryEntity, string|null, string|null, string|null}> */
/** * @param array<mixed> $entities * * @return EntityLoadedContainerEvent[] */
    public function createForSalesChannel(array $entities, SalesChannelContext $context): array
    {
        $mapping = $this->recursion($entities[]);

        $generator = fn (EntityDefinition $definition, array $entities) => new EntityLoadedEvent($definition$entities$context->getContext());

        $salesGenerator = fn (EntityDefinition $definition, array $entities) => new SalesChannelEntityLoadedEvent($definition$entities$context);

        return [
            $this->buildEvents($mapping$generator$context->getContext()),
            $this->buildEvents($mapping$salesGenerator$context->getContext()),
        ];
    }

    /** * @param array<mixed> $entities * * @return EntityLoadedContainerEvent[] */
$p1 = (new SalesChannelProductEntity())->assign(['id' => $ids->get('product-1')]);
        $p2 = (new SalesChannelProductEntity())->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(
            $this->createMock(SalesChannelProductDefinition::class),
            [$p1$p2],
            $this->createMock(SalesChannelContext::class)
        );

        $subscriber->salesChannelLoaded($event);

        static::assertEquals(10, $p1->getStock());
        static::assertFalse($p1->getAvailable());
        static::assertEquals(5, $p1->getMinPurchase());
        static::assertTrue($p1->hasExtension('stock_data'));
        
public function testResolveCmsPageIdProviderWithSalesChannelLoadedEvent(Entity $entity, SystemConfigService $config, ?string $expected): void
    {
        $subscriber = new ProductSubscriber(
            $this->createMock(ProductVariationBuilder::class),
            $this->createMock(AbstractProductPriceCalculator::class),
            $this->createMock(AbstractPropertyGroupSorter::class),
            $this->createMock(ProductMaxPurchaseCalculator::class),
            $this->createMock(IsNewDetector::class),
            $config,
        );

        $event = new SalesChannelEntityLoadedEvent(
            $this->createMock(SalesChannelProductDefinition::class),
            [$entity],
            $this->createMock(SalesChannelContext::class)
        );

        $subscriber->salesChannelLoaded($event);

        static::assertSame($expected$entity->get('cmsPageId'));
    }

    public static function resolveCmsPageIdProviderWithLoadedEventProvider(): \Generator
    {
Home | Imprint | This part of the site doesn't use cookies.