addSuccess example

'documentNumber' => $number,
                        'documentDate' => $operation->getConfig()['documentDate'] ?? $now,
                        'custom' => [
                            'deliveryNoteNumber' => $number,
                            'deliveryDate' => $customConfig['deliveryDate'] ?? $now,
                            'deliveryNoteDate' => $customConfig['deliveryNoteDate'] ?? $now,
                        ],
                    ]);

                    if ($operation->isStatic()) {
                        $doc = new RenderedDocument('', $number$config->buildName()$operation->getFileType()$config->jsonSerialize());
                        $result->addSuccess($orderId$doc);

                        continue;
                    }

                    $deliveries = null;
                    if ($order->getDeliveries()) {
                        $deliveries = $order->getDeliveries()->first();
                    }

                    /** @var LocaleEntity $locale */
                    $locale = $order->getLanguage()->getLocale();

                    


        $ids = $this->getAffectedIds($event);

        if (empty($ids)) {
            return;
        }

        $beforeLineItems = $this->fetchOrderLineItems($ids);
        $context = $event->getContext();

        $event->addSuccess(function D) use ($ids$beforeLineItems$context): void {
            $afterLineItems = $this->fetchOrderLineItems($ids);

            $changes = [];

            foreach ($beforeLineItems as $id => $lineItem) {
                $changes = [...$changes, ...$this->calculateChanges($id$lineItem$afterLineItems[$id] ?? null)];
            }

            foreach ($afterLineItems as $id => $lineItem) {
                // this item was added, decrease the stock                 if (!isset($beforeLineItems[$id])) {
                    
$config->merge([
                    'documentDate' => $operation->getConfig()['documentDate'] ?? (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                    'documentNumber' => $number,
                    'custom' => [
                        'creditNoteNumber' => $number,
                        'invoiceNumber' => $referenceDocumentNumber,
                    ],
                ]);

                if ($operation->isStatic()) {
                    $doc = new RenderedDocument('', $number$config->buildName()$operation->getFileType()$config->jsonSerialize());
                    $result->addSuccess($orderId$doc);

                    continue;
                }

                $price = $this->calculatePrice($creditItems$order);

                /** @var LocaleEntity $locale */
                $locale = $order->getLanguage()->getLocale();

                $html = $this->documentTemplateRenderer->render(
                    $template,
                    [
throw new DecorationPatternException(self::class);
    }

    public function render(array $operations, Context $context, DocumentRendererConfig $rendererConfig): RendererResult
    {
        $result = new RendererResult();

        foreach ($operations as $operation) {
            $rendered = new RenderedDocument('<html>test</html>');
            $rendered->setName('custom.pdf');

            $result->addSuccess($operation->getOrderId()$rendered);
        }

        return $result;
    }
}
$config->merge([
                    'documentDate' => $operation->getConfig()['documentDate'] ?? $now,
                    'documentNumber' => $number,
                    'custom' => [
                        'stornoNumber' => $number,
                        'invoiceNumber' => $referenceDocumentNumber,
                    ],
                ]);

                if ($operation->isStatic()) {
                    $doc = new RenderedDocument('', $number$config->buildName()$operation->getFileType()$config->jsonSerialize());
                    $result->addSuccess($orderId$doc);

                    continue;
                }

                /** @var LocaleEntity $locale */
                $locale = $order->getLanguage()->getLocale();
                $html = $this->documentTemplateRenderer->render(
                    $template,
                    [
                        'order' => $order,
                        'config' => $config,
                        
'documentNumber' => $number,
                        'custom' => [
                            'invoiceNumber' => $number,
                        ],
                    ]);

                    // create version of order to ensure the document stays the same even if the order changes                     $operation->setOrderVersionId($this->orderRepository->createVersion($orderId$context, 'document'));

                    if ($operation->isStatic()) {
                        $doc = new RenderedDocument('', $number$config->buildName()$operation->getFileType()$config->jsonSerialize());
                        $result->addSuccess($orderId$doc);

                        continue;
                    }

                    /** @var LocaleEntity $locale */
                    $locale = $order->getLanguage()->getLocale();

                    $html = $this->documentTemplateRenderer->render(
                        $template,
                        [
                            'order' => $order,
                            

    public function testEntityDeleteEventSuccessCallbacksCalled(string $eventClass): void
    {
        $id1 = $this->ids->get('product');

        $delete = [['id' => $id1]];

        $successSpy = $this->callbackSpy();
        $errorSpy = $this->callbackSpy();

        $spy = $this->eventListenerCalledSpy(function DEntityDeleteEvent $event) use ($successSpy$errorSpy): void {
            $event->addSuccess($successSpy(...));
            $event->addError($errorSpy(...));
        });

        $this->getContainer()->get('event_dispatcher')->addListener($eventClass$spy);

        $this->productRepository->delete($delete, Context::createDefaultContext());

        static::assertTrue($successSpy->called);
        static::assertFalse($errorSpy->called);

        $this->getContainer()->get('event_dispatcher')->removeListener($eventClass$spy);
    }
public int $counter = 0;

            public function __invoke(): void
            {
                ++$this->counter;
            }
        };

        $callback1 = $callbackFactory();
        $callback2 = $callbackFactory();

        $event->addSuccess($callback1);
        $event->addSuccess($callback1);
        $event->addError($callback2);

        $event->success();

        static::assertEquals(2, $callback1->counter);

        $event->error();
        static::assertEquals(1, $callback2->counter);
    }
}
if ($media->isPrivate()) {
                $privatePaths[] = $this->urlGenerator->getRelativeThumbnailUrl($media$thumbnail);
            } else {
                $publicPaths[] = $this->urlGenerator->getRelativeThumbnailUrl($media$thumbnail);
            }
        }

        $this->performFileDelete($context$privatePaths, Visibility::PRIVATE);
        $this->performFileDelete($context$publicPaths, Visibility::PUBLIC);

        $event->addSuccess(function D) use ($thumbnails$context): void {
            $this->dispatcher->dispatch(new MediaThumbnailDeletedEvent($thumbnails$context), MediaThumbnailDeletedEvent::EVENT_NAME);
        });
    }

    /** * @param list<string> $ids */
    private function getThumbnails(array $ids, Context $context): MediaThumbnailCollection
    {
        $criteria = new Criteria();
        $criteria->addAssociation('media');
        
public int $counter = 0;

            public function __invoke(): void
            {
                ++$this->counter;
            }
        };

        $callback1 = $callbackFactory();
        $callback2 = $callbackFactory();

        $event->addSuccess(\Closure::fromCallable($callback1));
        $event->addSuccess(\Closure::fromCallable($callback1));
        $event->addError(\Closure::fromCallable($callback2));

        $event->success();

        static::assertEquals(2, $callback1->counter);

        $event->error();
        static::assertEquals(1, $callback2->counter);
    }
}
'documentTypeId' => $documentTypeId,
                    'fileType' => $operation->getFileType(),
                    'orderId' => $orderId,
                    'orderVersionId' => $operation->getOrderVersionId(),
                    'static' => $operation->isStatic(),
                    'documentMediaFileId' => $mediaId,
                    'config' => $document->getConfig(),
                    'deepLinkCode' => $deepLinkCode,
                    'referencedDocumentId' => $operation->getReferencedDocumentId(),
                ];

                $result->addSuccess(new DocumentIdStruct($id$deepLinkCode$mediaId));
            } catch (\Throwable $exception) {
                $result->addError($orderId$exception);
            }
        }

        $this->writeRecords($records$context);

        return $result;
    }

    public function upload(string $documentId, Context $context, Request $uploadedFileRequest): DocumentIdStruct
    {
$source = $context->getSource();
        $salesChannelId = null;

        if ($source instanceof SalesChannelApiSource) {
            $salesChannelId = $source->getSalesChannelId();
        }

        /** @var CustomerCollection $customers */
        $customers = $this->customerRepository->search(new Criteria($ids)$context)->getEntities();

        $event->addSuccess(function D) use ($customers$context$salesChannelId): void {
            foreach ($customers->getElements() as $customer) {
                $salesChannelContext = $this->salesChannelContextService->get(
                    new SalesChannelContextServiceParameters(
                        $salesChannelId ?? $customer->getSalesChannelId(),
                        Random::getAlphanumericString(32),
                        $customer->getLanguageId(),
                        null,
                        null,
                        $context,
                    )
                );

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