How to override vendor/magento/module-quote/Model/Quote.php in Magento2.
Any help would be appreciated.
How to override vendor/magento/module-quote/Model/Quote.php in Magento2.
Any help would be appreciated.
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"/>
</type>
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)
<?php
namespace Vendor\Custommodule\Plugin\Magento\Quote\Model;
class Quote
{
public function afterIsVirtual(
\Magento\Quote\Model\Quote $subject,
$result
) {
//Your plugin code
return $result;
}
}