magento2: Fatal error on creditmemo mail grouped product

Preconditions

  1. Magento 2.3.3
  2. Production mode and development mode

Steps to reproduce (*)

  1. Install Magento 2.3.3 with sample data
  2. Add grouped product to cart (Set of Sprite Yoga Straps)
  3. Place order
  4. Login in admin section
  5. Create invoice for order
  6. Create credit memo for order
  7. In the credit memo section click ‘Send Email’

Expected result (*)

  1. Mail is send
  2. No Fatal Error

Actual result (*)

  1. Mail is not send
  2. Fatal Error is thrown image
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)

Most upvoted comments

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 mail_server_error_500 mail_server_error_source

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

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Creditmemo Items List" design_abstraction="custom">
    <body>
        <referenceBlock name="sales.email.order.creditmemo.renderers">
            <block class="Magento\GroupedProduct\Block\Order\Email\Items\CreditMemo\Grouped" name="sales.email.order.creditmemo.renderers.grouped" as="grouped" template="Magento_Sales::email/items/creditmemo/default.phtml"/>
        </referenceBlock>
    </body>
</page>

In this case, the block above extends Magento\Sales\Block\Order\Email\Items\DefaultItems that has the getItemPrice, but its parameter type is not specified.

    /**
     * Get the html for item price
     *
     * @param OrderItem|InvoiceItem|CreditmemoItem $item
     * @return string
     * @throws LocalizedException
     */
    public function getItemPrice($item)
    {
        $block = $this->getLayout()->getBlock('item_price');
        $item->setRowTotal((float) $item->getPrice() * (float) $this->getItem()->getQty());
        $item->setBaseRowTotal((float) $item->getBasePrice() * (float) $this->getItem()->getQty());
        $block->setItem($item);
        return $block->toHtml();
    }

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