commerce icon indicating copy to clipboard operation
commerce copied to clipboard

[5.x]: Error when browsing "Store management" pages in CMS dashboard

Open benfeather opened this issue 2 years ago • 3 comments

What happened?

Description

Craft commerce throws an error when accessing a subpage under the "Store management" section in the Craft CMS dashboard:

Twig\Error\RuntimeError: Impossible to access an attribute ("name") on a null variable. in /var/www/html/vendor/craftcms/commerce/src/templates/_layouts/store-management.twig:14
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/helpers/Template.php(129): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), NULL, 'name', Array, 'any', false, false)
#1 /var/www/html/storage/runtime/compiled_templates/db/db70935bbc9c1af3a548d2b32c51276c.php(64): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), NULL, 'name', Array)
#2 /var/www/html/vendor/twig/twig/src/Template.php(394): __TwigTemplate_7198c7ce3f5eda482e2a54ea0f1d6595->doDisplay(Array, Array)
#3 /var/www/html/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#4 /var/www/html/storage/runtime/compiled_templates/0b/0b9e6febddbf82fee0f62812949e233a.php(99): Twig\Template->display(Array, Array)
#5 /var/www/html/vendor/twig/twig/src/Template.php(394): __TwigTemplate_77c6311e3635018ad9d7827edc97adce->doDisplay(Array, Array)
#6 /var/www/html/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#7 /var/www/html/vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#8 /var/www/html/vendor/twig/twig/src/TemplateWrapper.php(38): Twig\Template->render(Array)
#9 /var/www/html/vendor/twig/twig/src/Environment.php(280): Twig\TemplateWrapper->render(Array)
#10 /var/www/html/vendor/craftcms/cms/src/web/View.php(482): Twig\Environment->render('commerce/store-...', Array)
#11 /var/www/html/vendor/craftcms/cms/src/web/View.php(535): craft\web\View->renderTemplate('commerce/store-...', Array)
#12 /var/www/html/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(57): craft\web\View->renderPageTemplate('commerce/store-...', Array, 'cp')
#13 /var/www/html/vendor/yiisoft/yii2/web/Response.php(1100): craft\web\TemplateResponseFormatter->format(Object(craft\web\Response))
#14 /var/www/html/vendor/craftcms/cms/src/web/Response.php(337): yii\web\Response->prepare()
#15 /var/www/html/vendor/yiisoft/yii2/web/Response.php(340): craft\web\Response->prepare()
#16 /var/www/html/vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#17 /var/www/html/web/index.php(17): yii\base\Application->run()
#18 {main}

Steps to reproduce

  1. Install craft cms 5 beta.
  2. Install craft commerce beta from the plugin store.
  3. Navigate to: /commerce/store-management/
  4. Click on any of the links to the sub pages (excluding the general page).

Expected behavior

No error.

Actual behavior

Has error.

Craft CMS version

5.0.0-beta.6

Craft Commerce version

5.0.0-beta.1

PHP version

8.2.15

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

"require": {
    "craftcms/ckeditor": "4.0.0-beta.7",
    "craftcms/cms": "5.0.0-beta.6",
    "craftcms/commerce": "5.0.0-beta.1",
    "doublesecretagency/craft-cpcss": "3.0.0",
    "doublesecretagency/craft-cpjs": "3.0.0",
    "ether/simplemap": "v5.0.0-rc1",
    "mmikkel/cp-field-inspect": "2.0.0-beta.3",
    "nystudio107/craft-retour": "5.0.0-beta.4",
    "nystudio107/craft-seomatic": "5.0.0-beta.5",
    "spicyweb/craft-batch-actions": "2.0.0-beta.1",
    "spicyweb/craft-embedded-assets": "5.0.0-beta.1",
    "verbb/field-manager": "4.0.0-beta.1",
    "verbb/formie": "3.0.0-beta.3",
    "verbb/hyper": "2.0.0-beta.2",
    "verbb/social-poster": "5.0.0-beta.1",
    "verbb/stamped-io": "3.0.0-beta.1",
    "verbb/timber": "2.0.0-beta.2",
    "vlucas/phpdotenv": "^5.4.0"
  }

benfeather avatar Mar 06 '24 23:03 benfeather

@benfeather I am unable to reproduce this issue. It looks like you have no store with the store handle attempted to be accessed from the URL. Can you confirm you have the store in the project config and database with that handle?

Can you make sure you clear any template caches with ddev craft clear-caches/all.

lukeholder avatar Mar 07 '24 09:03 lukeholder

I cleared the cache and disabled all of my plugins, but I still had the same issue.

I was able to fix the problem by:

  1. Deleting cpresources, vendor and the composer-lock file
  2. Clearing Composer's cache with ddev composer clear-cache
  3. Reinstalled the packages.

I'm not sure what happened, but this issue is resolved; thank you for your help.

P.S. Craft 5 is looking great; I'm really looking forward to the full release. Keep up the excellent work.

benfeather avatar Mar 07 '24 20:03 benfeather

Ok, this is strange. The error just happened again.

Each of these pages throws the same error:

CleanShot 2024-03-08 at 09 51 49@2x

Twig\Error\RuntimeError: Impossible to access an attribute ("name") on a null variable. in /var/www/html/vendor/craftcms/commerce/src/templates/_layouts/store-management.twig:14
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/helpers/Template.php(129): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), NULL, 'name', Array, 'any', false, false)
#1 /var/www/html/storage/runtime/compiled_templates/db/db3faf5001544eb3a150b0c235c840ce.php(64): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), NULL, 'name', Array)
#2 /var/www/html/vendor/twig/twig/src/Template.php(394): __TwigTemplate_d80ea5c574405a41441cd388758956cd->doDisplay(Array, Array)
#3 /var/www/html/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#4 /var/www/html/storage/runtime/compiled_templates/23/23da377f2ca9ec3be012050b75bb1846.php(151): Twig\Template->display(Array, Array)
#5 /var/www/html/vendor/twig/twig/src/Template.php(394): __TwigTemplate_11107a6a3456fd3f45080e71c0df3d8e->doDisplay(Array, Array)
#6 /var/www/html/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#7 /var/www/html/vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#8 /var/www/html/vendor/twig/twig/src/TemplateWrapper.php(38): Twig\Template->render(Array)
#9 /var/www/html/vendor/twig/twig/src/Environment.php(280): Twig\TemplateWrapper->render(Array)
#10 /var/www/html/vendor/craftcms/cms/src/web/View.php(482): Twig\Environment->render('commerce/store-...', Array)
#11 /var/www/html/vendor/craftcms/cms/src/web/View.php(535): craft\web\View->renderTemplate('commerce/store-...', Array)
#12 /var/www/html/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(57): craft\web\View->renderPageTemplate('commerce/store-...', Array, 'cp')
#13 /var/www/html/vendor/yiisoft/yii2/web/Response.php(1100): craft\web\TemplateResponseFormatter->format(Object(craft\web\Response))
#14 /var/www/html/vendor/craftcms/cms/src/web/Response.php(337): yii\web\Response->prepare()
#15 /var/www/html/vendor/yiisoft/yii2/web/Response.php(340): craft\web\Response->prepare()
#16 /var/www/html/vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#17 /var/www/html/web/index.php(17): yii\base\Application->run()
#18 {main}

I have uninstalled all plugins except for Craft Commerce.

CleanShot 2024-03-08 at 09 57 36@2x

I have two stores and two sites set up like so:

Sites CleanShot 2024-03-08 at 10 02 24@2x

Shops shop

Shop & Site sites

NZ config: nz

AU config: au

benfeather avatar Mar 07 '24 20:03 benfeather

@benfeather is this from a fresh install that already had a project config in place with multi-site?

Could you send your config folder (which includes the project config) and DB Backup and composer.json and composer.lock to [email protected] and reference this issue? We can then take a look. Thanks for reporting.

lukeholder avatar Mar 13 '24 09:03 lukeholder

@benfeather What does the URL look like when you get that error?

lukeholder avatar Mar 13 '24 09:03 lukeholder

Here's the URL: https://craft-5.ddev.site/commerce/store-management/tepariNZ/inventory-locations?site=tepariNZ

This was a fresh install when the first Craft 5 Alpha was released.

I have sent the files to the support email.

benfeather avatar Mar 13 '24 20:03 benfeather

@benfeather Could you update to the latest on the develop branch:

change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "dev-5.0#c6fc6590d47e9b4c144825e6e907e11375faa0ca as 5.0.0-beta.1",
  "...": "..."
}

Then run composer update.

After that run Ultilities > Project Config > Rebuild

And let me know if that fixes it. Thanks.

lukeholder avatar Mar 15 '24 09:03 lukeholder

I can't install that version using composer:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires craftcms/commerce dev-5.0#c6fc6590d47e9b4c144825e6e907e11375faa0ca as 5.0.0-beta.1, found craftcms/commerce[dev-zarchive/order-edit-line-item-options, ..., dev-patch-1, 0.9.1170, ..., 0.9.1176, 1.0.1182, ..., 1.2.1334, 2.0.0-beta.1, ..., 2.2.27, 3.0.0-alpha.1, ..., v3.x-dev, 4.0.0-beta.1, ..., 4.5.2, 5.0.0-beta.1, 5.0.x-dev] but it does not match the constraint.

Composer [update] failed, composer command failed: exit status 2.

benfeather avatar Mar 17 '24 04:03 benfeather

Hi @benfeather

Can you try the following in your composer file:

"require": {
  "craftcms/commerce": "5.0.x-dev#c6fc6590d47e9b4c144825e6e907e11375faa0ca as 5.0.0-beta.1",
  "...": "..."
}

Then run composer update. Hopefully this should get you pointing to the correct commit

nfourtythree avatar Mar 17 '24 07:03 nfourtythree

I installed that version and rebuilt the config, but I still get that error on the store management pages.

benfeather avatar Mar 17 '24 20:03 benfeather

Closing as this was resolved via support. Project related issue and not a Commerce bug.

nfourtythree avatar Mar 21 '24 06:03 nfourtythree