magento2: Fatal error on creditmemo mail grouped product
Preconditions
- Magento 2.3.3
- Production mode and development mode
Steps to reproduce (*)
- Install Magento 2.3.3 with sample data
- Add grouped product to cart (Set of Sprite Yoga Straps)
- Place order
- Login in admin section
- Create invoice for order
- Create credit memo for order
- In the credit memo section click ‘Send Email’
Expected result (*)
- Mail is send
- No Fatal Error
Actual result (*)
- Mail is not send
- Fatal Error is thrown

Fatal error: Uncaught TypeError:
Argument 1 passed to Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder::getItemPrice() must be an instance of Magento\Sales\Model\Order\Item,
instance of Magento\Sales\Model\Order\Creditmemo\Item given,
called in /www/magento233/vendor/magento/module-sales/view/frontend/templates/email/items/creditmemo/default.phtml
on line 32 and defined in /www/magento233/vendor/magento/module-sales/Block/Order/Email/Items/Order/DefaultOrder.php:99
Stack trace:
#0 /www/magento233/vendor/magento/module-sales/view/frontend/templates/email/items/creditmemo/default.phtml(32): Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder->getItemPrice(Object(Magento\Sales\Model\Order\Creditmemo\Item))
#1 /www/magento233/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/ww...')
#2 /www/magento233/vendor/magento/framework/View/Element/Template.php(271): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Gro in /www/magento233/vendor/magento/module-sales/Block/Order/Email/Items/Order/DefaultOrder.php on line 99
When async email is enabled
report.CRITICAL: Error when running a cron job
{"exception":
"[object] (RuntimeException(code: 0): Error when running a cron job at /www/magento233/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php:330,
TypeError(code: 0):
Argument 1 passed to Magento\\Sales\\Block\\Order\\Email\\Items\\Order\\DefaultOrder::getItemPrice() must be an instance of Magento\\Sales\\Model\\Order\\Item,
instance of Magento\\Sales\\Model\\Order\\Creditmemo\\Item given,
called in /www/magento233/var/view_preprocessed/pub/static/vendor/magento/module-sales/view/frontend/templates/email/items/creditmemo/default.phtml
on line 1 at /www/magento233/vendor/magento/module-sales/Block/Order/Email/Items/Order/DefaultOrder.php:99)"} []
Bug introduced at https://github.com/magento/magento2/pull/22265 But if you would revert this change, the mail works, but the subtotal is wrong indeed. So I think the accepted PR did some wrong fix.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 32 (25 by maintainers)
Sharing for referenece. this issue is already fixed in here https://github.com/magento/magento2/pull/26246
Hello @cyildirim thank you for the provided attachment.
From what I can see is that you are using Magento 2.3.5. We have rechecked this issue on Magento 2.3.5-p1 on the Turkish locale and indeed, the issue is reproducible. Please see the attachments

However, the issue is not reproducible on the latest 2.4-develop on the same machine, with the same steps and settings: locale, currency, products, user address…
Are you sure that you have been able to reproduce the issue on the latest 2.4-develop?
Thank you
Hi @cyildirim, I’m also not able to reproduce it locally but I’ve done some investigation on this. From what I could see locally with vanilla 2.4-develop Magento installed we have the following scenario:
The Layout XML used when the email is sent is:
app/code/Magento/GroupedProduct/view/frontend/layout/sales_email_order_creditmemo_renderers.xmlIn this case, the block above extends
Magento\Sales\Block\Order\Email\Items\DefaultItemsthat has thegetItemPrice, but its parameter type is not specified.Can you debug your case and provide more details? Maybe there is something else we are missing here. Thanks.
@engcom-Bravo your steps seem correct. I’ll try it again with my local and will update here. Till then you may try to create new grouped product and try with that though. i don’t expect that’s the actual issue. Because i remember used a new grouped product.
@engcom-Bravo As far as i get it from screenshot you shared, you recieved email for order confirmation. You need to check creditmemo email. (you’ll need to check “send copy of email” option while creating creditmemo). Also remember to disable async emails before to do that to see the exception right away.
@engcom-Bravo I used mailhog to reproduce this. But i had the same issue with Mageplaza SMTP/ AWS SES as well. Also feel free to share your thoughts in my PR here please. https://github.com/magento/magento2/pull/31819