带参数的magento 2负载等级

时间:2019-05-03 09:22:53

标签: php magento2

请问我有简单的问题 我正在尝试将此课程加载到我自己的课程中:https://github.com/picqer/moneybird-php-client/blob/master/src/Picqer/Financials/Moneybird/Moneybird.php

逻辑上是在__construct中调用它: \ Picqer \ Financials \ Moneybird \ Moneybird $ moneybird

但是问题在于它需要事先建立\ Picqer \ Financials \ Moneybird \ Connection

所以我该如何在我的代码中使用它?

class OnepageControllerSuccessAction implements \Magento\Framework\Event\ObserverInterface
{
    protected $_order;
    protected $_connection;
    protected $_invoiceFactory;
    protected $_moneybird;

    public function __construct(
        \Magento\Sales\Api\Data\OrderInterface $order,
        \Picqer\Financials\Moneybird\Connection $connection,
        \Picqer\Financials\Moneybird\Moneybird $moneybird,
        \Wemessage\Moneybird\Model\InvoiceFactory $invoiceFactory
    ){
        $this->_order = $order;
        $this->_connection = $connection;
        $this->_invoiceFactory = $invoiceFactory;
        $this->_moneybird = $moneybird;
    }
...
public function execute(
    \Magento\Framework\Event\Observer $observer
) {

    $orderids = $observer->getEvent()->getOrderIds();
    foreach($orderids as $orderid){
        $order = $this->_order->load($orderid);
        $this->_connection->setRedirectUrl('');
        ...
        // connection has been established and now we need to pass it to the moneybird
        $moneybird = $this->_moneybird($this->_connection);

这将导致错误:PHP致命错误:未捕获的错误:函数名称必须是字符串...

修复它的一种方法是在该类中添加方法setConnection并调用它,但是这个问题是由作曲家从存储库下载的,因此如果我想在另一个安装中使用我的模块,我将必须做同样的事情步骤。

还有其他解决方法吗?

添加了moneybird文件的构造:

/**
     * Moneybird constructor.
     * @param \Picqer\Financials\Moneybird\Connection $connection
     */
    public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }

因此不会引起混乱和不必要的问题。

0 个答案:

没有答案