0

I migrated to craft 4 according to the migration guide and everything went well. Steps to reproduce

  1. Migrate to craft
  2. Add something into the cart
  3. On the Cart template there is the following error on the cart page:

craft\commerce\services\Discounts::getDiscountByCode(): Argument #1 ($code) must be of type string, null given, called in /Users/atelierworkstation/Documents/git-local/atelier-shop/vendor/twig/twig/src/Extension/CoreExtension.php on line 1607

TypeError: craft\commerce\services\Discounts::getDiscountByCode(): Argument #1 ($code) must be of type string, null given, called in /vendor/twig/twig/src/Extension/CoreExtension.php on line 1607 and defined in /vendor/craftcms/commerce/src/services/Discounts.php:382
Stack trace:
#0 /vendor/twig/twig/src/Extension/CoreExtension.php(1607): craft\commerce\services\Discounts->getDiscountByCode(NULL)
#1 /vendor/craftcms/cms/src/helpers/Template.php(110): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\commerce\services\Discounts), 'getDiscountByCo...', Array, 'method', false, false)
#2 /storage/runtime/compiled_templates/48/4814239c41dedafc8391a1b70140a2d5.php(59): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\commerce\services\Discounts), 'getDiscountByCo...', Array, 'method')
#3 /vendor/twig/twig/src/Template.php(171): __TwigTemplate_fc9f511b5bd2fbee71b2e2d81933d7e6->block_main(Array, Array)
#4 /storage/runtime/compiled_templates/1c/1c64b2042fe0dfe96716d9e6f05f4b31.php(332): Twig\Template->displayBlock('main', Array, Array)
#5 /vendor/twig/twig/src/Template.php(171): __TwigTemplate_f939a9e67f563b6befd17836bf1b98ec->block_body(Array, Array)
#6 /storage/runtime/compiled_templates/1c/1c64b2042fe0dfe96716d9e6f05f4b31.php(304): Twig\Template->displayBlock('body', Array, Array)
#7 /vendor/twig/twig/src/Template.php(394): __TwigTemplate_f939a9e67f563b6befd17836bf1b98ec->doDisplay(Array, Array)
#8 /vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#9 /storage/runtime/compiled_templates/06/06430c5474c19a0e396cb203c104bc63.php(53): Twig\Template->display(Array, Array)
#10 /vendor/twig/twig/src/Template.php(394): __TwigTemplate_f1d0c467d20bbb79bcf56d6786094c73->doDisplay(Array, Array)
#11 /vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#12 /storage/runtime/compiled_templates/48/4814239c41dedafc8391a1b70140a2d5.php(46): Twig\Template->display(Array, Array)
#13 /vendor/twig/twig/src/Template.php(394): __TwigTemplate_fc9f511b5bd2fbee71b2e2d81933d7e6->doDisplay(Array, Array)
#14 /vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#15 /vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#16 /vendor/twig/twig/src/TemplateWrapper.php(40): Twig\Template->render(Array, Array)
#17 /vendor/twig/twig/src/Environment.php(277): Twig\TemplateWrapper->render(Array)
#18 /vendor/craftcms/cms/src/web/View.php(451): Twig\Environment->render('purchase/cart', Array)
#19 /vendor/craftcms/cms/src/web/View.php(504): craft\web\View->renderTemplate('purchase/cart', Array)
#20 /vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(56): craft\web\View->renderPageTemplate('purchase/cart', Array, 'site')
#21 /vendor/yiisoft/yii2/web/Response.php(1098): craft\web\TemplateResponseFormatter->format(Object(craft\web\Response))
#22 /vendor/craftcms/cms/src/web/Response.php(286): yii\web\Response->prepare()
#23 /vendor/yiisoft/yii2/web/Response.php(339): craft\web\Response->prepare()
#24 /vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#25 /www/index.php(32): yii\base\Application->run()
#26 {main}

Craft CMS: 4.4.3 Craft Commerce: 4.2.3 PHP: 8.1.1

2
  • After you migrate, do you ever try to clearing the cache?
    – aodihis
    Commented Nov 29, 2022 at 7:12
  • nope. cleared the cache several times. This has no effect
    – KSPR
    Commented Nov 30, 2022 at 9:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.