5

In checkout section i try to place an order using a credit card payment method, my cc data is valid, but when i click place order button the page stuck at loading circle gif, and when i inspect network to find the error i got this error response from payment-information :

Fatal error: Call to a member function formatPrice() on null in /home/project/public_html/vendor/magento/module-weee/view/frontend/templates/email/items/price/row.phtml on line 25

{"messages":{"error":[{"code":500,"message":"Server internal error. See details in report api/1309099902234"}]}}

i try to open the row.phtml file at row 25, i've found this line of code:

  <?= /* @escapeNotVerified */  $_order->formatPrice($block->getRowDisplayPriceExclTax()) ?>

when i try to print the $block->getRowDisplayPriceExclTax() it prints 25.5, and when i try to comment the code like this:

<?//= /* @escapeNotVerified */  $_order->formatPrice($block->getRowDisplayPriceExclTax()) ?>

place an order is working just fine and sending email

1
  • did you get solution of above error? Oct 9, 2019 at 12:55

2 Answers 2

3

You are facing this error while you are using custom module so the line which you commented is formatting price only.

So instead of commenting, you can replace this line:

<?= /* @escapeNotVerified */  $_order->formatPrice($block->getRowDisplayPriceExclTax()) ?>

with this below code:

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); 
$formattedPrice = $priceHelper->currency($block->getRowDisplayPriceExclTax(), true, false);
echo $formattedPrice;?>

Hope this was useful

3

Ran into this issue recently as well using the Xtento_AdvancedOrderStatus module.

In our case, Xtento_AdvancedOrderStatus allows emails to be triggered based on order status changes, but the plugin they've added triggers an email too soon for new orders. Because we customized the email to display line items for the order, and the fact that a new order hasn't finished saving, the line items of the order haven't had the order associated to them yet, causing the error.

If you are/were using a custom module that does something similar, that might be the cause of the error. I'm going to document some of my findings in case it gives insight to you or anyone else stumbling across this. In general though, this error comes from the line items of the order not having the order associated to them at the time the transactional email wants to send:

New Orders

After an order is saved, Magento\Sales\Model\ResourceModel\Order\Relation::processRelation() is used to save relations to the order (Order Items, Payment, Status Histories, etc). This is where each of an order's line items get the sales_order.entity_id and Magento\Sales\Model\Order associated to them:

<?php

namespace Magento\Sales\Model\ResourceModel\Order;

class Relation implements RelationInterface
{
    ...

    /**
     * Save relations for Order
     *
     * @param \Magento\Framework\Model\AbstractModel $object
     * @return void
     * @throws \Exception
     */
    public function processRelation(\Magento\Framework\Model\AbstractModel $object)
    {
        /** @var \Magento\Sales\Model\Order $object */

        if (null !== $object->getItems()) {
            /** @var \Magento\Sales\Model\Order\Item $item */
            foreach ($object->getItems() as $item) {
                $item->setOrderId($object->getId());
                $item->setOrder($object);
                $this->orderItemRepository->save($item);
            }
        }

        ...other order relations
    }

    ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.