Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在供应商目录中找不到Magento 2 orderFactory_Magento_Magento2 - Fatal编程技术网

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

在供应商目录中找不到Magento 2 orderFactory,magento,magento2,Magento,Magento2,我正在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;

我正在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)
    {
       ...
    }
}


据我所知,工厂类名称是模型类的名称,并附加工厂词。因此,对于我们的示例,我们将使用TopicFactory类。您不能创建此类。Magento将为您创建它。每当Magento的对象管理器遇到以单词“Factory”结尾的类名时,如果该类不存在,它将在var/generation文件夹中自动生成Factory类。您将在中看到factory类

ROOT/generated/code/<vendor_name>/<module_name>/Model/OrderFactory.php
ROOT/generated/code///Model/OrderFactory.php
因此,第一步应该转到文件夹生成,查看类是否存在


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

Hi orderFactory没有以DB为单位的付款,因此您无法使用它来获得付款。您可以尝试以下方法:

use Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\CollectionFactory; 
protected $transactions;
public function __constructor(CollectionFactory $transactions)
{
    $this->transactions = $transactions;
}
在您的方法中:

$transactions = $this->transactions->create()->addOrderIdFilter($orderId);
...
$transactions->setTransactionId("-1");`

这似乎是问题所在,我没有检查var文件夹,但它几乎是空的(只有page_缓存在那里)。我试图根据magento 2文档设置权限,但没有成功。我将尝试重新安装我的magento商店并更新此问题。谢谢你的时间和努力!很抱歉,我给出了错误的路径,根目录/generated/code///ClassFactory.php中的工厂类,因为您在magento 2.3.4文件夹
generated/code/magento
中只包含框架文件夹,所以问题似乎出现在所有生成的代码中?是的。因为每个工厂类都将生成并位于generated/code下。感谢您的回答,在我重新安装magento 2后,我可以尝试一下。