16

The $data[] can be used to hold values passed from di.xml's arguments replacement mechanism, when \Magento\Catalog\Block\Product\ListProduct intantiated. In your case this could be populated by <type name="\Magento\Catalog\Block\Product\ListProduct"> <arguments> <argument name="data" xsi:type="array"> ...


13

The $data can be used to populate data on your object since the constructor of \Magento\Framework\DataObject is this public function __construct(array $data = []) { $this->_data = $data; } or similar for Magento\Framework\Api\AbstractSimpleObject /** * Initialize internal storage * * @param array $data */ public function __construct(array $data ...


9

For getting all available list of plugins: Go to vendor/magento/framework/Interception/PluginList/PluginList.php find method merge public function merge(array $config) { // default code echo "<pre>"; print_r($this->_data); die(); } For getting all available list of preferences: vendor/magento/framework/ObjectManager/Config/...


6

It's definitely feasible using preferences. You can do something like this in a di.xml file: <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Framework\Class\You\Want\To\Rewrite" type="Vendor\Module\Your\Class" /> </...


5

You've mixed up two concepts here: preferences and plugins. Preferences are basically rewrites on the class level. In case you define a preference for your controller your preference class will have to extend the original class and you can modify whatever method you want Declaring preferences is different than declaring plugins you can find details here: ...


5

Thanks fschmengler , I managed to solve this by using Plugin. Override/replace single method in block class: app/code/MySpace/MyModule/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\Bundle\Block\Catalog\Product\...


5

To replace a single method, use the around plugin and don't call the original method with $proceed()


4

ConfigurablePriceResolver is virtual type both used by ConfigurableFinalPriceResolver and ConfigurableRegularPriceResolver. Therefore, to override it, you have to override the virtual type, not the class itself. <preference for="ConfigurableFinalPriceResolver" type="Vendor\Module\Pricing\Price\ConfigurablePriceResolver" /> <preference for="...


3

Another option would be to use a Magento 2 plugin, for example, in a etc/di.xml: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Framework\Config\File\ConfigFilePool"> <plugin name="...


3

Solution: app/code/vender/module/etc/di.xml <?xml version="1.0" encoding="UTF-8"?> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...


3

Unless your also overriding the template in your module, you need to change the module name for your class, otherwise magento looks for the template file in your module instead of the core module. You can do it by adding this method: public function getModuleName() { return 'Magento_Checkout'; } or by setting it in the constructor like this: $this->...


3

So after taking everyones suggestions and getting as far as being able to render the product detail page without any errors but the block addtocart.phtml would not appear at all. I ran into this stackoverflow question Overriding Block in Magento 2 and I realized that the accepted answer allowed for my block to be rendered on the page. Even though my block ...


2

I may be wrong but I'm pretty sure it's because those controllers are admin controllers and thus the corresponding di.xml should not be global. I reckon you should move your di.xml from etc to etc/adminhtml


2

I think you misunderstanding plugins and preferences. If you want to override an entire class you need to use preferences: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Sales\Block\...


2

There is an excellent answer to the plugin option of your questions here: how magento getting configurable product lowest price of associated products? You can see the setup of the module and an aroundResolvePrice method/function I have worked on this problem before and came to conclusion that it may not be possible to use a preference for ...


2

You should try with Plugin. The code below will work: etc/adminhtml/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Sales\Api\CreditmemoRepositoryInterface"> <plugin ...


2

I think it is because the class you are trying to override via preferences is actually being used by the system via virtualtype. vendor/magento/module-paypal/etc/di.xml <virtualType name="Magento\Paypal\Model\Payflow\Service\Response\Validator\ResponseValidatorInController" type="Magento\Paypal\Model\Payflow\Service\Response\Validator\ResponseValidator"&...


2

Step 1:- create di.xml file in Folder app/code/Webkul/Hello/etc/ <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Swatches\Block\Product\Renderer\Configurable" type="Webkul\Hello\Block\Rewrite\...


2

You can disable the Plugin with disabled="true". For example: <type name="Magento\Framework\App\Action\Action"> <plugin name="storeCheck" disabled="true" /> <plugin name="storeCheckCustom" type="Vendor\Module\Model\Plugin\StoreCheck" sortOrder="99" /> </type>


2

Try following way: <virtualType name="VendorName\ModuleName\Model\ResourceModel\Fulltext\CollectionFactory" type="Magento\Catalog\Model\ResourceModel\Product\CollectionFactory"> <arguments> <argument name="instanceName" xsi:type="string">VendorName\ModuleName\Model\ResourceModel\Fulltext\Collection</argument> </arguments> </...


2

It work for me. I override the Catalog\Model\ResourceModel\fulltext\Collection.php. Create a etc\di.xml file. write the code <virtualType name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory" type="Magento\Catalog\Model\ResourceModel\Product\CollectionFactory"> <arguments> <argument name="...


2

I strongly recommend to not use Preferences, because there are other techniques which you could use to update the input or output of a function. For example you could write a Before plugin to update the incoming parameters or a After plugin to update the outgoing result. But in your case it probably is not possible with a Plugin but then you could use the ...


2

<preference for="Amasty\Shopby\Model\ResourceModel\Fulltext\Collection" type="Abc\Cde\Model\ResourceModel\Product\Collection" />


1

As you want to overide the class Magento\LayeredNavigation\Block\Navigation So your preference class should be for="Magento\LayeredNavigation\Block\Navigation" instead of for="Vendor\ModuleName\Block\Navigation" Please do the recommend changes at di.xml. And Macforum\MultipleLayeredNavigation\Block\Navigation code should be: <?php namespace ...


1

I hope you are trying to override Magento Layered navigation block. Your di.xml should be like below: <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\LayeredNavigation\Block\Navigation" type="Macforum\MultipleLayeredNavigation\...


1

If you want to overwrite only getName() function you can create plugin instead of overwriting the entire customer Model. Any of the public function in model we can create plugin. http://inchoo.net/magento-2/overriding-classes-magento-2/


1

Because you are extending \Magento\Catalog\Pricing\Price\TierPrice you can access the protected property $product with: $productId = $this->getProduct()->getId(); The $product property is set in the constructor of \Magento\Framework\Pricing\Price\AbstractPrice which \Magento\Catalog\Pricing\Price\TierPrice extends.


1

We also ran into a similar issue. We wanted to rewrite some files that used in setup upgrade to optimize the deploy process. After some investigation, we found that these CLI commands are implemented independently of Magento using Symfony. It does not follow usual Magento execution cycle. As a solution, we have created a module/script using the same method ...


1

U cannot override private variables. When we run $ php bin/magento setup:upgrade <pre>Array ( [dist] => Array ( [app_config] => config.dist.php [app_env] => env.dist.php ) [local] => Array ( [app_config] => config.local.php [app_env] => env.local.php ...


1

Error handler created not through DI, so preferences are not applicable see: https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/App/Bootstrap.php#L373 The best way to log errors its change settings for \Psr\Log\LoggerInterface that already used to log errors. Magento uses Monolog library for logging. For example, you can add \...


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