Magento在管理面板中提交订单时出错,但订单成功提交了?

时间:2018-06-02 20:42:57

标签: magento2 magento2.2

我尝试在Sales > Order > Create New Order > Create New Customer内创建订单,然后填写所有内容并添加项目。当我点击Submit Order按钮时出现错误:

We can't get the order instance right now.

屏幕截图:

enter image description here

接下来,当我继续执行管理操作日志时,我发现这样的事情:

enter image description here

接下来经过一些尝试后,我将错误跟踪到以下文件:

vendor/magento/module-sales/Block/Adminhtml/Order/AbstractOrder.php:58-68

代码:

/**
 * Retrieve available order
 *
 * @return Order
 * @throws \Magento\Framework\Exception\LocalizedException
 */
public function getOrder()
{
    if ($this->hasOrder()) {
        return $this->getData('order');
    }
    if ($this->_coreRegistry->registry('current_order')) {
        return $this->_coreRegistry->registry('current_order');
    }
    if ($this->_coreRegistry->registry('order')) {
        return $this->_coreRegistry->registry('order');
    }
    throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t get the order instance right now.'));
}

当我评论抛出新的异常行代码为:

//throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t get the order instance right now.'));

然后再次单击“提交订单”按钮,我收到了一个新错误:

Fatal error: Uncaught Error: Call to a member function getCountryId() on boolean in E:\xampp-php-7\htdocs\m2shop.drberg.com\app\code\Connextar\WickedReports\Observer\OrderPlace.php:29 Stack trace: #0 E:\xampp-php-7\htdocs\m2shop.drberg.com\vendor\magento\framework\Event\Invoker\InvokerDefault.php(72): Connextar\WickedReports\Observer\OrderPlace->execute(Object(Magento\Framework\Event\Observer)) #1 E:\xampp-php-7\htdocs\m2shop.drberg.com\vendor\magento\framework\Event\Invoker\InvokerDefault.php(60): Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod(Object(Connextar\WickedReports\Observer\OrderPlace), Object(Magento\Framework\Event\Observer)) #2 E:\xampp-php-7\htdocs\m2shop.drberg.com\vendor\magento\module-staging\Model\Event\Manager.php(97): Magento\Framework\Event\Invoker\InvokerDefault->dispatch(Array, Object(Magento\Framework\Event\Observer)) #3 E:\xampp-php-7\htdocs\m2shop.drberg.com\generated\code\Magento\Staging\Model\Event\Manager\Proxy.php(95): Magento\Staging\Model\Event\Manager->dispatch('checko in E:\xampp-php-7\htdocs\m2shop.drberg.com\app\code\Connextar\WickedReports\Observer\OrderPlace.php on line 29

文件app\code\Connextar\WickedReports\Observer\OrderPlace.php:29的代码如下:

<?php

namespace Connextar\WickedReports\Observer;

use WickedReports\Api\Item\Order;
use WickedReports\Api\Collection\Orders;

use WickedReports\Api\Item\OrderItem;
use WickedReports\Api\Collection\OrderItems;

use WickedReports\Api\Item\OrderPayment;
use WickedReports\Api\Collection\OrderPayments;

class OrderPlace implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
         $om = \Magento\Framework\App\ObjectManager::getInstance();
         $order = $observer->getEvent()->getOrder();
         $order = $om->create('\Magento\Sales\Model\Order')->load($order->getId());
         $orderId = $order->getIncrementId();
         $createdAt =  $order->getCreatedAt();
         $customerId = $order->getCustomerId();
         $customerEmail = $order->getCustomerEmail();
         $ordertotal = $order->getGrandTotal();
         $customerObj = $om->create('Magento\Customer\Model\Customer')
         ->load($customerId);
         $billingAddress = $customerObj->getDefaultBillingAddress(); 
         $country = $billingAddress->getCountryId();
         $city = $billingAddress->getCity();
         $region = $billingAddress->getRegion();
         $obj = $om->get('Magento\Framework\HTTP\PhpEnvironment\RemoteAddress');
         $ip =  $obj->getRemoteAddress();


         $api = new \WickedReports\WickedReports("A5F8OFxZ6FczbtqETDS0EBcEBC87rarY", true);
         $wporder = new Orders([
             new Order([
                'SourceSystem'   => 'DrBerg_M2',
                'SourceID'       => $orderId,
                'CreateDate'     => $createdAt,
                'timezone'       => 'UTC',
                'ContactID'      => $customerId,
                'ContactEmail'   => $customerEmail,
                'OrderTotal'     => $ordertotal,
                'Country'        => $country,
                'City'           => $city,
                'State'          => $region,
                'SubscriptionID' => '',
                'IP_Address'     => $ip
             ])
         ]);
        $success1=false;
        while ($success1==false) {
         $success1 = $api->addOrders($wporder);
        }

         foreach ($order->getAllItems() as $item) {
             $orderitem = new OrderItems([
                new OrderItem([
                    "SourceSystem" => "DrBerg_M2",
                    "SourceID" => $item->getItemId(),
                    "OrderID" => $orderId,
                    "ProductID" => $item->getProductId(),
                    "Qty" => $item->getQtyOrdered(),
                    "PPU" => $item->getPrice()
                ])
            ]);
            $success2=false;
            while ($success2==false) {
                $success2 = $api->addOrderItems($orderitem);
            }
        }

        $orderpayment = new OrderPayments([
            new OrderPayment([
                "SourceSystem" => "DrBerg_M2",
                "OrderID" =>  $orderId,
                "PaymentDate" => $createdAt,
                "Amount" => $ordertotal,
                "Status" => "APPROVED",
                "timezone" => "UTC"
            ])
        ]);
        $success3=false;
        while ($success3==false) {
            $success3 = $api->addOrderPayments($orderpayment);
        }
    }
}

events.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="catalog_product_save_after">
        <observer name="product_wickedreports" instance="Connextar\WickedReports\Observer\ProductSave" />
    </event>
    <event name="customer_register_success">
        <observer name="customerregister_wickedreports" instance="Connextar\WickedReports\Observer\CustomerRegistration" />
    </event>
    <event name="checkout_submit_all_after">
       <observer name="orderplace_wickedreports" instance="Connextar\WickedReports\Observer\OrderPlace" />
   </event>
</config>

然后我继续使用以下命令禁用自定义编写的模块:

php bin/magento module:disable Connextar_WickedReports

模块已成功禁用。

接下来,当我再次点击Submit Order按钮时,订单已成功创建。我被重定向到订单查看页面。

enter image description here

但是当我取消注释异常错误行时,它会再次开始给出错误。所以我想知道可能是什么问题?

注意:我是Magento的新手,所以非常感谢您的帮助!感谢

更新#1:即使它出错,所以订单似乎正在创建,但订单页面没有被重定向到订单视图页面,而是提供错误。

更新#2:还有一个问题是该网站的行为与我在TEST SERVER上的问题中解释的行为不同。我做了所有的事情,即评论了所有的异常行,并且已经看到模块在TEST SERVER中被禁用了,无论我在TEST SERVER中得到相同的错误,而它在LOCAL上的表现不同服务器。

0 个答案:

没有答案