Magento2: Error While send Invoice with Grouped Products

Created on 20 Jun 2016  Â·  23Comments  Â·  Source: magento/magento2

Steps to reproduce

  1. Install Magento from develop branch.
  2. Add some Grouped Product to cart.
  3. Place an order with the grouped product.
  4. Go to admin.
  5. Go to Sales>Orders and open de current order with the grouped product.
  6. Go to Invoice and select the "Email Copy of Invoice" checkbox.
  7. Press "Submit Invoice".

    Expected result

  8. Invoice the order.

  9. Send the copy email to client.

    Actual result

  10. Order is invoiced.

  11. An error occurs with the price and send email fails.

The error from report:
AH01071: Got error 'PHP message: PHP 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\\Invoice\\Item given, called in /var/www/vhosts/superpiensos.com/development/vendor/magento/module-sales/view/frontend/templates/email/items/invoice/default.phtml on line 34 and defined in /var/www/vhosts/superpiensos.com/development/vendor/magento/module-sales/Block/Order/Email/Items/Order/DefaultOrder.php:97\nStack trace:\n#0 /var/www/vhosts/superpiensos.com/development/vendor/magento/module-sales/view/frontend/templates/email/items/invoice/default.phtml(34): Magento\\Sales\\Block\\Order\\Email\\Items\\Order\\DefaultOrder->getItemPrice(Object(Magento\\Sales\\Model\\Order\\Invoice\\Item))\n#1 /var/www/vhosts/superpiensos.com/development/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/var/www/vhosts...')\n#2 /var/www/vhosts/superpiensos.com/development/vendor/magento/fr...\n', referer: http://magento.superpiensos.com/admin_superp/sales/order_invoice/new/order_id/92/key/a6d27d6abf43f83c88d6e6be59095107f13ef4b74420fb3697e35953217a52ac/

Fixed in 2.2.x Fixed in 2.3.x Clear Description Format is not valid bug report

All 23 comments

Hi @srbarba , we cannot reproduce this scenario on current develop(3561b6614eeafb70cbcbf0dc0254359b857af3d4).
You could disable all third party extensions, update your version of magento. Do composer install/update. Clear magento cache. Do bin/magento setup:upgrade.
If scenario will be reproducing again. Please add more details to steps for reproduce.
Thank you!

Hello!
I did a new installation(without third party extensions) with Magento 2.0.7v in another server.
The error appears.

Steps:

  1. Install Magento
  2. Create category
  3. Create 2 Simple Products
  4. Create Grouped with this 2 Simple products.
  5. Buy a simple product from the Grouped Product.
  6. Invoice the order at admin with Copy email option checked.

Result:
The error at first comment.

See that video!
https://drive.google.com/file/d/0B3WruH9jln9bVml1aDl5bG0zZW8/view

I tryed without "Autosettings" changes(at simple product) too, nothing change.

Hi @srbarba , thank you for your video.
Internal ticket MAGETWO-54633 was created.

Hi,

Just to let you know I'm also getting this similar when you try and click on "send email" for an invoiced order.

I'm also using magento version 2.0.7

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\Invoice\Item given, called in /Users/chris/Sites/magento_test/vendor/magento/module-sales/view/frontend/templates/email/items/invoice/default.phtml on line 34 and defined in /Users/chris/Sites/magento_test/vendor/magento/module-sales/Block/Order/Email/Items/Order/DefaultOrder.php:97 Stack trace: #0 /Users/chris/Sites/magento_test/vendor/magento/module-sales/view/frontend/templates/email/items/invoice/default.phtml(34): Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder->getItemPrice(Object(Magento\Sales\Model\Order\Invoice\Item)) #1 /Users/chris/Sites/magento_test/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/Users/chris...') #2 /Users/chris/Sites/magento_test/vendor/magento/framework/View/Element/Template.php(255): Magento\Framework\Vi in /Users/chris/Sites/magento_test/vendor/magento/module-sales/Block/Order/Email/Items/Order/DefaultOrder.php on line 97

Thanks

Hi,

Btw - The problem is the Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder::getItemPrice() method.

public function getItemPrice(OrderItem $item)
{
    $block = $this->getLayout()->getBlock('item_price');
    $block->setItem($item);
    return $block->toHtml();
}

If you take off the Type hint OrderItem $item for the argument and just have:

public function getItemPrice()
{
    $block = $this->getLayout()->getBlock('item_price');
    $block->setItem($item);
    return $block->toHtml();
}

it works fine

Also this is in magento 2.1.12 as well

Hi everyone.

Any news about this error?

Cheers.

Experiencing the issue on 2.1.4.
Trying out the type hinting workaround by @ghost.

It is tricky to implement a workaround as a custom module, because the signature of the method \Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder::getItemPrice() cannot be overridden by a descendant due to type incompatibility of order item and invoice item.

Looking forward to the fix in core.

@Mulderua please provide an update about this issue?
We cannot release our clients Magento 2 webshop because customers see a broken white page after they paid and return from the PSP !! And there is no workaround except changing core code, which means I need to do this manually every single time my CI pipeline has run..

It's almost been a year since this issue was posted..

just create preference for \Magento\GroupedProduct\Block\Order\Email\Items\Order\Grouped

and extend your block from \Magento\Framework\View\Element\Template. This way you can change signature of buggy getItemPrice($item) method. Don't forget to copy the rest methods from \Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder

Same error 2.1.5

  • Clean install
  • Create grouped product
  • Place in order
  • Invoice order
    -Resend email

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\Invoice\Item given, called in /var/www/html/vendor/magento/module-sales/view/frontend/templates/email/items/invoice/default.phtml on line 34 and defined in /var/www/html/vendor/magento/module-sales/Block/Order/Email/Items/Order/DefaultOrder.php:97 Stack trace: #0 /var/www/html/vendor/magento/module-sales/view/frontend/templates/email/items/invoice/default.phtml(34): Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder->getItemPrice(Object(Magento\Sales\Model\Order\Invoice\Item)) #1 /var/www/html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/var/www/html/v...') #2 /var/www/html/vendor/magento/framework/View/Element/Template.php(255): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\GroupedProduct\Block\Order\Email\Items\Order\Grouped), '/var/www/html/v...', Array) # in /var/www/html/vendor/magento/module-sales/Block/Order/Email/Items/Order/DefaultOrder.php on line 97

@srbarba, thank you for your report.
We've created internal ticket(s) MAGETWO-54633 to track progress on the issue.

Assign to @michielgerritsen

Hi @srbarba the issue has been fixed in 2.2-develop branch and will be available in 2.2.1 release soon

Internal ticket to track issue progress: MAGETWO-81340

This is still an error in Magento 2.2.1

Hi @srbarba. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1282 by @magento-engcom-team in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming patch release.

The error appears again, and it seemed like that the change to fix the issue has been reverted in https://github.com/magento/magento2/commit/62fed32a567bbdf018b0b0c8e9631d44cc48194d

Hi @engcom-Echo. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

Hello @arnoudhgz

Thank you for your report and collaboration!
We are not able to reproduce this issue on the 2.3-develop branch by provided steps.

Testing scenario:

Preconditions:
Grouped Product which consists of two simple products has been created and assigned to a category

Steps to reproduce:

  1. Add Grouped Product to cart.
  2. Place an order with the grouped product.
  3. Go to admin.
  4. Go to Sales → Orders and open the current order with the grouped product.
  5. Go to Invoice and select the "Email Copy of Invoice" checkbox.
    Screenshot from 2019-11-14 17-54-47
  6. Press "Submit Invoice".

  7. Check e-mail

Result:
The Invoice has been created successfully. No errors. An Email is came.
Screenshot from 2019-11-14 17-57-26
Screenshot from 2019-11-14 18-02-14
Screenshot from 2019-11-14 18-02-31
Thank you!

@engcom-Echo you are correct, the issue I found was about the credit memos (the file is almost similar). I will try it out again for credit memos and create a new issue.

Was this page helpful?
0 / 5 - 0 ratings