Questions tagged [preference]
Denotes questions related to Magento 2 preferences
101
questions
0
votes
3
answers
39
views
Preference Module - When to Pass in Parent Dependencies
I am currently creating a preference module to add additional functionality to \Magento\Catalog\Model\Product and in reviewing some of the tutorials, example below, I noted that dependencies weren't ...
1
vote
2
answers
278
views
Magento 2 how to overwrite a trait function
How do you overwrite a trait function from vendor.
Things i did try in the di.xml
<preference for="\Vendor\Module\Traits\Model\ChangeMe"
type="\Company\Module\Traits\...
1
vote
2
answers
231
views
Magento 2 - Send data into a new quote_item column from an API call
I have added a new column in quote_item table and want to add this field as a parameter in cart API payload but I don't how this will happen.
This is what I get when i try to hit add to cart api.
...
0
votes
2
answers
170
views
How to override CartItemInterface class in in my custom model?
I have to add 2 new methods getter and setter in CartItemInterface but i am facing issues.
Basically I have added a new column in quote item table and now I want to add this column in cart api.
Please ...
0
votes
1
answer
31
views
Composer Patch vs. Custom Module for Vendor Directory Modifications
Is there a general consensus on when you should create a custom module to override core vs when you should use a composer patch?
At present, I need to add @ to a line of code and feel that a module is ...
0
votes
1
answer
110
views
Override CatalogWidget\Block\Product\ProductsList with new dependence injection
Here is my di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<...
0
votes
2
answers
162
views
override checkout index controller
I would like to override only one line in checkout/index/index controller.
do I need to use preference or plugin or observer?
if (!$this->_customerSession->isLoggedIn() && !$...
0
votes
1
answer
341
views
Override \Magento\CatalogImportExport\Model\Import\Uploader.php
I'm working on 2.4.5 upgrade and Magento has a bug in the core. I need to work around the bug by overriding a class.
I created a plugin to override it via preference.
What am I missing?
/etc/di.xml
&...
0
votes
0
answers
58
views
Magento 2 : preference for reviews post controller error:Type Error occurred when creating object:
I get this error Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object:
I created a prefernce for review controller Post and added the construct method ...
0
votes
1
answer
195
views
Whenever a product is added to cart an additional qty of same product should be added to cart using prefrence not plugin? [duplicate]
Should be achieved by preference not using the plugin and observer.
can anyone provide code for this ?
0
votes
1
answer
228
views
Magento 2: Disable Welcome Email Using preference [closed]
How to Disable Customer Welcome Email Only Using preference not with plugin
0
votes
1
answer
858
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/...
0
votes
0
answers
291
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\...
1
vote
2
answers
649
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/...
0
votes
1
answer
1k
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://...
0
votes
1
answer
52
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?
0
votes
1
answer
39
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 ...
0
votes
2
answers
423
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 ...
0
votes
0
answers
82
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, ...
0
votes
1
answer
283
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 ...
0
votes
1
answer
188
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 ...
0
votes
3
answers
597
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 ...
0
votes
1
answer
296
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(...
0
votes
1
answer
172
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
0
votes
1
answer
170
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-...
0
votes
1
answer
111
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\...
0
votes
0
answers
22
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 ...
3
votes
1
answer
418
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
0
votes
2
answers
331
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 ...
0
votes
2
answers
57
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 ...
0
votes
1
answer
996
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.
1
vote
0
answers
90
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.
2
votes
2
answers
448
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/...
1
vote
0
answers
171
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 ...
1
vote
2
answers
70
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\...
0
votes
0
answers
64
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 ...
2
votes
2
answers
2k
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/...
0
votes
1
answer
542
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:...
2
votes
1
answer
1k
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 ...
1
vote
1
answer
615
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 ...
1
vote
3
answers
390
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 ...
0
votes
1
answer
1k
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 ...
0
votes
2
answers
1k
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 ...
1
vote
1
answer
684
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 ...
0
votes
1
answer
106
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 ...
1
vote
1
answer
386
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\...
0
votes
1
answer
1k
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
...
0
votes
1
answer
422
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 ?
0
votes
1
answer
332
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/...
2
votes
0
answers
90
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 ...