Skip to content

[5.x]: Twig RuntimeError: Coupon::hiddenInputs() called when editing Discount’s Coupons #4069

@martinleveille

Description

@martinleveille

What happened?

Description

When creating a Discount with an associated Coupon code in the control panel, saving and reloading the Discount causes a Twig runtime error. It attempts to call a hiddenInputs() method on the craft\commerce\models\Coupon model, which doesn't exist.

The error originates from editableTable.twig, likely when rendering the Coupons list within the Discount editor.

Steps to reproduce

  1. Go to Commerce → Store Management → Discounts.

  2. Create a new Discount (or edit an existing one).

  3. Switch to the Coupons tab.

  4. Enable Require Coupon Code lightswitch.

  5. Click + Add a coupon.

  6. Enter Code then save the Discount.

  7. Re-open the same Discount to edit it again.

  8. Observe the error thrown instead of the normal editable table for coupons.

Expected behavior

The Coupons tab should render a table of associated coupon codes without error.

No Twig exceptions should be thrown when reloading the Discount edit screen.

Actual behavior

Twig\Error\RuntimeError: Calling unknown method: craft\commerce\models\Coupon::hiddenInputs() in /var/www/html/vendor/craftcms/cms/src/templates/_includes/forms/editableTable.twig:285
Stack trace:
#0 /var/www/html/storage/runtime/compiled_templates/59/59f6c9f51928b822c56a00e2ea8458e8.php(432): craft\helpers\Template::attribute()
#1 /var/www/html/vendor/twig/twig/src/Template.php(387): __TwigTemplate_fb7abb09b4b65507f3b1f3cf55a722fc->doDisplay()
#2 /var/www/html/storage/runtime/compiled_templates/be/be7bc29e8ff13426b60b0c8cd02a5546.php(901): Twig\Template->yield()
#3 /var/www/html/vendor/twig/twig/src/Extension/CoreExtension.php(2058): __TwigTemplate_4c36d931586389595f088ea132fb660e->{closure}()
#4 /var/www/html/storage/runtime/compiled_templates/be/be7bc29e8ff13426b60b0c8cd02a5546.php(897): Twig\Extension\CoreExtension::captureOutput()
#5 /var/www/html/storage/runtime/compiled_templates/c5/c55e87e55a30123f99d739d65ec59fb3.php(497): __TwigTemplate_4c36d931586389595f088ea132fb660e->macro_editableTable()
#6 /var/www/html/vendor/twig/twig/src/Extension/CoreExtension.php(2058): __TwigTemplate_1e1348b57d00eafc0e465701c52a8fbd->{closure}()
#7 /var/www/html/storage/runtime/compiled_templates/c5/c55e87e55a30123f99d739d65ec59fb3.php(492): Twig\Extension\CoreExtension::captureOutput()
#8 /var/www/html/vendor/twig/twig/src/Template.php(431): __TwigTemplate_1e1348b57d00eafc0e465701c52a8fbd->block_content()
#9 /var/www/html/storage/runtime/compiled_templates/f3/f3426d1105d66071e9aea2a64a10e996.php(674): Twig\Template->yieldBlock()
#10 /var/www/html/vendor/twig/twig/src/Template.php(431): __TwigTemplate_752bb38235c891c8ae6c5f611d49399b->block_main()
#11 /var/www/html/storage/runtime/compiled_templates/f3/f3426d1105d66071e9aea2a64a10e996.php(402): Twig\Template->yieldBlock()
#12 /var/www/html/vendor/twig/twig/src/Template.php(431): __TwigTemplate_752bb38235c891c8ae6c5f611d49399b->block_body()
#13 /var/www/html/storage/runtime/compiled_templates/1a/1a6cb34b5591e7d414c53576761b1208.php(102): Twig\Template->yieldBlock()
#14 /var/www/html/vendor/twig/twig/src/Template.php(387): __TwigTemplate_e0d08f71dde67dfae8f7c5cdb7141b07->doDisplay()
#15 /var/www/html/storage/runtime/compiled_templates/ea/ea70a175a7f55db0d1f5339c58e54b77.php(60): Twig\Template->yield()
#16 /var/www/html/vendor/twig/twig/src/Template.php(387): __TwigTemplate_d59b3249c39149d9d81e983df4d4bd07->doDisplay()
#17 /var/www/html/storage/runtime/compiled_templates/f3/f3426d1105d66071e9aea2a64a10e996.php(179): Twig\Template->yield()
#18 /var/www/html/vendor/twig/twig/src/Template.php(387): __TwigTemplate_752bb38235c891c8ae6c5f611d49399b->doDisplay()
#19 /var/www/html/storage/runtime/compiled_templates/ce/ce28b0d4515093402a7632a7dc515d9d.php(50): Twig\Template->yield()
#20 /var/www/html/vendor/twig/twig/src/Template.php(387): __TwigTemplate_b39a93e6cc29f3d3c829b1a576995887->doDisplay()
#21 /var/www/html/storage/runtime/compiled_templates/8d/8de57b5334b9e4caac3106157977c45d.php(80): Twig\Template->yield()
#22 /var/www/html/vendor/twig/twig/src/Template.php(387): __TwigTemplate_15eb653dafe2adeca8253e29757018a7->doDisplay()
#23 /var/www/html/storage/runtime/compiled_templates/c5/c55e87e55a30123f99d739d65ec59fb3.php(203): Twig\Template->yield()
#24 /var/www/html/vendor/twig/twig/src/Template.php(387): __TwigTemplate_1e1348b57d00eafc0e465701c52a8fbd->doDisplay()
#25 /var/www/html/vendor/twig/twig/src/Template.php(343): Twig\Template->yield()
#26 /var/www/html/vendor/twig/twig/src/Template.php(358): Twig\Template->display()
#27 /var/www/html/vendor/twig/twig/src/TemplateWrapper.php(35): Twig\Template->render()
#28 /var/www/html/vendor/twig/twig/src/Environment.php(320): Twig\TemplateWrapper->render()
#29 /var/www/html/vendor/craftcms/cms/src/web/View.php(570): Twig\Environment->render()
#30 /var/www/html/vendor/craftcms/cms/src/web/View.php(623): craft\web\View->renderTemplate()
#31 /var/www/html/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(57): craft\web\View->renderPageTemplate()
#32 /var/www/html/vendor/yiisoft/yii2/web/Response.php(1109): craft\web\TemplateResponseFormatter->format()
#33 /var/www/html/vendor/craftcms/cms/src/web/Response.php(341): yii\web\Response->prepare()
#34 /var/www/html/vendor/yiisoft/yii2/web/Response.php(340): craft\web\Response->prepare()
#35 /var/www/html/vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#36 /var/www/html/web/index.php(12): yii\base\Application->run()
#37 {main}

Craft CMS version

5.8.3

Craft Commerce version

5.4.0

PHP version

8.3

Operating system and version

No response

Database type and version

MySQL 8.0

Image driver and version

No response

Installed plugins and versions

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions