How to override vendor/magento/module-quote/Model/Quote.php in Magento2.

Any help would be appreciated.

  • Do you need to overide the entire file? or only particular function?
    – aravind
    Jan 28, 2020 at 10:38
  • Only particular function
    – Amy
    Jan 28, 2020 at 10:42
  • which function?
    – aravind
    Jan 28, 2020 at 10:45
  • public function isVirtual()
    – Amy
    Jan 28, 2020 at 10:52

1 Answer 1


You can use preference to override the whole class

you below type of code in your module's etc/di.xml if only want to use for front-end then etc/frontend/di.xml or if only for admin then etc/adminhtml/di.xml

<preference for="Magento\Quote\Model\Quote" type="Vendor\Custommodule\Rewrite\Magento\Quote\Model\Quote"/> 

or if you only want to modify the reference class public method then best to use plugin and add below code in your module's etc/di.xml

<type name="Magento\Quote\Model\Quote">
    <plugin disabled="false" name="Vendor_Custommodule_Plugin_Magento_Quote_Model_Quote" sortOrder="10" type="Vendor\Custommodule\Plugin\Magento\Quote\Model\Quote"/>

and in your plugin class use below type of code and use after method to modify the result of reference class method(or before plugin if you only want to modify the input arguments of reference method)


namespace Vendor\Custommodule\Plugin\Magento\Quote\Model;

class Quote

    public function afterIsVirtual(
        \Magento\Quote\Model\Quote $subject,
    ) {
        //Your plugin code
        return $result;

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.