getPayloads example


        ];
        $repo->create([$attributeSet], Context::createDefaultContext());

        $update = [
            'id' => $id,
            'name' => 'test set update',
            'config' => ['description' => 'update', 'translatable' => true],
        ];
        $result = $repo->update([$update], Context::createDefaultContext());
        $event = $result->getEventByEntityName(CustomFieldSetDefinition::ENTITY_NAME);
        static::assertCount(1, $event->getPayloads());

        $result = $repo->search(new Criteria([$id]), Context::createDefaultContext());
        /** @var CustomFieldSetEntity $set */
        $set = $result->first();
        static::assertEquals($update['config']$set->getConfig());
    }

    public function testSearchWithAssociations(): void
    {
        /** @var EntityRepository $repo */
        $repo = $this->getContainer()->get('custom_field_set.repository');

        
return false;
        }

        $promotionIndividualWrittenEvent = $event->getEventByEntityName(PromotionIndividualCodeDefinition::ENTITY_NAME);

        if ($promotionIndividualWrittenEvent === null || $promotionIndividualWrittenEvent->getName() !== 'promotion_individual_code.written') {
            return false;
        }

        $promotionWrittenEvent = $event->getEventByEntityName(PromotionDefinition::ENTITY_NAME);

        if ($promotionWrittenEvent === null || $promotionWrittenEvent->getName() !== 'promotion.written' || !empty($promotionWrittenEvent->getPayloads()[0])) {
            return false;
        }

        return true;
    }
}
public static function getSubscribedEvents(): array
    {
        return [
            UserEvents::USER_WRITTEN_EVENT => 'onUserWritten',
            UserEvents::USER_DELETED_EVENT => 'onUserDeleted',
        ];
    }

    public function onUserWritten(EntityWrittenEvent $event): void
    {
        $payloads = $event->getPayloads();

        foreach ($payloads as $payload) {
            if ($this->userCredentialsChanged($payload)) {
                $this->refreshTokenRepository->revokeRefreshTokensForUser($payload['id']);
                $this->updateLastUpdatedPasswordTimestamp($payload['id']);
            }
        }
    }

    public function onUserDeleted(EntityDeletedEvent $event): void
    {
        


    /** * @experimental */
    public function create(array $data, Context $context): EntityWrittenContainerEvent
    {
        $writeResults = $this->getDummyWriteResults($data, EntityWriteResult::OPERATION_INSERT, $context);
        /** @var EntityWrittenEvent $entityWrittenEvent */
        $entityWrittenEvent = $writeResults->first();

        $this->creates[] = $entityWrittenEvent->getPayloads();

        return new EntityWrittenContainerEvent($context$writeResults[]);
    }

    /** * @experimental */
    public function update(array $data, Context $context): EntityWrittenContainerEvent
    {
        $this->updates[] = $data;

        
return;
        }

        // invalidates all http cache items where the snippets used         $snippets = $event->getEventByEntityName(SnippetDefinition::ENTITY_NAME);

        if (!$snippets) {
            return;
        }

        $tags = [];
        foreach ($snippets->getPayloads() as $payload) {
            if (isset($payload['translationKey'])) {
                $tags[] = Translator::buildName($payload['translationKey']);
            }
        }
        $this->cacheInvalidator->invalidate($tags);
    }

    public function invalidateShippingMethodRoute(EntityWrittenContainerEvent $event): void
    {
        // checks if a shipping method changed or the assignment between shipping method and sales channel         $logs = [...$this->getChangedShippingMethods($event), ...$this->getChangedShippingAssignments($event)];

        


        $order = $this->getOrderData($orderId$mediaId);

        $this->orderRepository->create([$order]$this->context);

        $event = $this->mediaRepository->delete([['id' => $mediaId]]$this->context)->getEventByEntityName(OrderLineItemDefinition::ENTITY_NAME);

        static::assertInstanceOf(EntityWrittenEvent::class$event);
        $this->runWorker();

        $payload = $event->getPayloads()[0];

        static::assertEquals(OrderEvents::ORDER_LINE_ITEM_WRITTEN_EVENT, $event->getName());
        static::assertNull($payload['coverId']);
    }

    /** * @return array<string, mixed> */
    private function getOrderData(string $orderId, ?string $mediaId = null): array
    {
        $addressId = Uuid::randomHex();
        
'id' => $bazId,
                'name' => 'foo\'bar',
                'custom' => [
                    'foo' => 'baz',
                ],
            ],
        ];

        $repo = $this->getTestRepository();
        $result = $repo->create($entities, Context::createDefaultContext());
        $events = $result->getEventByEntityName(CustomFieldTestDefinition::ENTITY_NAME);
        static::assertCount(2, $events->getPayloads());

        $expected = [$barId$bazId];
        static::assertEquals($expected$events->getIds());

        $actual = $repo->search(new Criteria([$barId]), Context::createDefaultContext())->first();
        static::assertEquals($barId$actual->get('id'));
        static::assertEquals($entities[0]['custom']$actual->get('custom'));

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('custom.foo', 'bar'));
        $result = $repo->search($criteria, Context::createDefaultContext());
        
'isModified' => false,
        ];

        $context = Context::createDefaultContext();
        /** @var EntityRepository $repo */
        $repo = $this->getContainer()->get('seo_url.repository');
        $events = $repo->create([$url]$context);
        static::assertCount(1, $events->getEvents());

        $event = $events->getEventByEntityName(SeoUrlDefinition::ENTITY_NAME);
        static::assertNotNull($event);
        static::assertCount(1, $event->getPayloads());
    }

    public function testUpdate(): void
    {
        $id = Uuid::randomHex();
        $fk = Uuid::randomHex();
        $url = [
            'id' => $id,
            'salesChannelId' => TestDefaults::SALES_CHANNEL,
            'foreignKey' => $fk,

            
'productNumber' => Uuid::randomHex(),
            'name' => '😄',
            'stock' => 1,
            'ean' => 'EAN-1',
            'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 100, 'net' => 10, 'linked' => false]],
            'manufacturer' => ['name' => 'create'],
            'tax' => ['name' => 'create', 'taxRate' => 1],
        ];

        $affected = $this->getContainer()->get('product.repository')->create([$product], Context::createDefaultContext());
        static::assertInstanceOf(EntityWrittenEvent::class$affected->getEventByEntityName(ProductTranslationDefinition::ENTITY_NAME));
        $writtenProductTranslations = $affected->getEventByEntityName(ProductTranslationDefinition::ENTITY_NAME)->getPayloads();

        static::assertCount(1, $writtenProductTranslations);
        static::assertEquals('😄', $writtenProductTranslations[0]['name']);
    }

    public function testCreateOrderVersion(): void
    {
        $ruleId = Uuid::randomHex();
        $customerId = $this->createCustomer();
        $paymentMethodId = $this->createPaymentMethod($ruleId);
        $this->addCountriesToSalesChannel();

        

    public static function getSubscribedEvents(): array
    {
        return [
            CustomerEvents::CUSTOMER_WRITTEN_EVENT => 'setDefaultSalutation',
            CustomerEvents::CUSTOMER_ADDRESS_WRITTEN_EVENT => 'setDefaultSalutation',
        ];
    }

    public function setDefaultSalutation(EntityWrittenEvent $event): void
    {
        $payloads = $event->getPayloads();
        foreach ($payloads as $payload) {
            if (\array_key_exists('salutationId', $payload) && $payload['salutationId']) {
                continue;
            }

            if (!isset($payload['id'])) {
                continue;
            }

            $this->updateCustomerWithNotSpecifiedSalutation($payload['id']);
        }
    }


    /** * @experimental */
    public function create(array $data, Context $context): EntityWrittenContainerEvent
    {
        $writeResults = $this->getDummyWriteResults($data, EntityWriteResult::OPERATION_INSERT, $context);
        /** @var EntityWrittenEvent $entityWrittenEvent */
        $entityWrittenEvent = $writeResults->first();

        $this->creates[] = $entityWrittenEvent->getPayloads();

        return new EntityWrittenContainerEvent($context$writeResults[]);
    }

    /** * @experimental */
    public function update(array $data, Context $context): EntityWrittenContainerEvent
    {
        $this->updates[] = $data;

        

    public static function getSubscribedEvents(): array
    {
        return [
            OrderEvents::ORDER_ADDRESS_WRITTEN_EVENT => 'setDefaultSalutation',
            OrderEvents::ORDER_CUSTOMER_WRITTEN_EVENT => 'setDefaultSalutation',
        ];
    }

    public function setDefaultSalutation(EntityWrittenEvent $event): void
    {
        $payloads = $event->getPayloads();
        foreach ($payloads as $payload) {
            if (\array_key_exists('salutationId', $payload) && $payload['salutationId']) {
                continue;
            }

            if (!isset($payload['id'])) {
                continue;
            }

            $this->updateOrderAddressWithNotSpecifiedSalutation($payload['id']);
        }
    }
$id = Uuid::randomHex();
        $attribute = [
            'id' => $id,
            'name' => 'foo.size',
            'type' => 'int',
        ];
        $result = $repo->create([$attribute], Context::createDefaultContext());

        $events = $result->getEventByEntityName(CustomFieldDefinition::ENTITY_NAME);
        static::assertNotNull($events);

        $payloads = $events->getPayloads();
        static::assertNotEmpty($payloads);

        static::assertEquals($attribute['id']$payloads[0]['id']);
        static::assertEquals($attribute['name']$payloads[0]['name']);
        static::assertEquals($attribute['type']$payloads[0]['type']);
    }

    public function testSearchId(): void
    {
        $repo = $this->getContainer()->get('custom_field.repository');

        

    public static function getSubscribedEvents(): array
    {
        return [
            CustomerEvents::CUSTOMER_WRITTEN_EVENT => 'onCustomerWritten',
        ];
    }

    public function onCustomerWritten(EntityWrittenEvent $event): void
    {
        $payloads = $event->getPayloads();
        foreach ($payloads as $payload) {
            if (!empty($payload['password'])) {
                $this->clearLegacyPassword($payload['id']);
            }
        }
    }

    private function clearLegacyPassword(string $customerId): void
    {
        $this->connection->executeStatement(
            'UPDATE `customer` SET `legacy_password` = null, `legacy_encoder` = null WHERE id = :id',
            [

    public static function getSubscribedEvents(): array
    {
        return [
            NewsletterEvents::NEWSLETTER_RECIPIENT_WRITTEN_EVENT => 'setDefaultSalutation',
        ];
    }

    public function setDefaultSalutation(EntityWrittenEvent $event): void
    {
        $payloads = $event->getPayloads();
        foreach ($payloads as $payload) {
            if (\array_key_exists('salutationId', $payload) && $payload['salutationId']) {
                continue;
            }

            if (!isset($payload['id'])) {
                continue;
            }

            $this->updateNewsletterRecipientWithNotSpecifiedSalutation($payload['id']);
        }
    }
Home | Imprint | This part of the site doesn't use cookies.