Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [preference]

Denotes questions related to Magento 2 preferences

0
votes
1answer
41 views

Why preference not working in Magento 2 observer (Custom module)

etc/di.xml <preference for="Custom\Pricerule\Observer\Frontend\Catalog\Catalog\ProductGetFinalPrice" type="Lof\RequestForQuote\Observer\ProductGetFinalPrice2" /> observer/...
1
vote
0answers
20 views

Preference for Magento\Setup Classes not working

TLDR - Is there a reason I can't use preference for classes in Magento\Setup namespace, specifically during the setup:upgrade processing, OR is there something I am missing with the following ...
1
vote
3answers
26 views

How to use a preference for only one website when there is multisite functionality magento 2?

I have created a preference to override the functionality of customer save. But the I need to use the core customer save functionality for 1 website and my preference functionality for another ...
0
votes
1answer
29 views

Preference for ConvertToCsv not working in custom module

I have below code in my di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/...
2
votes
1answer
28 views

Preference class doesn't work

I'm trying to replace a class method "wrapResult" from: \Magento\Catalog\Pricing\Render\FinalPriceBox Never enter into this method. Try to stop the execution with die () or with xdebug, enter ...
0
votes
0answers
18 views

Error Class not found before deleting generated folder

I have created a preference to override a class but constantly getting error "Class not found" before deleting "generated" folder content: Error: Fatal error: Uncaught Error: Class 'Vendor\Module\...
1
vote
1answer
29 views

How to override List.phtml and Block as well

I'm trying to override the List.phtml and its block using preference I tried this <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:...
0
votes
1answer
15 views

How to override Quick Order model

I'm working on a Magento 2.2.3 B2B, with the Quick Order feature enabled, and I can't find a way to extend a method of the Magento\QuickOrder\Model\Cart model. So far I tried the usual: MyCompany/...
4
votes
2answers
58 views

Magento 2 : How to override files from Magento core framework?

Actually I'm refering to #19247 for PHP 7.2 specific issue. that partially solved my issue but can't able to override that file. I tried using preference here's what I tried. <preference for="...
0
votes
1answer
34 views

Undo preference from third party module

I have to deal with a third party module that enthusiastically uses preferences for everything and breaks stuff with it. For example: <preference for="Magento\Sales\Model\Order" type="Censored\...
2
votes
0answers
40 views

Is it possible to change/replace the custom function argument in magento 2

I just want to change/replace the custom function arguments, not constructor arguments. This is third party module function, which have wrong argument. public function addAttachment(\Fooman\...
0
votes
0answers
46 views

How to rewrite Magento\Framework\Simplexml\Config file functions?

I have to rewrite public function loadString($string) { .... } in the file Magento\Framework\Simplexml\Config. I tried with preference like below in mudule's di.xml <preference for="Magento\...
1
vote
3answers
60 views

How to Make Class or module to support M 2.1.7 and M 2.2.4 version in Magento 2

I have one custom module which is working fine for M 2.1.7 in that module, I extend \Magento\Bundle\Model\Product\Type in M 2.2.4 they added a new class for core file and passed to __construct ...
0
votes
2answers
37 views

How to call Plugin which already using the preference for vendor file in magento 2

How to call Plugin which already using the preference for vendor file in magento 2. I have already has preference which is overridding the some custom Magento controller, Now how can i use plugin to ...
0
votes
2answers
62 views

Private method error while overriding Magento\Customer\Model\ResourceModel\CustomerRepository

I am using <preference> to override CustomerRepository, but Magento\Customer\Model\ResourceModel\CustomerRepository contains private functions and it throws me error Fatal error: Call to ...
0
votes
3answers
382 views

Magento 2, preference for Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection does not work

When filters + Ancor is enabled for category, sorting by product name doesn't work. I know the fix as I tested in Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection. So now I'm trying to ...
0
votes
1answer
31 views

Overriding Custom module's controller in Magento2 giving error

I am trying to override the controller of an extension in Magento2. My di.xml file is:- <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
3
votes
0answers
80 views

Why is there a DI preference for ProductInterface?

The ProductInterface has a DI preference leading it the ProductModel. While ProductModel is marked as falling under the Backward Compatibility Standard (it is marked with @api), it is still belonging ...
1
vote
0answers
249 views

Custom Module - Cart Page shows only “Estimate Shipping and Tax”

I'm trying to overwrite the function setRequest in /vendor/magento/module-usps/Model/Carrier.php to request "Online" rates from USPS. My complete module code is below. My module is enabled. I ...
0
votes
1answer
184 views

is it possible to override core plugin method by custom preference method?

is possible to override core plugin method by preference? Means I need to override afterXyz method in my module by using preference.
0
votes
4answers
2k views

Magento 2 Extend class with custom method through preference doesn't work

I'm trying to add a custom method Magento\LayeredNavigation\Block\Navigation. To my knowledge preference is the only way to do that. My di.xml <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
3
votes
2answers
400 views

Magento 2 not respecting preference?

I'm trying to make a preference to override the PayPal Module's ResponseValidator class, so that i can save the validation errors for easier debugging on our end if a customer's checkout fails. The ...
1
vote
1answer
328 views

Dependency injection not working on one the the tax collector class

I am trying to override mapItem method from "Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector" using below code. However code written in my local module's class is not invoked. VendorName\Tax\...
4
votes
1answer
196 views

How to override _registerJsPrice($price) function in Configurable.php Block in Magento2?

I am trying to override __registerJsPrice($price) function in configurable.php This function is work when we change swatch. Path of configurable.php is /opt/lampp/htdocs/magento/vendor/magento/...
2
votes
2answers
288 views

Magento 2 - Override Model Failed

I try to override the Customer model. I created code/Tc/Name/etc/di.xml, code/Tc/Name/Model/Customer/Customer.php . In di.xml <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
0
votes
1answer
175 views

Magento 2: Get product ID in override getTierPriceList from TierPrice

I'm extending \Magento\Catalog\Pricing\Price\TierPrice to return a custom list of tier prices for products. But I can't seem to figure out how to get the product id that is calling the ...
7
votes
0answers
340 views

How to override class Virtual Type class

I saw this, but it don't work for me. How to override Virtual Type class in Magento 2 <virtualType name="categoryFilterList" type="Magento\Catalog\Model\Layer\FilterList"> <arguments>...
3
votes
3answers
1k views

How to overwrite \Magento\Framework\Config\File\ConfigFilePool

Short version: How to use custom db and module config files instead of env.php and config.php ? or How to completely overwrite \Magento\Framework\Config\File\ConfigFilePool ? Long version: I'm ...
3
votes
1answer
99 views

How to override UpgradeData.php with Factory?

I need to override the UpgradeData Class from Catalog\Setup\UpgradeData But the constructor has factories in his arguments like CategorySetupFactory When I run setup:di:compile I got an error that ...
1
vote
1answer
253 views

how to intercept PayPal IPN messages

I was trying to understand what's the best way to read incoming IPN messages from PayPal. This need comes from the order workflow we implemented in our website. For example: when a payment is ...
0
votes
1answer
219 views

Why is my Magento Catalog Block Preference ignored in di.xml?

I am trying to extend the Magento\Catalog\Block\Product\ListProduct block in Magento 2.1 My Vendor_ModuleName module has the registration.php, the etc/module.xml and it's enabled. Then I add an etc/...
3
votes
1answer
193 views

How to extend creditmemo save action in magento 2

I need to extend creditmemo save action: Update post data before action method call Update database after creditmemo save. Which method is better Plugin or preference and if Plugin then how can I ...
5
votes
2answers
772 views

Magento 2: preference not working in admin panel

I am trying to override ConfigurablePriceResolver but can't override app/code/vender/module/etc/di.xml <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www.w3.org/2001/...
3
votes
1answer
518 views

How to Override Payment Helper Data Method Magento 2?

I am trying to override Magento Payment Helper data in my extension but it's not working. I have overriden by using the preference method. I have put below code in app/code/Demo/PaymentTest/etc/di....
3
votes
1answer
216 views

Magento 2 preference not working for Magento\Checkout\Block\Onepage

I am trying to override Magento\Checkout\Block\Onepage and it's display blank page Here is my Mymodule/Test/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/...
0
votes
1answer
492 views

Why preference is not working in Magento 2?

I am trying to implement error report in magento 2 so for that purpose i would like to mail all the errors in email. So I started with prefernece. di.xml <?xml version="1.0"?> <config xmlns:...
1
vote
4answers
3k views

Preference is not working in Magento 2

I am trying to override ErrorHandler class using preference but it is not working. di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
4
votes
2answers
705 views

Magento 2.1: <preference> doesn't work with block

I try to override getSelectionTitlePrice() - function. (vendor/magento/module-bundle/Block/Catalog/Product/View/Type/Bundle/Option.php) if i have understood right the best way to do it is use ...
8
votes
1answer
2k views

Magento 2: get a list of all plugins (interceptors) and preferences

Is there a way I can retrieve the list of all plugins (with the methods they're plugged onto) and all preferences (and their original class) on a Magento 2 install.
0
votes
1answer
276 views

What is the best way to override _initProduct() in module-checkout\Controller\Cart\Add.php

What is the best way to override _initProduct() function in: vendor\magento\module-checkout\Controller\Cart\Add.php I have this in my di.xml: <type name="Magento\Checkout\Controller\Cart\Add"&...
3
votes
1answer
624 views

Magento 2 override Pricing\Price\ConfigurablePriceResolver how to solve?

Hi I'm using Magento 2. I'm trying to override Pricing\Price\ConfigurablePriceResolver by adding a plugin or preference in the app/code folder but I can't make it work. I need to replace the ...
3
votes
1answer
51 views

Magento 2: Extend from rewritten block

Originally: There are 2 blocks like this: namespace Vendor\Module_1\Block; class ParentBlock{} class ChildBlock extends ParentBlock {} Now, I need to rewrite ParentBlock using di.xml: <...
0
votes
1answer
41 views

magento 2 preferences - what to extend

I have a question about m2 preferences (overwriting core modules). Whenever I overwrite a core module, do I have to inject all the classes the same way original class does? Also what should I extend? ...
1
vote
1answer
146 views

Overriding Block file is not working in Magento 2

Today I am trying to overwrite the \Magento\Sales\Block\Adminhtml\Order\View file, but it's not working. The same coding working on core files. My Code is <?php namespace SR\StackExchange\Block\...
2
votes
2answers
3k views

Magento 2: How to override Magento\Catalog\Block\Product\View constructor to inject \Magento\Eav\Model\Entity\Attribute\SetFactory

I am attempting to override the __construct method in the Magento\Catalog\block\Product\View block so that I can access the Magento\Eav\Model\Entity\Attribute\SetFactory to get the AttributeSetName of ...
5
votes
1answer
6k views

Magento2: plugin around method not working

I'm trying to use the plugin around method to override the execute method of \Magento\Checkout\Controller\Onepage\Success.php. I'm trying to create a module that allows you to view the checkout ...
0
votes
2answers
527 views

Catalog ProductList not overriding magento2

I have overridden my catalog product listproduct in etc/di.xml as: <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/...
3
votes
1answer
821 views

Magento 2: controller preference not working after setup:di:compile

I need to rewrite a couple of adminhtml controllers in Magento 2. I am using preference and my configuration in etc/di.xml file looks like this: <?xml version="1.0"?> <config xmlns:xsi="http:...
1
vote
1answer
780 views

Overriding Sales\Block\Order\View Block in Magento 2

I am trying to extend Magento\Sales\Block\Order\View by using preferences to get some more information into customer order view page. Everything works fine if i remove __construct. so what might be ...
19
votes
2answers
4k views

Magento 2: what is the $data array constructor parameter?

So I noticed that in most models and blocks, there's this array $data = [] given as the last parameter of the constructor. For example \Magento\Catalog\Block\Product\ListProduct public function ...