How to use Mage::getModel() on Magento 2?












2















I need to convert my following Mage::getModel() from Magento1 to Magento2



$cart_api = Mage::getModel('checkout/cart_api');
$quoteId = $cart_api->create($storeObject->getStoreId());
$quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($quoteId);

$product = Mage::getModel('catalog/product');

$customer = Mage::getModel('customer/customer');
$customerAddress = Mage::getModel('customer/address');

$convertQuoteObj = Mage::getModel('sales/convert_quote');

$storeObject = Mage::getModel('core/store')->load(1);


So anyone let me know the correct method for Magento2.










share|improve this question














bumped to the homepage by Community 22 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    2















    I need to convert my following Mage::getModel() from Magento1 to Magento2



    $cart_api = Mage::getModel('checkout/cart_api');
    $quoteId = $cart_api->create($storeObject->getStoreId());
    $quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($quoteId);

    $product = Mage::getModel('catalog/product');

    $customer = Mage::getModel('customer/customer');
    $customerAddress = Mage::getModel('customer/address');

    $convertQuoteObj = Mage::getModel('sales/convert_quote');

    $storeObject = Mage::getModel('core/store')->load(1);


    So anyone let me know the correct method for Magento2.










    share|improve this question














    bumped to the homepage by Community 22 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      2












      2








      2








      I need to convert my following Mage::getModel() from Magento1 to Magento2



      $cart_api = Mage::getModel('checkout/cart_api');
      $quoteId = $cart_api->create($storeObject->getStoreId());
      $quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($quoteId);

      $product = Mage::getModel('catalog/product');

      $customer = Mage::getModel('customer/customer');
      $customerAddress = Mage::getModel('customer/address');

      $convertQuoteObj = Mage::getModel('sales/convert_quote');

      $storeObject = Mage::getModel('core/store')->load(1);


      So anyone let me know the correct method for Magento2.










      share|improve this question














      I need to convert my following Mage::getModel() from Magento1 to Magento2



      $cart_api = Mage::getModel('checkout/cart_api');
      $quoteId = $cart_api->create($storeObject->getStoreId());
      $quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($quoteId);

      $product = Mage::getModel('catalog/product');

      $customer = Mage::getModel('customer/customer');
      $customerAddress = Mage::getModel('customer/address');

      $convertQuoteObj = Mage::getModel('sales/convert_quote');

      $storeObject = Mage::getModel('core/store')->load(1);


      So anyone let me know the correct method for Magento2.







      magento2 magento2.2 magento2.2.4






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 11 '18 at 7:28









      MeskMesk

      627




      627





      bumped to the homepage by Community 22 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 22 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          2 Answers
          2






          active

          oldest

          votes


















          0














          For Mage::getModel magento1 you need to use the below code for Magento 2:



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $model = $objectManager->create('NamespaceModulenameModelModulename');


          For Mage::getSingleton you need to use:



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $model = $objectManager->get('NamespaceModulenameModelModulename');





          share|improve this answer
























          • I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

            – Mesk
            Jul 11 '18 at 9:06











          • How can I use it in my Custom class?

            – Mesk
            Jul 11 '18 at 9:33











          • @Selvamesk, Check the link in my answer!

            – Pallavi
            Jul 11 '18 at 11:46











          • @Pallavi How can we get customer, product details in my Custom module's Index Controller?

            – Mesk
            Jul 12 '18 at 7:01











          • @Selvamesk, why you need controller for that? you can create model or helper for fetching that data. You will get so many examples in this site for fetching customer/product details. Updated My answer with helper example.

            – Pallavi
            Jul 12 '18 at 11:33



















          0














          Override constructor in your Model class and add your model class as dependency.



          protected $_modelObj;
          public function __construct(
          ...
          VendorExampleModelModel $modelObj,
          ...
          ) {
          ...
          $this->modelObj = $modelObj;
          ...
          }

          function someMetod() {
          $model = $this->modelObj->create();
          }


          There are thousands of examples you can find in google for same. Also you can check core files how it is implemented.



          Adding here one specific answer for your question:



          protected $_quoteFactory;

          public function __construct(
          ...
          MagentoQuoteModelQuoteFactory $quoteFactory
          ) {
          $this->_quoteFactory = $quoteFactory;
          parent::__construct(...);
          }


          Then in your class you can do:



          $this->_quoteFactory->create()->loadByIdWithoutStore($quoteId);


          For using it in your custom class, check this link!



          Hope this helps!



          <?php

          namespace Yourcompany<yourmodule>Helper {

          /**
          * Customer data helper
          */
          class Data extends MagentoFrameworkAppHelperAbstractHelper
          {
          protected $customerRepository;

          public function __construct(
          MagentoCustomerApiCustomerRepositoryInterfaceFactory $customerRepositoryFactory) {
          $this->customerRepository = $customerRepositoryFactory->create();
          }

          public LoadCustomerById($customerId) {
          $customer = $this->customerRepository->getById($customerId);
          return $customer;
          }

          }


          Same way you can add functions for getting product detail and use these in your module controller. Hope this helps!






          share|improve this answer


























          • @Sukumar, direct use of $objectManager is not accepted as standard way of implementation. It should be done via class constructor.

            – Pallavi
            Jul 11 '18 at 7:40











          • I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

            – Mesk
            Jul 11 '18 at 9:06











          • @Pallavi Mage::getModel is accepted? I am only saying what are the code for getModel and getSingleton in magento2. So Please read the question carefully as I also know use of objectManager anywhere directly is not good practice.

            – Sukumar Gorai
            Jul 11 '18 at 9:10













          • How can I use it in my Custom class?

            – Mesk
            Jul 11 '18 at 9:30











          • @SukumarGorai, My comment was not intended to offend you in any ways. However If you felt so, I apologize. My only intention was to tell the correct way of implementation, that's it. hope you understand!

            – Pallavi
            Jul 11 '18 at 11:43











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f233086%2fhow-to-use-magegetmodel-on-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          For Mage::getModel magento1 you need to use the below code for Magento 2:



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $model = $objectManager->create('NamespaceModulenameModelModulename');


          For Mage::getSingleton you need to use:



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $model = $objectManager->get('NamespaceModulenameModelModulename');





          share|improve this answer
























          • I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

            – Mesk
            Jul 11 '18 at 9:06











          • How can I use it in my Custom class?

            – Mesk
            Jul 11 '18 at 9:33











          • @Selvamesk, Check the link in my answer!

            – Pallavi
            Jul 11 '18 at 11:46











          • @Pallavi How can we get customer, product details in my Custom module's Index Controller?

            – Mesk
            Jul 12 '18 at 7:01











          • @Selvamesk, why you need controller for that? you can create model or helper for fetching that data. You will get so many examples in this site for fetching customer/product details. Updated My answer with helper example.

            – Pallavi
            Jul 12 '18 at 11:33
















          0














          For Mage::getModel magento1 you need to use the below code for Magento 2:



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $model = $objectManager->create('NamespaceModulenameModelModulename');


          For Mage::getSingleton you need to use:



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $model = $objectManager->get('NamespaceModulenameModelModulename');





          share|improve this answer
























          • I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

            – Mesk
            Jul 11 '18 at 9:06











          • How can I use it in my Custom class?

            – Mesk
            Jul 11 '18 at 9:33











          • @Selvamesk, Check the link in my answer!

            – Pallavi
            Jul 11 '18 at 11:46











          • @Pallavi How can we get customer, product details in my Custom module's Index Controller?

            – Mesk
            Jul 12 '18 at 7:01











          • @Selvamesk, why you need controller for that? you can create model or helper for fetching that data. You will get so many examples in this site for fetching customer/product details. Updated My answer with helper example.

            – Pallavi
            Jul 12 '18 at 11:33














          0












          0








          0







          For Mage::getModel magento1 you need to use the below code for Magento 2:



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $model = $objectManager->create('NamespaceModulenameModelModulename');


          For Mage::getSingleton you need to use:



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $model = $objectManager->get('NamespaceModulenameModelModulename');





          share|improve this answer













          For Mage::getModel magento1 you need to use the below code for Magento 2:



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $model = $objectManager->create('NamespaceModulenameModelModulename');


          For Mage::getSingleton you need to use:



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $model = $objectManager->get('NamespaceModulenameModelModulename');






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 11 '18 at 7:36









          Sukumar GoraiSukumar Gorai

          6,8453629




          6,8453629













          • I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

            – Mesk
            Jul 11 '18 at 9:06











          • How can I use it in my Custom class?

            – Mesk
            Jul 11 '18 at 9:33











          • @Selvamesk, Check the link in my answer!

            – Pallavi
            Jul 11 '18 at 11:46











          • @Pallavi How can we get customer, product details in my Custom module's Index Controller?

            – Mesk
            Jul 12 '18 at 7:01











          • @Selvamesk, why you need controller for that? you can create model or helper for fetching that data. You will get so many examples in this site for fetching customer/product details. Updated My answer with helper example.

            – Pallavi
            Jul 12 '18 at 11:33



















          • I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

            – Mesk
            Jul 11 '18 at 9:06











          • How can I use it in my Custom class?

            – Mesk
            Jul 11 '18 at 9:33











          • @Selvamesk, Check the link in my answer!

            – Pallavi
            Jul 11 '18 at 11:46











          • @Pallavi How can we get customer, product details in my Custom module's Index Controller?

            – Mesk
            Jul 12 '18 at 7:01











          • @Selvamesk, why you need controller for that? you can create model or helper for fetching that data. You will get so many examples in this site for fetching customer/product details. Updated My answer with helper example.

            – Pallavi
            Jul 12 '18 at 11:33

















          I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

          – Mesk
          Jul 11 '18 at 9:06





          I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

          – Mesk
          Jul 11 '18 at 9:06













          How can I use it in my Custom class?

          – Mesk
          Jul 11 '18 at 9:33





          How can I use it in my Custom class?

          – Mesk
          Jul 11 '18 at 9:33













          @Selvamesk, Check the link in my answer!

          – Pallavi
          Jul 11 '18 at 11:46





          @Selvamesk, Check the link in my answer!

          – Pallavi
          Jul 11 '18 at 11:46













          @Pallavi How can we get customer, product details in my Custom module's Index Controller?

          – Mesk
          Jul 12 '18 at 7:01





          @Pallavi How can we get customer, product details in my Custom module's Index Controller?

          – Mesk
          Jul 12 '18 at 7:01













          @Selvamesk, why you need controller for that? you can create model or helper for fetching that data. You will get so many examples in this site for fetching customer/product details. Updated My answer with helper example.

          – Pallavi
          Jul 12 '18 at 11:33





          @Selvamesk, why you need controller for that? you can create model or helper for fetching that data. You will get so many examples in this site for fetching customer/product details. Updated My answer with helper example.

          – Pallavi
          Jul 12 '18 at 11:33













          0














          Override constructor in your Model class and add your model class as dependency.



          protected $_modelObj;
          public function __construct(
          ...
          VendorExampleModelModel $modelObj,
          ...
          ) {
          ...
          $this->modelObj = $modelObj;
          ...
          }

          function someMetod() {
          $model = $this->modelObj->create();
          }


          There are thousands of examples you can find in google for same. Also you can check core files how it is implemented.



          Adding here one specific answer for your question:



          protected $_quoteFactory;

          public function __construct(
          ...
          MagentoQuoteModelQuoteFactory $quoteFactory
          ) {
          $this->_quoteFactory = $quoteFactory;
          parent::__construct(...);
          }


          Then in your class you can do:



          $this->_quoteFactory->create()->loadByIdWithoutStore($quoteId);


          For using it in your custom class, check this link!



          Hope this helps!



          <?php

          namespace Yourcompany<yourmodule>Helper {

          /**
          * Customer data helper
          */
          class Data extends MagentoFrameworkAppHelperAbstractHelper
          {
          protected $customerRepository;

          public function __construct(
          MagentoCustomerApiCustomerRepositoryInterfaceFactory $customerRepositoryFactory) {
          $this->customerRepository = $customerRepositoryFactory->create();
          }

          public LoadCustomerById($customerId) {
          $customer = $this->customerRepository->getById($customerId);
          return $customer;
          }

          }


          Same way you can add functions for getting product detail and use these in your module controller. Hope this helps!






          share|improve this answer


























          • @Sukumar, direct use of $objectManager is not accepted as standard way of implementation. It should be done via class constructor.

            – Pallavi
            Jul 11 '18 at 7:40











          • I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

            – Mesk
            Jul 11 '18 at 9:06











          • @Pallavi Mage::getModel is accepted? I am only saying what are the code for getModel and getSingleton in magento2. So Please read the question carefully as I also know use of objectManager anywhere directly is not good practice.

            – Sukumar Gorai
            Jul 11 '18 at 9:10













          • How can I use it in my Custom class?

            – Mesk
            Jul 11 '18 at 9:30











          • @SukumarGorai, My comment was not intended to offend you in any ways. However If you felt so, I apologize. My only intention was to tell the correct way of implementation, that's it. hope you understand!

            – Pallavi
            Jul 11 '18 at 11:43
















          0














          Override constructor in your Model class and add your model class as dependency.



          protected $_modelObj;
          public function __construct(
          ...
          VendorExampleModelModel $modelObj,
          ...
          ) {
          ...
          $this->modelObj = $modelObj;
          ...
          }

          function someMetod() {
          $model = $this->modelObj->create();
          }


          There are thousands of examples you can find in google for same. Also you can check core files how it is implemented.



          Adding here one specific answer for your question:



          protected $_quoteFactory;

          public function __construct(
          ...
          MagentoQuoteModelQuoteFactory $quoteFactory
          ) {
          $this->_quoteFactory = $quoteFactory;
          parent::__construct(...);
          }


          Then in your class you can do:



          $this->_quoteFactory->create()->loadByIdWithoutStore($quoteId);


          For using it in your custom class, check this link!



          Hope this helps!



          <?php

          namespace Yourcompany<yourmodule>Helper {

          /**
          * Customer data helper
          */
          class Data extends MagentoFrameworkAppHelperAbstractHelper
          {
          protected $customerRepository;

          public function __construct(
          MagentoCustomerApiCustomerRepositoryInterfaceFactory $customerRepositoryFactory) {
          $this->customerRepository = $customerRepositoryFactory->create();
          }

          public LoadCustomerById($customerId) {
          $customer = $this->customerRepository->getById($customerId);
          return $customer;
          }

          }


          Same way you can add functions for getting product detail and use these in your module controller. Hope this helps!






          share|improve this answer


























          • @Sukumar, direct use of $objectManager is not accepted as standard way of implementation. It should be done via class constructor.

            – Pallavi
            Jul 11 '18 at 7:40











          • I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

            – Mesk
            Jul 11 '18 at 9:06











          • @Pallavi Mage::getModel is accepted? I am only saying what are the code for getModel and getSingleton in magento2. So Please read the question carefully as I also know use of objectManager anywhere directly is not good practice.

            – Sukumar Gorai
            Jul 11 '18 at 9:10













          • How can I use it in my Custom class?

            – Mesk
            Jul 11 '18 at 9:30











          • @SukumarGorai, My comment was not intended to offend you in any ways. However If you felt so, I apologize. My only intention was to tell the correct way of implementation, that's it. hope you understand!

            – Pallavi
            Jul 11 '18 at 11:43














          0












          0








          0







          Override constructor in your Model class and add your model class as dependency.



          protected $_modelObj;
          public function __construct(
          ...
          VendorExampleModelModel $modelObj,
          ...
          ) {
          ...
          $this->modelObj = $modelObj;
          ...
          }

          function someMetod() {
          $model = $this->modelObj->create();
          }


          There are thousands of examples you can find in google for same. Also you can check core files how it is implemented.



          Adding here one specific answer for your question:



          protected $_quoteFactory;

          public function __construct(
          ...
          MagentoQuoteModelQuoteFactory $quoteFactory
          ) {
          $this->_quoteFactory = $quoteFactory;
          parent::__construct(...);
          }


          Then in your class you can do:



          $this->_quoteFactory->create()->loadByIdWithoutStore($quoteId);


          For using it in your custom class, check this link!



          Hope this helps!



          <?php

          namespace Yourcompany<yourmodule>Helper {

          /**
          * Customer data helper
          */
          class Data extends MagentoFrameworkAppHelperAbstractHelper
          {
          protected $customerRepository;

          public function __construct(
          MagentoCustomerApiCustomerRepositoryInterfaceFactory $customerRepositoryFactory) {
          $this->customerRepository = $customerRepositoryFactory->create();
          }

          public LoadCustomerById($customerId) {
          $customer = $this->customerRepository->getById($customerId);
          return $customer;
          }

          }


          Same way you can add functions for getting product detail and use these in your module controller. Hope this helps!






          share|improve this answer















          Override constructor in your Model class and add your model class as dependency.



          protected $_modelObj;
          public function __construct(
          ...
          VendorExampleModelModel $modelObj,
          ...
          ) {
          ...
          $this->modelObj = $modelObj;
          ...
          }

          function someMetod() {
          $model = $this->modelObj->create();
          }


          There are thousands of examples you can find in google for same. Also you can check core files how it is implemented.



          Adding here one specific answer for your question:



          protected $_quoteFactory;

          public function __construct(
          ...
          MagentoQuoteModelQuoteFactory $quoteFactory
          ) {
          $this->_quoteFactory = $quoteFactory;
          parent::__construct(...);
          }


          Then in your class you can do:



          $this->_quoteFactory->create()->loadByIdWithoutStore($quoteId);


          For using it in your custom class, check this link!



          Hope this helps!



          <?php

          namespace Yourcompany<yourmodule>Helper {

          /**
          * Customer data helper
          */
          class Data extends MagentoFrameworkAppHelperAbstractHelper
          {
          protected $customerRepository;

          public function __construct(
          MagentoCustomerApiCustomerRepositoryInterfaceFactory $customerRepositoryFactory) {
          $this->customerRepository = $customerRepositoryFactory->create();
          }

          public LoadCustomerById($customerId) {
          $customer = $this->customerRepository->getById($customerId);
          return $customer;
          }

          }


          Same way you can add functions for getting product detail and use these in your module controller. Hope this helps!







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jul 12 '18 at 11:35

























          answered Jul 11 '18 at 7:35









          PallaviPallavi

          30918




          30918













          • @Sukumar, direct use of $objectManager is not accepted as standard way of implementation. It should be done via class constructor.

            – Pallavi
            Jul 11 '18 at 7:40











          • I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

            – Mesk
            Jul 11 '18 at 9:06











          • @Pallavi Mage::getModel is accepted? I am only saying what are the code for getModel and getSingleton in magento2. So Please read the question carefully as I also know use of objectManager anywhere directly is not good practice.

            – Sukumar Gorai
            Jul 11 '18 at 9:10













          • How can I use it in my Custom class?

            – Mesk
            Jul 11 '18 at 9:30











          • @SukumarGorai, My comment was not intended to offend you in any ways. However If you felt so, I apologize. My only intention was to tell the correct way of implementation, that's it. hope you understand!

            – Pallavi
            Jul 11 '18 at 11:43



















          • @Sukumar, direct use of $objectManager is not accepted as standard way of implementation. It should be done via class constructor.

            – Pallavi
            Jul 11 '18 at 7:40











          • I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

            – Mesk
            Jul 11 '18 at 9:06











          • @Pallavi Mage::getModel is accepted? I am only saying what are the code for getModel and getSingleton in magento2. So Please read the question carefully as I also know use of objectManager anywhere directly is not good practice.

            – Sukumar Gorai
            Jul 11 '18 at 9:10













          • How can I use it in my Custom class?

            – Mesk
            Jul 11 '18 at 9:30











          • @SukumarGorai, My comment was not intended to offend you in any ways. However If you felt so, I apologize. My only intention was to tell the correct way of implementation, that's it. hope you understand!

            – Pallavi
            Jul 11 '18 at 11:43

















          @Sukumar, direct use of $objectManager is not accepted as standard way of implementation. It should be done via class constructor.

          – Pallavi
          Jul 11 '18 at 7:40





          @Sukumar, direct use of $objectManager is not accepted as standard way of implementation. It should be done via class constructor.

          – Pallavi
          Jul 11 '18 at 7:40













          I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

          – Mesk
          Jul 11 '18 at 9:06





          I need to get all the above values in my custom php file placed in magento 2 root. So let me know how to do this for my above code?

          – Mesk
          Jul 11 '18 at 9:06













          @Pallavi Mage::getModel is accepted? I am only saying what are the code for getModel and getSingleton in magento2. So Please read the question carefully as I also know use of objectManager anywhere directly is not good practice.

          – Sukumar Gorai
          Jul 11 '18 at 9:10







          @Pallavi Mage::getModel is accepted? I am only saying what are the code for getModel and getSingleton in magento2. So Please read the question carefully as I also know use of objectManager anywhere directly is not good practice.

          – Sukumar Gorai
          Jul 11 '18 at 9:10















          How can I use it in my Custom class?

          – Mesk
          Jul 11 '18 at 9:30





          How can I use it in my Custom class?

          – Mesk
          Jul 11 '18 at 9:30













          @SukumarGorai, My comment was not intended to offend you in any ways. However If you felt so, I apologize. My only intention was to tell the correct way of implementation, that's it. hope you understand!

          – Pallavi
          Jul 11 '18 at 11:43





          @SukumarGorai, My comment was not intended to offend you in any ways. However If you felt so, I apologize. My only intention was to tell the correct way of implementation, that's it. hope you understand!

          – Pallavi
          Jul 11 '18 at 11:43


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f233086%2fhow-to-use-magegetmodel-on-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What other Star Trek series did the main TNG cast show up in?

          Berlina muro

          Berlina aerponto