Questions tagged [preference]

Denotes questions related to Magento 2 preferences

Filter by
Sorted by
Tagged with
0 votes
1 answer
34 views

How to override the Search.php using preference in magento 2?

I am not able to override the Search.php file by using preference in magento 2.3.4. Below is the my di.xml file. Please anybody can check the below code. <config xmlns:xsi="http://www.w3.org/...
user avatar
  • 696
0 votes
0 answers
44 views

Override third party module customerData class defined in di.xml arguments

I have a third party module that has this class app/code/Vendor/ModuleName/CustomerData/Popup.php and that class is defined in the frontend/di.xml file like this <type name="Magento\...
user avatar
  • 289
0 votes
2 answers
222 views

Magento 2 : Magento\Newsletter\Model\SubscriptionManagerInterface class does not exist in 2.3 version. Need Compatible code for 2.3 and 2.4

I have installed a custom module related newsletter, I want my module to be compatible in 2.3 and 2.4. I'm overriding the class Magento\Newsletter\Controller\Subscriber\NewAction MyVendor/MyModule/...
user avatar
  • 1,838
0 votes
1 answer
159 views

Magento2.4 How to override \Magento\Checkout\Controller\Cart?

Even if I simply copy the file without changes, it does not work as a preference. Any idea why? I created a preference in di.xml <?xml version="1.0"?> <config xmlns:xsi="http://...
user avatar
0 votes
1 answer
31 views

What's the difference between a XML preference with slash and without it?

Checking the Magento core I see two patterns a class with the slash in the beginning and a class without it. What would be the difference?
user avatar
0 votes
1 answer
32 views

Overriding Third Party Component code - preference

I am using an extension that displays a message as the customer approaches a Free Shipping threshold (https://aheadworks.com/free-shipping-bar-extension-for-magento-2), eg, "30 euro left until ...
user avatar
0 votes
2 answers
101 views

Magento 2 - Can't override class - must be an instance of

I created a preference override for Magento\Quote\Model\Quote\Item\CartItemPersister in my own module. But I get this error in the browser developer console: Total: Type Error occurred when creating ...
user avatar
  • 2,441
0 votes
0 answers
22 views

magento 2.4 multiple modules override the same block class

I have the following situation: third party module A overrides core block php class via preference in order to customize a method the original method gets the input, loops it to extract some data, ...
user avatar
  • 129
0 votes
1 answer
34 views

How to override a method of a class where the method itself is defined in its parent class, and only called in the current class?

I would like to extend the OrderSender class, located at Magento\Sales\Model\Order\Email\Sender\ and then override the method prepareTemplate($order), this method is actually defined in the Sender ...
user avatar
0 votes
1 answer
33 views

Preference seems to be ignored

This is the class I want to get preferenced : Amasty\Shopby\Block\Navigation\Top\Navigation I've put some dump inside each files....only the test 3 is appearing when it shouldn't as ovverrided by the ...
user avatar
  • 772
0 votes
3 answers
124 views

Is it possible to override methods with arguments using preference?

I want to disable verification email sending from certain route. At first, I thought that I would create a plugin which would change the customer email to the dummy one before actually sending the ...
user avatar
  • 11
0 votes
1 answer
121 views

Magento 2.4 Preference on Block does not work

What i'm trying to do is to rewrite a core function of ( MagentoMagento\ConfigurableProduct\Block\Product\View\Type\Configurable ) The function is called getJsonConfig() public function getJsonConfig(...
user avatar
0 votes
1 answer
44 views

Magento 2 preference not working for Magento\Customer\Model\Metadata\Form\File

I want to create preference for this file Magento\Customer\Model\Metadata\Form\File but its not working so please give some solution for this problem how to solve it di.xml code
user avatar
  • 3
0 votes
1 answer
116 views

Magento 2 cannot override 3rd party controller

Im trying to override a controller from swissup/firecheckout location in my vendor folder my di.xml is <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
user avatar
  • 133
0 votes
1 answer
61 views

Magento 2 preference not working

I created a preference, if I try to exit the extended class nothing happens. But if I try it with the following code: <?php require_once 'app/bootstrap.php'; $bootstrap = \Magento\Framework\App\...
user avatar
0 votes
0 answers
18 views

Suddenly Sitemap model stopped working after 4month

I have used the preference to override the Sitemap model. Working fine for 4 months. I have also tried to find other module is overriding the same but didn't get anything. Can somebody help me to find ...
user avatar
  • 696
1 vote
1 answer
134 views

Override Magento\Sales\Model\Order\Email\Sender\CreditmemoSender Magento 2

How to override below file in module ? Magento\Sales\Model\Order\Email\Sender\CreditmemoSender.php
user avatar
  • 367
0 votes
2 answers
173 views

How can i override abstract class protected function

I want to override abstract class Magento\Sales\Controller\Adminhtml\Order\Create of the below method protected function _processActionData($action = null){ } I have tried using preference but it ...
user avatar
  • 5,856
0 votes
2 answers
47 views

What is the error in this Preference?

Due to PayPal Error, i am updating the following function in app/code/Magento/Paypal/Model/Api/Nvp.php, not edit the entire code just update a single function. Function Name : function ...
user avatar
  • 95
0 votes
1 answer
625 views

Magento 2 : How to Override /vendor/magento/module-quote/Model/Quote/Address/Total/Grand.php

Not able to override grand.php file can anyone help me out.
user avatar
1 vote
0 answers
44 views

I have override the block Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option but is not working

I have followed this Magento2 - How to override this file Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Options.php but its now working.
user avatar
  • 718
1 vote
2 answers
291 views

Magento 2.3 - How to handle Preference Error - Type Error occurred when creating object

I am using Magento 2.3.4 small bug in it (LINK) then Update the following code https://github.com/magento/magento2/blob/db69693bd929bd8665015ff6d9b6a3845584aa0b/lib/internal/Magento/Framework/Search/...
user avatar
  • 95
1 vote
0 answers
45 views

Preference is not working while a method called from child class

I created a preference for the method _applyOptionsPrice() in Magento/Catalog/Model/Product/Type/Price.php class. The preference is working while the _applyOptionsPrice() was called from the same ...
user avatar
1 vote
2 answers
63 views

Cannot override class RuleProductPricesPersistor in Magento 2

I'm trying to override following class Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor Using below code <preference for="Magento\CatalogRule\Model\Indexer\...
user avatar
  • 1,474
0 votes
0 answers
61 views

magento2 preference not working in Enterprise Edition 2.3.5

magento2 while overriding class using preference, its not working in Enterprise Edition 2.3.5 In checkout_cart_index.xml <referenceBlock name="checkout.cart.crosssell"> <action ...
user avatar
1 vote
2 answers
896 views

Magento2 Around Plugin vs Preference. Which option is better?

I think I don't need to explain in detail about plugins, preferences and observers. These are types of overriding or extending default magento functionality. While overriding any magento core method/...
user avatar
0 votes
1 answer
398 views

Overriding \Magento\Quote\Model\ShippingMethodManagement not successful

I've created a module to override di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:...
user avatar
  • 2,048
2 votes
1 answer
668 views

Magento 2 Override public static method of framework class

I want to override public static function getCorrectFileName method of Magento\Framework\File\Uploader, I have check with Preference and Plugin but it is not working for me. Anyone have idea about ...
user avatar
1 vote
1 answer
496 views

Magento 2.3 - Swatches Helper override

I'm trying to override a function in the Helper of the Swatches module of Magento 2. The function resides in the Data.php file. As some of you may know in specific versions of Magento 2 the text ...
user avatar
1 vote
3 answers
301 views

Magento 2.3.3 : How to Overide Collect method in Magento\Catalog\Ui\DataProvider\Product\Listing\Collector\Image

I Have created recently viewed product widget in backend category page sidebar. I have single store with multiple Currency setup when i view the product gets added to list perfectly. My problem is ...
user avatar
  • 1,696
0 votes
1 answer
943 views

How do you override Magento\Catalog\Block\Category\View?

I want to override the protected function _prepareLayout() So i have used preference <preference for="Magento\Catalog\Block\Category\View" type="Module\Name\Block\Category\View"/> class View ...
user avatar
0 votes
2 answers
885 views

Magento 2: Preference is not working

I want to override Magento\Catalog\Model\ResourceModel\Product\Collection using preference to modify the _buildClearSelect($select = null) method. For this, I have created di.xml with the following ...
user avatar
1 vote
1 answer
570 views

Magento 2-Override FinalPriceBox using Preference or Plugin class of Configurable Product module

Anyone has idea how to make preference or plugin on Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox class of Magento\ConfigurableProduct. Basically, new function i wanted to add in the ...
user avatar
  • 1,735
0 votes
1 answer
84 views

Is there a way to declare preference for a model or overwrite a model alias in M1?

I'm using Magento 1.9.x EE. I'm looking to overwrite the Mage_Core_Model_Email_Template::send function. I could overwrite the core class, but then my changes would be dependent on code that resides ...
user avatar
1 vote
1 answer
212 views

How to override already override class in magento 2

Hii we need to override Magento\Catalog\Model\ResourceModel\Product\Collection class for our customisation. To do this we added <preference for="Magento\Catalog\Model\ResourceModel\Product\...
user avatar
  • 147
0 votes
1 answer
904 views

Some of product detail page error- Element 'reference': This element is not expected

When I tried to change or open product I got next message: 1 exception(s): Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'reference': This element is not expected. Line: 1 ...
user avatar
  • 413
0 votes
1 answer
289 views

How to change shipment PDF font style in Magento 2.2.7

I am working on Magento 2.2.7 & need to change font style of shipment pdf i want to achieve that using preference way of di.xml file how to do that. which files,function i have to override ?
user avatar
0 votes
1 answer
262 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/...
user avatar
  • 1,047
2 votes
0 answers
85 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 ...
user avatar
  • 465
1 vote
2 answers
180 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 ...
user avatar
0 votes
2 answers
395 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/...
user avatar
2 votes
1 answer
263 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 ...
user avatar
  • 943
0 votes
0 answers
387 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\...
user avatar
1 vote
1 answer
77 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:...
user avatar
  • 1,434
0 votes
1 answer
115 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/...
user avatar
  • 746
5 votes
4 answers
313 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="...
user avatar
  • 3,664
3 votes
1 answer
677 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=&...
user avatar
2 votes
0 answers
155 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\...
user avatar
  • 1,096
1 vote
3 answers
72 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 ...
user avatar
0 votes
2 answers
291 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 ...
user avatar