<p>I migrated to craft 4 according to the migration guide and everything went well.
Steps to reproduce</p>
<ol>
<li>Migrate to craft</li>
<li>Add something into the cart</li>
<li>On the Cart template there is the following error on the cart page:</li>
</ol>
<blockquote>
<p>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</p>
</blockquote>
<pre><code>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-&gt;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-&gt;block_main(Array, Array)
#4 /storage/runtime/compiled_templates/1c/1c64b2042fe0dfe96716d9e6f05f4b31.php(332): Twig\Template-&gt;displayBlock('main', Array, Array)
#5 /vendor/twig/twig/src/Template.php(171): __TwigTemplate_f939a9e67f563b6befd17836bf1b98ec-&gt;block_body(Array, Array)
#6 /storage/runtime/compiled_templates/1c/1c64b2042fe0dfe96716d9e6f05f4b31.php(304): Twig\Template-&gt;displayBlock('body', Array, Array)
#7 /vendor/twig/twig/src/Template.php(394): __TwigTemplate_f939a9e67f563b6befd17836bf1b98ec-&gt;doDisplay(Array, Array)
#8 /vendor/twig/twig/src/Template.php(367): Twig\Template-&gt;displayWithErrorHandling(Array, Array)
#9 /storage/runtime/compiled_templates/06/06430c5474c19a0e396cb203c104bc63.php(53): Twig\Template-&gt;display(Array, Array)
#10 /vendor/twig/twig/src/Template.php(394): __TwigTemplate_f1d0c467d20bbb79bcf56d6786094c73-&gt;doDisplay(Array, Array)
#11 /vendor/twig/twig/src/Template.php(367): Twig\Template-&gt;displayWithErrorHandling(Array, Array)
#12 /storage/runtime/compiled_templates/48/4814239c41dedafc8391a1b70140a2d5.php(46): Twig\Template-&gt;display(Array, Array)
#13 /vendor/twig/twig/src/Template.php(394): __TwigTemplate_fc9f511b5bd2fbee71b2e2d81933d7e6-&gt;doDisplay(Array, Array)
#14 /vendor/twig/twig/src/Template.php(367): Twig\Template-&gt;displayWithErrorHandling(Array, Array)
#15 /vendor/twig/twig/src/Template.php(379): Twig\Template-&gt;display(Array)
#16 /vendor/twig/twig/src/TemplateWrapper.php(40): Twig\Template-&gt;render(Array, Array)
#17 /vendor/twig/twig/src/Environment.php(277): Twig\TemplateWrapper-&gt;render(Array)
#18 /vendor/craftcms/cms/src/web/View.php(451): Twig\Environment-&gt;render('purchase/cart', Array)
#19 /vendor/craftcms/cms/src/web/View.php(504): craft\web\View-&gt;renderTemplate('purchase/cart', Array)
#20 /vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(56): craft\web\View-&gt;renderPageTemplate('purchase/cart', Array, 'site')
#21 /vendor/yiisoft/yii2/web/Response.php(1098): craft\web\TemplateResponseFormatter-&gt;format(Object(craft\web\Response))
#22 /vendor/craftcms/cms/src/web/Response.php(286): yii\web\Response-&gt;prepare()
#23 /vendor/yiisoft/yii2/web/Response.php(339): craft\web\Response-&gt;prepare()
#24 /vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response-&gt;send()
#25 /www/index.php(32): yii\base\Application-&gt;run()
#26 {main}
</code></pre>
<p>Craft CMS: 4.4.3
Craft Commerce: 4.2.3
PHP: 8.1.1</p>

CC BY-SA 4.0
2022-11-29T07:12:18.393Z
After you migrate, do you ever try to clearing the cache?
aodihis
CC BY-SA 4.0
2022-11-30T09:56:36.707Z
nope. cleared the cache several times. This has no effect
KSPR
<migration><craft4><commerce4>
getDiscountByCode(): Argument #1 ($code) must be of type string, null given
# getDiscountByCode(): Argument #1 ($code) must be of type string, null given

(Asked by: username_0 on 2022-11-28)

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

Migrate to craft
Add something into the cart
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

**Tags:** migration, craft4, commerce4

> **Comments:**
> **username_1**: After you migrate, do you ever try to clearing the cache?  
> **username_0**: nope. cleared the cache several times. This has no effect  

---

## 0 answers

