gpt4 book ai didi

Magento 2 orderFactory 在供应商目录中找不到

转载 作者:行者123 更新时间:2023-12-02 02:05:45 28 4
gpt4 key购买 nike

我在 docker 容器内使用 Magento 2.3.4 作为支付网关扩展。首先,这是受影响的代码:

<?php

namespace Magento\PGM\Block;

use Magento\AdminNotification\Model\Inbox;
use Magento\Checkout\Model\Session;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\Response\Http;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Sales\Api\Data\OrderAddressInterface;
use Magento\Sales\Model\Order\Payment\Transaction;
use Magento\Sales\Model\Order\Payment\Transaction\Builder as TransactionBuilder;
use Magento\Sales\Model\OrderFactory;
use Magento\Store\Model\ScopeInterface;
use Magento\PGM\Logger\Logger;


class Main extends Template
{
protected $_objectmanager;
protected $checkoutSession;
protected $urlBuilder;
protected $response;
protected $config;
protected $messageManager;
protected $transactionBuilder;
protected $inbox;
private $logger;
private $orderFactory;

public function __construct(Context $context, Session $checkoutSession, OrderFactory $orderFactory = null, Logger $logger, Http $response, TransactionBuilder $tb, Inbox $inbox)
{
$this->checkoutSession = $checkoutSession;
$this->orderFactory = $orderFactory ?: ObjectManager::getInstance()->get(OrderFactory::class);
$this->response = $response;
$this->config = $context->getScopeConfig();
$this->transactionBuilder = $tb;
$this->logger = $logger;
$this->inbox = $inbox;

$this->urlBuilder = ObjectManager::getInstance()
->get('Magento\Framework\UrlInterface');
parent::__construct($context);
}

public function getParentId()
{
return $this->getData(OrderAddressInterface::PARENT_ID);
}

protected function _prepareLayout()
{
$method_data = array();
$order = $this->orderFactory->create()->load($this->getParentId());
if ($order) {
$payment = $order->getPayment();
// The error is thrown here (" Call to a member function setTransactionId() on null")
$payment->setTransactionId("-1");
...
$payment->save();
$order->save();

...
}

private function setApiData($order, $testmode, $instance)
{
...
}
}

我收到此错误:

Call to a member function setTransactionId() on null

我认为这只是一个症状。订单对象未创建,我的 IDE 将 $order->getPayment() 方法标记为根本找不到。

代码本身应该不是问题,但文件夹“Sales\Model”不包含 orderFactory.php 文件。文件是否丢失或已弃用?有几个模块使用此文件并创建这样的订单,例如 Paypal PGM ,并使用 OrderFactory.php 文件。

最佳答案

据我所知,Factory 类名称是 Model 类的名称,并附加了 Factory 单词。因此,对于我们的示例,我们将有 TopicFactory 类。您不得创建此类。 Magento 将为您创建它。每当 Magento 的对象管理器遇到以“Factory”结尾的类名时,如果该类尚不存在,它将自动在 var/Generation 文件夹中生成 Factory 类。您将在

中看到工厂类
ROOT/generated/code/<vendor_name>/<module_name>/Model/OrderFactory.php

因此,第一步您应该转到文件夹 Generation 来查看该类是否存在。

如果它不存在,我认为您面临权限问题,magento 无法在 Generation 文件夹中生成(无法创建文件或文件夹)Factory 类。

关于Magento 2 orderFactory 在供应商目录中找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60705403/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com