Skip to content

Call to undefined method Category::getCartProductShowPid() — missing Extbase Object substitution #293

Description

@Hobokens

Bug Report

Current Behavior
Rendering a cartproducts_listproducts (or cartproducts_showproduct) plugin whose product has a category throws a fatal error:

Call to undefined method TYPO3\CMS\Extbase\Domain\Model\Category::getCartProductShowPid()
in Classes/ViewHelpers/Link/ProductViewHelper.php line 102

Expected behavior/output
The extended Extcode\CartProducts\Domain\Model\Category (which provides getCartProductShowPid() / getCartProductListPid()) should be used wherever a category is loaded via a product, so the plugin renders without error.

Environment

  • TYPO3 version(s): 14.3
  • cart-products version: dev-main (8.x branch)
  • Is your TYPO3 installation set up with Composer (Composer Mode): yes
  • OS: Windows 11 (via ddev/Docker)

Possible Solution
Configuration/Extbase/Persistence/Classes.php maps Extcode\CartProducts\Domain\Model\Category to the sys_category table, but that only configures persistence (table mapping) — it does not register an Extbase Object substitution. extcode/cart's CategoryTrait::getCategory() is typed to the core TYPO3\CMS\Extbase\Domain\Model\Category, so without a substitution Extbase hydrates the plain core class instead of the extended one.

Adding the following to ext_localconf.php resolves the issue:

$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Extbase\Domain\Model\Category::class] = [
    'className' => \Extcode\CartProducts\Domain\Model\Category::class,
];

Additional context
Confirmed by registering the substitution manually in a site extension's ext_localconf.php — the error disappears immediately.

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