cancel
Showing results for 
Search instead for 
Did you mean: 

how to call one module model method in another module model . in magento 2 ?

how to call one module model method in another module model . in magento 2 ?

hi guys ,

                 am faceing an issue with calling modal method in another module model.

for example : here am having two files 

 

one : /vendor/subscribepro/subscribepro-magento2-ext/Model/Quote/SubscriptionCreator.php

public function createSubscriptions($quote, $order){

 

}

two : vendor/magento/module-sales/Model/Order/Email/Sender/OrderSender.php

 

Note : i just want to call the createSubscriptions method in two model file.

How can i call that . can anyone guide me ?

 

1 REPLY 1

Re: how to call one module model method in another module model . in magento 2 ?

You have to use this call in your constructor and after creating object just call the function something link this:

In your model file where you want to callcreateSubscriptions() write something like this

 

 

 

use NameSpace/Modulename/Model/Quote/SubscriptionCreator

private $subscriptionCreator;

 

then 

 

public function __construct(    SubscriptionCreator $subscriptionCreator
) {
$this
->subscriptionCreator = $subscriptionCreator;
}

Now in which ever method you want to call  createSubscriptions() you can call like this

 

$this->subscriptionCreator->createSubscriptions($quote,$order)

 

Note: For this module id there is any interface available than use interface.

 

For reference you can  also have a look on this

 

If Issue Solved, Click Kudos/Accept As solutions.