- Issue created by @Grimreaper
- 🇫🇷France Grimreaper France 🇫🇷
Digging up, it was the access on the product variation which was problematic, order item fields were ok.
Having updated the permissions on my website to give anonymous users access to my product types fixed the problem.
I keep the issue opened because the access check needs to be done on the order's customer and not depend on the current user during sending mail code execution.
- Status changed to Fixed
3 months ago 7:35am 22 July 2024 - 🇮🇱Israel jsacksick
I think the problem here is simply cron that's ran as user 0 (anonymous).
What's happening is that the order item access is determined by the access on the order. Considering cron is executed as user 0, this can't work.This is more like a support request than a bug report.
For example, if you'd like to run your cron as user 1, you can do the following:
$account_switcher = \Drupal::service('account_switcher'); $account_switcher->switchTo(new UserSession(['uid' => 1])); // Run your code... // then call the switchBack() method. $account_switcher->switchBack();
- 🇫🇷France Grimreaper France 🇫🇷
Thanks for the quick feedback.
I tried to switch account but with \Drupal::currentUser()->setAccount()..., I felt it was not the right way to do it, but forgot how to do it and what to search for.
Thanks for the code snippet, as mentioned, updating my user permissions fixed it, but I will try it to ensure it is ok. I will use the order's customer. With changes in Core 10.3 allowing to remove user 1 the super admin right, I don't know if it is a long term solution :)
But I still think, sending the receipt email should already be evaluated in the order's customer context.
- 🇮🇱Israel jsacksick
But I still think, sending the receipt email should already be evaluated in the order's customer context.
What you're suggesting would imply that the order receipt should switch the active user to the order customer. I think that is "risky". Admins are allow to resend receipts from the admin and they should have sufficient rights for the receipt to be rendered without issues.
Automatically closed - issue fixed for 2 weeks with no activity.