Skip to content

Commit f48e4ac

Browse files
committed
[BUGFIX] makes cart extension compatible to php version 8.1
* unserialize(): Passing null to parameter of type string is deprecates * PHP Warning Undefined array key: use isset before address some array keys * PHP Warning Undefined array key: use null coalescing operator to set default values if settings not present
1 parent 318568b commit f48e4ac

6 files changed

Lines changed: 38 additions & 36 deletions

File tree

Classes/Controller/Cart/OrderController.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function createAction(
114114
) {
115115
if (is_null($billingAddress)) {
116116
$sessionData = $GLOBALS['TSFE']->fe_user->getKey('ses', 'cart_billing_address_' . $this->settings['cart']['pid']);
117-
$billingAddress = unserialize($sessionData);
117+
$billingAddress = is_null($sessionData) ? null : unserialize($sessionData);
118118
} else {
119119
$sessionData = serialize($billingAddress);
120120
$GLOBALS['TSFE']->fe_user->setKey('ses', 'cart_billing_address_' . $this->settings['cart']['pid'], $sessionData);
@@ -174,12 +174,9 @@ public function createAction(
174174
$paymentId = $this->cart->getPayment()->getId();
175175
$paymentSettings = $this->parserUtility->getTypePluginSettings($this->pluginSettings, $this->cart, 'payments');
176176

177-
if ($paymentSettings['options'][$paymentId] &&
178-
$paymentSettings['options'][$paymentId]['redirects'] &&
179-
$paymentSettings['options'][$paymentId]['redirects']['success'] &&
180-
$paymentSettings['options'][$paymentId]['redirects']['success']['url']
181-
) {
182-
$this->redirectToUri($paymentSettings['options'][$paymentId]['redirects']['success']['url'], 0, 200);
177+
$url = $paymentSettings['options'][$paymentId]['redirects']['success']['url'] ?? false;
178+
if ($url) {
179+
$this->redirectToUri($url, 0, 200);
183180
}
184181
}
185182

Classes/Domain/Model/Cart/Cart.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,17 @@ public function getServiceTaxes()
459459
if ($this->payment) {
460460
$paymentTaxes = $this->payment->getTaxes();
461461
foreach ($paymentTaxes as $paymentTax) {
462-
$taxes[$paymentTax['taxClassId']] += $paymentTax['tax'];
462+
if (isset($taxes[$paymentTax['taxClassId']])) {
463+
$taxes[$paymentTax['taxClassId']] += $paymentTax['tax'] ?? 0;
464+
}
463465
}
464466
}
465467
if ($this->shipping) {
466468
$shippingTaxes = $this->shipping->getTaxes();
467469
foreach ($shippingTaxes as $shippingTax) {
468-
$taxes[$shippingTax['taxClassId']] += $shippingTax['tax'];
470+
if (isset($taxes[$shippingTax['taxClassId']])) {
471+
$taxes[$shippingTax['taxClassId']] += $shippingTax['tax'] ?? 0;
472+
}
469473
}
470474
}
471475
if ($this->specials) {

Classes/EventListener/Order/Create/Number.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@ protected function generateNumber(NumberGeneratorEventInterface $event): string
6363
$registry->set('tx_cart', $this->getRegistryName($event), $numberInRegistry);
6464

6565
$format = $this->options['format'] ?? '%d';
66-
$numberInRegistryWithOffset = $numberInRegistry + (int)$this->options['offset'];
66+
$offset = $this->options['offset'] ?? 0;
67+
$numberInRegistryWithOffset = $numberInRegistry + (int)$offset;
6768

69+
$prefix = $this->options['prefix'] ?? '';
70+
$suffix = $this->options['suffix'] ?? '';
6871
return implode([
69-
$this->options['prefix'],
72+
$prefix,
7073
sprintf($format, $numberInRegistryWithOffset),
71-
$this->options['suffix'],
74+
$suffix,
7275
]);
7376
}
7477
}

Classes/EventListener/Order/Finish/ClearCart.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public function __invoke(EventInterface $event): void
4949
$paymentId = $cart->getPayment()->getId();
5050
$paymentSettings = $this->parserUtility->getTypePluginSettings($settings, $cart, 'payments');
5151

52-
if (intval($paymentSettings['options'][$paymentId]['preventClearCart']) != 1) {
52+
$preventClearCart = $paymentSettings['options'][$paymentId]['preventClearCart'] ?? null;
53+
if ((int)$preventClearCart !== 1) {
5354
$cart = $this->cartUtility->getNewCart($settings);
5455
}
5556

Classes/EventListener/Order/Finish/Email.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public function __invoke(EventInterface $event): void
3838
$serviceSettings = $settings['payments']['options'][$paymentId];
3939
}
4040

41-
if (intval($serviceSettings['preventBuyerEmail']) != 1) {
41+
if (!isset($serviceSettings['preventBuyerEmail']) || 1 !== (int)$serviceSettings['preventSellerEmail']) {
4242
$this->sendBuyerMail($orderItem);
4343
}
44-
if (intval($serviceSettings['preventSellerEmail']) != 1) {
44+
if (!isset($serviceSettings['preventSellerEmail']) || 1 !== (int)$serviceSettings['preventSellerEmail']) {
4545
$this->sendSellerMail($orderItem);
4646
}
4747
}

Classes/Hooks/MailAttachmentHook.php

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,27 @@ public function __construct()
5252
*/
5353
public function getMailAttachments(FluidEmail $mailMessage, Item $item, string $type): FluidEmail
5454
{
55-
if ($this->pluginSettings['mail'] && $this->pluginSettings['mail'][$type]) {
56-
if ($this->pluginSettings['mail'][$type]['attachments']) {
57-
$attachments = $this->pluginSettings['mail'][$type]['attachments'];
58-
59-
foreach ($attachments as $attachment) {
60-
$attachmentFile = GeneralUtility::getFileAbsFileName($attachment);
61-
if (file_exists($attachmentFile)) {
62-
$mailMessage->attachFromPath($attachmentFile);
63-
}
55+
$mailSettings = $this->pluginSettings['mail'][$type] ?? null;
56+
if ($mailSettings) {
57+
$attachments = $mailSettings['attachments'] ?? [];
58+
foreach ($attachments as $attachment) {
59+
$attachmentFile = GeneralUtility::getFileAbsFileName($attachment);
60+
if (file_exists($attachmentFile)) {
61+
$mailMessage->attachFromPath($attachmentFile);
6462
}
6563
}
6664

67-
if ($this->pluginSettings['mail'][$type]['attachDocuments']) {
68-
foreach ($this->pluginSettings['mail'][$type]['attachDocuments'] as $pdfType => $pdfData) {
69-
$getter = 'get' . ucfirst($pdfType) . 'Pdfs';
70-
$pdfs = $item->$getter();
71-
if ($pdfs && ($pdfs instanceof ObjectStorage)) {
72-
$pdfs = end($pdfs->toArray());
73-
if ($pdfs) {
74-
$lastOriginalPdf = $pdfs->getOriginalResource();
75-
$lastOriginalPdfPath = $lastOriginalPdf->getForLocalProcessing(false);
76-
if (is_file($lastOriginalPdfPath)) {
77-
$mailMessage->attachFromPath($lastOriginalPdfPath);
78-
}
65+
$attachDocuments = $mailSettings['attachDocuments'] ?? [];
66+
foreach ($attachDocuments as $pdfType => $pdfData) {
67+
$getter = 'get' . ucfirst($pdfType) . 'Pdfs';
68+
$pdfs = $item->$getter();
69+
if ($pdfs instanceof ObjectStorage) {
70+
$pdfs = end($pdfs->toArray());
71+
if ($pdfs) {
72+
$lastOriginalPdf = $pdfs->getOriginalResource();
73+
$lastOriginalPdfPath = $lastOriginalPdf->getForLocalProcessing(false);
74+
if (is_file($lastOriginalPdfPath)) {
75+
$mailMessage->attachFromPath($lastOriginalPdfPath);
7976
}
8077
}
8178
}

0 commit comments

Comments
 (0)