Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x]: craft\commerce\services\Stores::craft\commerce\services\{closure}(): Argument #1 ($site) must be of type craft\models\Site, null given #3755

Open
bartdigitalpulse opened this issue Nov 8, 2024 · 3 comments

Comments

@bartdigitalpulse
Copy link

What happened?

Description

I get this error on the admin/dashboard and on the store settings. I think it has to do with stores settings not getting correctly updated after removing a site in admin/settings/sites.

TypeError: craft\commerce\services\Stores::craft\commerce\services\{closure}(): Argument #1 ($site) must be of type craft\models\Site, null given in vendor/craftcms/commerce/src/services/Stores.php:227
Stack trace:
#0 [internal function]: craft\commerce\services\Stores->craft\commerce\services\{closure}()
#1 vendor/illuminate/collections/Arr.php(600): array_map()
#2 vendor/illuminate/collections/Collection.php(778): Illuminate\Support\Arr::map()
#3 vendor/craftcms/commerce/src/services/Stores.php(227): Illuminate\Support\Collection->map()
#4 [internal function]: craft\commerce\services\Stores->craft\commerce\services\{closure}()
#5 vendor/illuminate/collections/Arr.php(911): array_filter()
#6 vendor/illuminate/collections/Collection.php(388): Illuminate\Support\Arr::where()
#7 vendor/craftcms/commerce/src/services/Stores.php(226): Illuminate\Support\Collection->filter()
#8 vendor/twig/twig/src/Extension/CoreExtension.php(1802): craft\commerce\services\Stores->getStoresByUserId()
#9 vendor/craftcms/cms/src/helpers/Template.php(148): Twig\Extension\CoreExtension::getAttribute()
#10 shared/storage/runtime/compiled_templates/b0/b0d57600644a1953f31e4db0604169e8.php(49): craft\helpers\Template::attribute()
#11 vendor/twig/twig/src/Template.php(393): __TwigTemplate_b41cc74617e1b7734b85636267556e63->doDisplay()
#12 shared/storage/runtime/compiled_templates/f5/f5e8e0adf4e4979b04e778927d1352c0.php(52): Twig\Template->yield()
#13 vendor/twig/twig/src/Template.php(393): __TwigTemplate_cced57f1caf1e6ea99fa90586938377c->doDisplay()
#14 vendor/twig/twig/src/Template.php(349): Twig\Template->yield()
#15 vendor/twig/twig/src/Template.php(364): Twig\Template->display()
#16 vendor/twig/twig/src/TemplateWrapper.php(35): Twig\Template->render()
#17 vendor/twig/twig/src/Environment.php(306): Twig\TemplateWrapper->render()
#18 vendor/craftcms/cms/src/web/View.php(500): Twig\Environment->render()
#19 vendor/craftcms/commerce/src/widgets/AverageOrderTotal.php(129): craft\web\View->renderTemplate()
#20 vendor/craftcms/cms/src/controllers/DashboardController.php(77): craft\commerce\widgets\AverageOrderTotal->getSettingsHtml()
#21 vendor/craftcms/cms/src/web/View.php(1738): craft\controllers\DashboardController->craft\controllers\{closure}()
#22 vendor/craftcms/cms/src/controllers/DashboardController.php(76): craft\web\View->namespaceInputs()
#23 [internal function]: craft\controllers\DashboardController->actionIndex()
#24 vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#25 vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#26 vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#27 vendor/craftcms/cms/src/web/Application.php(350): yii\base\Module->runAction()
#28 vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction()
#29 vendor/craftcms/cms/src/web/Application.php(318): yii\web\Application->handleRequest()
#30 vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#31 web/index.php(12): yii\base\Application->run()
#32 {main}

Steps to reproduce

  1. Setup a multi site commerce and play around with removing and adding sites.

Craft CMS version

Craft Pro 5.4.10.1

Craft Commerce version

5.2.2

PHP version

8.2.24

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@bartdigitalpulse
Copy link
Author

In the commerce_site_stores table there was a row with siteId 7.
In the sites table Site with Id 7 dateDeleted was not null.

Deleting the row in commerce_site_stores fixed the error.

@nfourtythree nfourtythree self-assigned this Nov 8, 2024
@nfourtythree
Copy link
Contributor

Hi @bartdigitalpulse

I have tried to replicate this issue but am unable to get into the state you mentioned.

When a site is deleted (even soft deleted) the record from the commerce_site_stores table is removed, this is done by Commerce listening to the site delete event from Craft and removing the site store record from Commerce's project config.

Is it possible for you to show the steps that got you to this point?

I tried

  • Creating a new site
  • Waiting for it to propagate data
  • Saw the record in the sites and commerce_site_stores tables
  • Deleted the site
  • Observed the dateDeleted being not null in the sites table
  • Observed that the relationship row in the commerce_site_stores had been removed
  • No errors in the CP

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants