Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Extcode\CartPdf\EventListener\ProcessOrderCreate;
namespace Extcode\CartPdf\EventListener\Order\Finish;

/*
* This file is part of the package extcode/cart-pdf.
Expand All @@ -11,24 +11,28 @@
* LICENSE file that was distributed with this source code.
*/

use Extcode\Cart\Domain\Repository\Order\ItemRepository as OrderItemRepository;
use Extcode\Cart\Event\ProcessOrderCreateEvent;
use Extcode\CartPdf\Service\PdfService;
use Extcode\Cart\Domain\Repository\Order\ItemRepository as OrderItemRepository;
use Extcode\Cart\Event\Order\EventInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;

class DocumentRenderer
class DocumentRenderer implements LoggerAwareInterface
{
use LoggerAwareTrait;

public function __construct(
protected PersistenceManager $persistenceManager,
protected OrderItemRepository $orderItemRepository,
protected PdfService $pdfService,
) {}

public function __invoke(ProcessOrderCreateEvent $event): void
public function __invoke(EventInterface $event): void
{
$orderItem = $event->getOrderItem();
$settings = $event->getSettings();

$this->logger->debug('DocumentRenderer', $settings);
$generateDocuments = (array)($settings['autoGenerateDocuments'] ?? []);

if (empty($generateDocuments)) {
Expand Down
6 changes: 3 additions & 3 deletions Classes/Service/PdfService.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private function renderCartHeader(OrderItem $orderItem, string $pdfType): string
$view->assign('orderItem', $orderItem);
$header = $view->render();

return trim(preg_replace('~[\\n]+~', '', $header));
return trim(preg_replace('~[\\n]+~', '', $header ?? ''));
}

private function renderCartBody(OrderItem $orderItem, string $pdfType): string
Expand All @@ -247,7 +247,7 @@ private function renderCartBody(OrderItem $orderItem, string $pdfType): string
$view->assign('product', $product);
$product = $view->render();

$bodyOut .= trim(preg_replace('~[\\n]+~', '', $product));
$bodyOut .= trim(preg_replace('~[\\n]+~', '', $product ?? ''));
}

return $bodyOut;
Expand All @@ -260,7 +260,7 @@ private function renderCartFooter(OrderItem $orderItem, string $pdfType): string
$view->assign('orderItem', $orderItem);
$footer = $view->render();

return trim(preg_replace('~[\\n]+~', '', $footer));
return trim(preg_replace('~[\\n]+~', '', $footer ?? ''));
}

private function setPluginSettings(string $pdfType): void {}
Expand Down
6 changes: 3 additions & 3 deletions Classes/Service/TcpdfWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ public function getStandaloneView(
$view->setFormat($format);

if (!empty($this->viewSettings)) {
$view->setLayoutRootPaths($this->viewSettings['layoutRootPaths']);
$view->setPartialRootPaths($this->viewSettings['partialRootPaths']);
$view->getRenderingContext()->getTemplatePaths()->setLayoutRootPaths($this->viewSettings['layoutRootPaths']);
$view->getRenderingContext()->getTemplatePaths()->setPartialRootPaths($this->viewSettings['partialRootPaths']);

if ($this->viewSettings['templateRootPaths']) {
foreach ($this->viewSettings['templateRootPaths'] as $pathNameKey => $pathNameValue) {
Expand All @@ -216,7 +216,7 @@ public function getStandaloneView(
$completePath = $templateRootPath . $templatePathAndFileName;

if (file_exists($completePath)) {
$view->setTemplatePathAndFilename($completePath);
$view->getRenderingContext()->getTemplatePaths()->setTemplatePathAndFilename($completePath);
}
}
}
Expand Down
44 changes: 44 additions & 0 deletions Configuration/Services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Extcode\CartPdf;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder) {
$services = $containerConfigurator->services();
$services->defaults()
->private()
->autowire()
->autoconfigure();

$services->load('Extcode\\CartPdf\\', __DIR__ . '/../Classes/')
->exclude(__DIR__ . '/../Classes/Domain/Model/');

// Make PdfService public
$services->set(\Extcode\CartPdf\Service\PdfService::class)
->public();

// Conditionally register event listeners based on cart_payone availability
if (class_exists('\\Extcode\\CartPayone\\Event\\Order\\FinishEvent')) {
// Register listeners for cart_payone events
$services->set('cart_pdf.event_listener.document_renderer.payone')
->class(\Extcode\CartPdf\EventListener\Order\Finish\DocumentRenderer::class)
->tag('event.listener', [
'identifier' => 'cart-pdf--order--finish--document-renderer-payone',
'event' => \Extcode\CartPayone\Event\Order\FinishEvent::class,
'before' => 'cart--order--finish--email',
]);
} else {
// Register listeners for standard cart events
$services->set('cart_pdf.event_listener.document_renderer.cart')
->class(\Extcode\CartPdf\EventListener\Order\Finish\DocumentRenderer::class)
->tag('event.listener', [
'identifier' => 'cart--order--finish--document-renderer',
'event' => \Extcode\Cart\Event\Order\FinishEvent::class,
'before' => 'cart--order--finish--email',
]);
}
};
8 changes: 4 additions & 4 deletions Tests/Unit/Domain/Model/Dto/PdfDemandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function tearDown(): void
/**
* @test
*/
public function getDebugInitiallyReturnsZero()
public function getDebugInitiallyReturnsZero(): void
{
self::assertSame(
0,
Expand All @@ -38,7 +38,7 @@ public function getDebugInitiallyReturnsZero()
/**
* @test
*/
public function getFontSizeInitiallyReturnsDefaultFontSize()
public function getFontSizeInitiallyReturnsDefaultFontSize(): void
{
self::assertSame(
8,
Expand All @@ -49,7 +49,7 @@ public function getFontSizeInitiallyReturnsDefaultFontSize()
/**
* @test
*/
public function getFoldMarksEnabledInitiallyReturnsTrue()
public function getFoldMarksEnabledInitiallyReturnsTrue(): void
{
self::assertTrue(
$this->fixture->getFoldMarksEnabled()
Expand All @@ -59,7 +59,7 @@ public function getFoldMarksEnabledInitiallyReturnsTrue()
/**
* @test
*/
public function getAddressFieldMarksEnabledInitiallyReturnsTrue()
public function getAddressFieldMarksEnabledInitiallyReturnsTrue(): void
{
self::assertTrue(
$this->fixture->getAddressFieldMarksEnabled()
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"config": {
"bin-dir": ".build/bin",
"vendor-dir": ".build/vendor",
"vendor-dir": ".build/vendor",
"allow-plugins": {
"typo3/cms-composer-installers": false,
"typo3/class-alias-loader": false
Expand All @@ -42,11 +42,11 @@
}
},
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 | ~8.4.0",
"php": "^8.2",
"ext-fileinfo": "*",
"typo3/cms-core": "^12.4",
"extcode/cart": "^10.3",
"tecnickcom/tcpdf": "^6.7"
"typo3/cms-core": "^13.4",
"extcode/cart": "^11.5",
"tecnickcom/tcpdf": "^6.10"
},
"require-dev": {
"typo3/testing-framework": "^8.2",
Expand Down
6 changes: 3 additions & 3 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
'author_email' => 'ext@extco.de',
'constraints' => [
'depends' => [
'typo3' => '12.4.0-12.4.99',
'cart' => '10.3.0-10.99.99',
'tcpdf' => '6.7.0-6.99.99',
'typo3' => '13.4.0-13.4.99',
'cart' => '11.5',
'tcpdf' => '6.7.0-6.99.999',
],
'conflicts' => [],
'suggests' => [],
Expand Down