magento2: Error While send Invoice with Grouped Products

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

  1. Invoice the order.
  2. Send the copy email to client.

Actual result

  1. Order is invoiced.
  2. 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/

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 23 (11 by maintainers)

Commits related to this issue

Most upvoted comments

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

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

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