Skip to main content
11 votes

How can i override the PriceCurrencyInterface in Magento 2?

Basically, You need to override dependency file of priceCurrency interface by below way to change precision of price. You can set precision of price using below way, Just need to create a simple ...
Rakesh Jesadiya's user avatar
8 votes

I want to override vendor\magento\module-email\Model\AbstractTemplate.php

You cannot override that class. Magento\Email\Model\AbstractTemplate is an abstract class and it never gets instantiated. Your code is correct but you don't see your method being called because your ...
Marius's user avatar
  • 199k
7 votes
Accepted

Overriding private method of Model file in Magento 2

Private function is not override: so you have better option that you can override getConfig method of Magento\Checkout\Model\DefaultConfigProvider and use di.xml <?xml version="1.0"?>...
Rutvee Sojitra's user avatar
6 votes

How can i override the PriceCurrencyInterface in Magento 2?

First of all, I will answer your question What is the best practices to override this php interface from the magento core files? From the basic knowledge, we cannot override an Interface. In ...
Khoa TruongDinh's user avatar
6 votes

I want to override vendor\magento\module-email\Model\AbstractTemplate.php

You can use the plugin to make changes in this function. Create following files in your custom module. app/code/Vendor/Module/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://...
Dinesh Yadav's user avatar
  • 6,475
5 votes

Overriding private method of Model file in Magento 2

Instead of overriding getCustomerData function, create a plugin for getConfig function. app/code/Vendor/Module/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/...
Dinesh Yadav's user avatar
  • 6,475
4 votes
Accepted

Magento 2, extending sales module's Model, getting error Required type: \Magento\Framework\ObjectManagerInterface

Here is complete working code you can use app/code/MyVendor/MyModule/etc/module.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
Dhaval Solanki's user avatar
3 votes

Magento 2 : override model file

Your di.xml is wrong if you want to override a class. In Magento there are two types of overriding: One is Plugin Another is preference PLUGIN: Is used for changing the behavior of a method. ...
Baharuni Asif's user avatar
3 votes
Accepted

I want to override model in the Magento 2

etc/di.xml <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\...
Eugene Kapelko's user avatar
3 votes

Magento 2 override Third party module installed with Composer

You could create another module to override the current one app/code/Vendor/Module/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
Tuyen Nguyen's user avatar
  • 1,332
3 votes
Accepted

How to override magento2 product tierprice?

You will achieve by the plugins. create a di.xml on following path: Company/Module/etc/di.xml <type name="Magento\Catalog\Model\Product"> <plugin name="after_final_price" type="...
Dhairya Shah's user avatar
3 votes
Accepted

Magento2: Failed Override Magento_Tax module Class with protected method

This is because you are overriding the wrong class. Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector The class CommonTaxCollector is not used directly, Magento2 used a Tax class which overrides ...
Saad Taimoor's user avatar
2 votes
Accepted

How to override customer resource module customer.php

You have to add models node and follow below code <?xml version="1.0"?> <config> <modules> <Abc_CustomizeCustomers> <version>0.1.0</version> ...
Qaisar Satti's user avatar
  • 32.5k
2 votes
Accepted

Override cart price rule functionality

Finally I found it. This is the class I had to override: \Magento\SalesRule\Model\ResourceModel\Rule\Collection public function setValidationFilter( $websiteId, $customerGroupId, $...
Marc Pont's user avatar
  • 1,453
2 votes
Accepted

Magento 2 - Can't override pdf invoice class

Use below code for di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config....
Kishan Patadia's user avatar
2 votes

Magento 2 product model override not working correctly

I think the best practice would be use Magento 2 plugin to apply your changes. di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
Nicholas Miller's user avatar
2 votes
Accepted

Override Order PDF Abstract Model From Custom Module

Magento does not allow you to rewrite abstract classes. The simplest solution would be copying the file to app/code/local/Mage/Sales/Model/Order/Pdf/Abstract.php and then editing the function as ...
Andrew Noble's user avatar
2 votes

Magento2 : Can't Override Model File

drop your __construct method because you are not adding anything new to it compared to the original class. Also you may need to copy all of the private methods from the original class into yours. ...
Marius's user avatar
  • 199k
2 votes
Accepted

Override Magento\Catalog\Model\Product

Can you do the below change in your di.xml file and confirm. <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:...
Thamo's user avatar
  • 446
2 votes
Accepted

Magento 2: Override di.xml in custom theme

di.xml files and models are considered "backend" code. Themes only deal with frontend code: layout, template, css/less, javascript, images, etc. You must create a module to accomplish those backend ...
Shawn Abramson's user avatar
2 votes

magento 2.3 how to override protected function in custom module

Your di.xml code will be look like: <?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/...
Amit Bera's user avatar
  • 77.7k
2 votes
Accepted

How to get Gift Message data on Invoice PDF in Backend Sales Order Grid Magento 2?

Below Code Worked for me. If you check sales_invoice_item table here order_item_id column contains your Order items id. Vendor\Module\Model\Order\Pdf\Items\Invoice\DefaultInvoice.php <?php ...
Hitesh Balpande's user avatar
2 votes
Accepted

How can I override Magento/Customer/Model/AccountManagement?

app/code/VendorName/ModuleName/etc/frontend/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
Pratik Oza's user avatar
  • 4,002
2 votes

Overriding Model Not working : Magento2

You cannot override private functions. Also, you should only use preference as a last resort, try instead to use plugins to change the behaviour. Please note plugins also cannot be used on private ...
Bogdan Tomi's user avatar
2 votes

Magento 2 : Prevent "payment method" based on country ID

You don't need to override any method. You can do with the use of observer. Step 1:- Please create events.xml file under path PackageName\Module\Observer\PaymentMethodAvailable <?xml version=&...
ZealousWeb's user avatar
  • 2,138
2 votes

How to override class Magento\Sales\Model\Order\Pdf\Total\DefaultTotal?

I have also tried with preference but it did not work so have done using the plugin. Please refer below files app/code/Vendor/Module/etc/adminhtml/di.xml <?xml version="1.0"?> <...
juber sherasiya's user avatar
1 vote

Magento2 override Newsletter Model showing error

Finally I have removed construct and used scope config to get system configuration value so my purpose was resolved.
bhargav shastri's user avatar
1 vote
Accepted

Magento2 override Newsletter Model showing error

try: please remove the generated folder and cleaned cache after replacing a code <?php namespace Commercepundit\Dealerregistration\Model; use Magento\Customer\Api\AccountManagementInterface; use ...
Prashant Patel's user avatar
1 vote

Magento2 override Newsletter Model showing error

Please replace your construct with below code and try: please remove generated folder and cleand cache after replacing code public function __construct( \Magento\Framework\Model\ResourceModel\Db\...
Rutvee Sojitra's user avatar
1 vote
Accepted

Overriding Product model doesn't work

You need to change the module from Overrides_All.xml to Overrides_Customs.xml Use the below code in your model: <?php class Overrides_Customs_Model_Product extends Mage_Catalog_Model_Product { ...
Sukumar Gorai's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible