Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions Classes/Controller/Backend/Order/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
use Extcode\Cart\Domain\Model\Cart\Cart;
use Extcode\Cart\Domain\Model\Order\Item;
use Extcode\Cart\Domain\Repository\Order\ItemRepository;
use Extcode\Cart\Event\Document\GenerateDocumentEvent;
use Extcode\Cart\Event\Order\NumberGeneratorEvent;
use Extcode\CartPdf\Service\PdfService;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

Expand Down Expand Up @@ -57,7 +55,7 @@ public function createAction(Item $orderItem, string $pdfType): ResponseInterfac
$this->persistenceManager->persistAll();
}

$this->generatePdfDocument($orderItem, $pdfType);
$this->eventDispatcher->dispatch(new GenerateDocumentEvent($orderItem, $pdfType));

$this->itemRepository->update($orderItem);
$this->persistenceManager->persistAll();
Expand Down Expand Up @@ -91,17 +89,4 @@ public function downloadAction(Item $orderItem, string $pdfType): ResponseInterf

return $this->htmlResponse();
}

protected function generatePdfDocument(Item $orderItem, string $pdfType): void
{
if (ExtensionManagementUtility::isLoaded('cart_pdf')) {
if (class_exists(PdfService::class)) {
$pdfService = GeneralUtility::makeInstance(
PdfService::class
);

$pdfService->createPdf($orderItem, $pdfType);
}
}
}
}
21 changes: 21 additions & 0 deletions Classes/Event/Document/GenerateDocumentEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Extcode\Cart\Event\Document;

/*
* This file is part of the package extcode/cart.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

use Extcode\Cart\Domain\Model\Order\Item;

final readonly class GenerateDocumentEvent
{
public function __construct(public Item $orderItem, public string $pdfType)
{
}
}