getCommandsForEntity example


        return new StockAlteration($id$productId$qtyBefore$newQty);
    }

    /** * @return array<string> */
    private function getAffectedIds(EntityWriteEvent $event): array
    {
        return array_map(
            static fn (WriteCommand $command) => $command->getPrimaryKey()['id'],
            array_filter($event->getCommandsForEntity(OrderLineItemDefinition::ENTITY_NAME)static function DWriteCommand $command) {
                if ($command instanceof DeleteCommand || $command instanceof InsertCommand) {
                    return true;
                }

                if ($command->hasField('referenced_id') || $command->hasField('product_id') || $command->hasField('quantity')) {
                    return true;
                }

                return false;
            })
        );
    }
return $fk;
    }

    /** * @param array<string, string> $primaryKey * * @return array<string, mixed> */
    private function getCurrentState(EntityDefinition $definition, array $primaryKey, WriteCommandQueue $commandQueue): array
    {
        $commands = $commandQueue->getCommandsForEntity($definition$primaryKey);

        $useDatabase = true;

        $state = [];

        foreach ($commands as $command) {
            if ($command instanceof DeleteCommand) {
                $state = [];
                $useDatabase = false;

                continue;
            }
$registry->get(MediaDefinition::class),
            ['id' => $ids->getBytes('m1')],
            new EntityExistence('media', ['id' => $ids->getBytes('m1')], true, true, true, [])
        );

        $event = EntityWriteEvent::create($writeContext[
            $productDelete,
            $mediaDelete,
        ]);

        static::assertSame([$productDelete$mediaDelete]$event->getCommands());
        static::assertSame([$productDelete]$event->getCommandsForEntity('product'));
        static::assertSame([$mediaDelete]$event->getCommandsForEntity('media'));

        static::assertSame([$ids->get('p1')]$event->getIds('product'));
        static::assertSame([$ids->get('m1')]$event->getIds('media'));
    }

    public function testCallbacksAreExecuted(): void
    {
        $context = Context::createDefaultContext();
        $writeContext = WriteContext::createFromContext($context);

        
foreach ($commands as $command) {
            $command->addPayload('available_stock', $command->getPayload()['stock'] ?? 0);
        }
    }

    /** * @return array<WriteCommand> */
    private function getAffected(EntityWriteEvent $event): array
    {
        return array_filter($event->getCommandsForEntity(ProductDefinition::ENTITY_NAME)static function DWriteCommand $command) {
            if ($command instanceof DeleteCommand) {
                return false;
            }

            if ($command instanceof InsertCommand) {
                return true;
            }

            if ($command->hasField('stock')) {
                return true;
            }

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