Skip to content

PHP warning Undefined array key "suffix" in Number.php #766

Description

@Hobokens

Bug Report

Current Behavior
When generating order/invoice/delivery numbers without a configured suffix (or prefix), the following PHP warning is logged:

PHP Warning: Undefined array key "suffix" in Classes/EventListener/Order/Create/Number.php line 48

Expected behavior/output
No warning should be raised when prefix/suffix are not configured in TypoScript; the number should simply be generated without them.

Environment

  • TYPO3 version(s): 14.3
  • cart version: ^12.0
  • Is your TYPO3 installation set up with Composer (Composer Mode): yes
  • OS: Windows 11 (via ddev/Docker)

Possible Solution
Classes/EventListener/Order/Create/Number.php (abstract base class for OrderNumber, InvoiceNumber, DeliveryNumber) accesses $this->options['prefix'] and $this->options['suffix'] directly without checking whether the keys exist:

return implode('', [
    is_string($this->options['prefix']) ? $this->options['prefix'] : '',
    $number,
    is_string($this->options['suffix']) ? $this->options['suffix'] : '',
]);

Suggested fix:

return implode('', [
    is_string($this->options['prefix'] ?? null) ? $this->options['prefix'] : '',
    $number,
    is_string($this->options['suffix'] ?? null) ? $this->options['suffix'] : '',
]);

Additional context
Occurs whenever a site's TypoScript configuration for number generation omits prefix and/or suffix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions