1

How to access one Model data functions in another model inside function in magento 2

Below is my override function Model NameSpace\modulename\Model\Rewrite\Quote

 public function createEmptyCart()
        {


            $storeId = $this->storeManager->getStore()->getStoreId();
            $quote = $this->createAnonymousCart($storeId);

            $quote->setBillingAddress($this->quoteAddressFactory->create());
            $quote->setShippingAddress($this->quoteAddressFactory->create());

            try {
                $this->quoteRepository->save($quote);
            } catch (\Exception $e) {
                throw new CouldNotSaveException(__('Cannot create quote'));
            }
            //return $quote->getId();
            // die('helloss');
            return parent::createEmptyCart();

        }

I want to get that return functionality in below model

NameSpace\modulename\Model

public function customcart($point1, $point2) {
//here i want to get that above function quote Data how to get 
}

Below is my Constructor

 public function __construct(PointInterfaceFactory $pointFactory) {
        $this->pointFactory = $pointFactory;
    }
2

you function is inside some class name inside quote Folder you have to add that class name then the below code will work fine

public function __construct(\NameSpace\modulename\Model\Rewrite\Quote\QuoteManagement  $quoteObj){
  $this->quoteObj = $quoteObj;
}

public function customcart($point1, $point2) {
     $getfunctions =   $this->quoteObj->createEmptyCart();
}
  • yes class is class QuoteManagement – magento12345 Oct 19 '16 at 6:26
  • i updated my answer try now – Brad Hodge Oct 19 '16 at 6:28
1

inside this file, NameSpace\modulename\Model you can get another model function using constuct method,

public function __construct(\NameSpace\modulename\Model\Rewrite\Quote $quoteObj){
  $this->quoteObj = $quoteObj;
}

public function customcart($point1, $point2) {
     $getfunctions =   $this->quoteObj->createEmptyCart();
}
  • i updated my question with my current constructor please let me know how to do it now because i am using that constructor – magento12345 Oct 19 '16 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.