craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
219 stars 170 forks source link

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

Closed benfeather closed 6 months ago

benfeather commented 7 months ago

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"
  }
lukeholder commented 7 months ago

@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.

benfeather commented 7 months ago

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 commented 7 months ago

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

lukeholder commented 6 months ago

@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 support@craftcms.com and reference this issue? We can then take a look. Thanks for reporting.

lukeholder commented 6 months ago

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

benfeather commented 6 months ago

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.

lukeholder commented 6 months ago

@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.

benfeather commented 6 months ago

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.
nfourtythree commented 6 months ago

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

benfeather commented 6 months ago

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

nfourtythree commented 6 months ago

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