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

3.0.0-beta.1 - error when used with commerce 5 #60

Closed
stanislavprokopov opened this issue Jun 13, 2024 · 1 comment
Closed

3.0.0-beta.1 - error when used with commerce 5 #60

stanislavprokopov opened this issue Jun 13, 2024 · 1 comment

Comments

@stanislavprokopov
Copy link

stanislavprokopov commented Jun 13, 2024

Setup:

  • Craft 5.2.0
  • Commerce 5.0.10
  • GeoMate 3.0.0-beta.1

Add {{ dump(currentUser.getPrimaryBillingAddress()) }} to templates/index.twig

Now open homepage, result:

Twig Runtime Error – [Twig\Error\RuntimeError](http://twig.sensiolabs.org/api/2.x/Twig/Error/RuntimeError.html)
Calling unknown method: craft\elements\User::getPrimaryBillingAddress()

Now if you disable GeoMate and check the same page you will not get any errors but will get null as you are not authenticated.

It appears that the CustomerBehavior registered by Commerce plugin is missing for some reason.

Disabling this part in RedirectService makes it work again:

if ($this->shouldIgnoreUser()) {
            GeoMate::log('Redirect ignored because of user credentials (user is either an admin or in a usergroup that was configured to be ignored).', Logger::LEVEL_INFO);
            return null;
        }

I would guess its related to init order, calling getIdentity() caches the user object before commerce registers the behavior so when user is used in tpl it is missing the required methods and causes the error, changing

Craft::$app->on(Application::EVENT_INIT, function() {
            $this->redirectCheck();
        }, null, false);

to

Craft::$app->on(Application::EVENT_INIT, function() {
            $this->redirectCheck();
        }, null, true);

or

Craft::$app->onInit(function() {
$this->redirectCheck();
});

Fixes the issue, but I am not sure how it affects other parts of the plugin.

mmikkel added a commit that referenced this issue Jun 13, 2024
@mmikkel
Copy link
Member

mmikkel commented Jun 13, 2024

Thanks for reporting that.

I just tagged GeoMate v. 3.0.0-beta.2 (Craft 5) and v. 2.1.3 (Craft 4) with a fix for this issue.

aelvan pushed a commit that referenced this issue Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants