1

wel i have simple problem i'm trying to load this class in to my own class: https://github.com/picqer/moneybird-php-client/blob/master/src/Picqer/Financials/Moneybird/Moneybird.php

logicaly is to call it in __construct: \Picqer\Financials\Moneybird\Moneybird $moneybird

but the problem is that it requires \Picqer\Financials\Moneybird\Connection to be established beforehand

so how can i use it in my code:

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);

which results in fault: PHP Fatal error: Uncaught Error: Function name must be a string...

wel one way to fix it, is to add method setConnection in that class and call it, but the problem that it's being downloaded from repository by composer so if i want to use my module in another installation i will have to do same steps.

any other workaround ?

added construct of moneybird file:

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

so it will not lead to confusions and unnecessary questions.

  • Where does the given code throw that error message? – Nico Haase May 03 '19 at 09:28
  • $moneybird = $this->_moneybird($this->_connection); this gives error – Naberd Zendi May 03 '19 at 09:32
  • $this->_connection is an object, you are not calling any method of class _moneybird ?? does that make sense ? – Rakesh Jakhar May 03 '19 at 09:42
  • you can't pass an instance of a class as an argument of the other instance. – fmsthird May 03 '19 at 09:44
  • wel this is what it accepts: /** * Moneybird constructor. * @param \Picqer\Financials\Moneybird\Connection $connection */ public function __construct(Connection $connection) { $this->connection = $connection; } hence the question is there a way to load this class with param or only by adding a method there ? – Naberd Zendi May 03 '19 at 09:51
  • 1
    If you want to call a constructor, why don't you do so? Obviously, `$this->_moneybird` is an instantiated class – Nico Haase May 03 '19 at 09:56
  • That's why i'm asking how i can call the class construct with parameters inside my function. normal php way is: new \Picqer\Financials\Moneybird\Moneybird($this->_connection); what is correct magento way ? – Naberd Zendi May 03 '19 at 11:09

0 Answers0