Magento 2.1.x
Run magento setup:di:compile (executed successfully)
My controller action should rewrite original Magento action.
Original Magento Action is executed.
Making it more clear, here is the piece of code which rewrites the Magento controllers (under _etc/di.xml_, tested also under _etc/adminhtml/di.xml_, with the same result):
<?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\Widget\Controller\Adminhtml\Widget\LoadOptions"
type="CustomModule\CustomWidgets\Controller\Widget\Adminhtml\Widget\WidgetLoadOptions" />
<preference for="Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\OnInsert"
type="CustomModule\CustomWidgets\Controller\Cms\Adminhtml\Wysiwyg\Images\WidgetOnInsert" />
</config>
If I don't run magento setup:di:compile, preferences will work without any problem. But, after run it, preferences stop working (tested with frontend and admin controllers)
I have checked _var/di/adminhtml.ser_ file and interceptors for my classes seem to be created correctly (not sure if such information can help)
I hope the information is enough detailed, thank you in advance!
Have you tried to run setup:static-content:deploy afterwards?
And just in case, run again setup:upgrade at the very end of operations.
Hi @stamster thanks for answering. I tried your suggestion and it didn't work. Of course, if at the end I run setup:upgrade command, preference will work, but that is because it removes _etc/di/_ folder content. Anyway, I guess preference should work with controllers after magento setup:di:compile because preference for other kind of classes (I tested it with a model, also) works normally. Only I have problems with controllers.
Hi,
We have same problem. Did you fix it?
Hi,
I have the same issue, I tried to extend the checkout controller using preference. My code is shown below:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\Checkout\Controller\Cart\Add" type="SCI\Checkout\Controller\Cart\Add" />
</config>
It is working fine and perfect, but after we deploy to production mode the preference is not executed. I double check by editing the vendor codes directly and so it works. So therefore it does not call my preference anymore. Any suggestions? Thank you.
Hi @jochhop , thanks for reporting this issue. Internal ticket MAGETWO-57704 was created.
Best,
Maksym
@ kaiSer007 It's happening for us too. If we switch to developer mode, it works.
Any update on this ticket?
I already have another example where preference is not working after compilation
<preference for="Magento\Framework\Data\Form\Element\Editor" type="Vendor\Name\Block\Element\Editor" />
Any update? Same issue faced by me. When i tried to override controller
<preference for="Magento\Checkout\Controller\Cart\Add" type="Trimantra\Override\Controller\Cart\Add" />
and after deployment its not working.
@xmav how do we check the updates of the internal ticket MAGETWO-57704. Is there a different thread were this issue been discussed?
@kaiSer007 github issue will be closed once internal ticket fixed
same issue with any controller with scope etc/adminhtml/di.xml or etc/di.xml or etc/frontend/di.xml
Latest version also having the same issue.
<preference for="Magento\Customer\Controller\Account\ForgotPasswordPost" type="Vendor\Module\Controller\Account\ForgotPasswordPost"/>
Any updates?
Same issue when overriding Magento\Customer\Controller\Account\LoginPost
Magento Version 2.0.13
I have been looking into this issue today, as it's blocking a release for us.
The problem appears to be if there is a plugin declared on the class:
This creates an interceptor file, which then means any further preference is completely ignored during di compilation.
I'm using Magento 2.1.5 and I have the same problem with a model rewrite, compiling di is ignoring a preference tag. Anyone has a fix to bypass this problem? Or I have to remove var/di folder?
Anyone know if this issue is resolved in 2.1, or does it still apply?
@jochhop, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
We tested the issue on 2.3.0, 2.2.0, 2.1.9
The same issue; in DEVELOPER MODE my controller preferences for adminhtml was neglected by di.xml, so they stopped working. After a successful setup:di:compile, the interceptors in var/generation were created successfully, but those are never executed in runtime.
Here is a workaround that worked for me;
everything is up an running again!
I think this is not a bug, but a confusion around development modes and how var/di is utilized... Seems like we SHOULD remove 'var/di' every time after compiling dependencies on DEVELOPER MODE.
Check this article
https://www.cadence-labs.com/2017/07/magento-2-run-setupdicompile/
Same issue when overriding Magento\ImportExport\Controller\Adminhtml\Import\Start
Magento Version 2.2.3
I'm having this issue too with 2.0.8. If I run setup:upgrade it clears the compiled classes and works. It seems I shouldn't have to do that though and it's not great from a performance standpoint to have to clear your compilation in production.
Most helpful comment
The same issue; in DEVELOPER MODE my controller preferences for adminhtml was neglected by di.xml, so they stopped working. After a successful setup:di:compile, the interceptors in var/generation were created successfully, but those are never executed in runtime.
Here is a workaround that worked for me;
everything is up an running again!
I think this is not a bug, but a confusion around development modes and how var/di is utilized... Seems like we SHOULD remove 'var/di' every time after compiling dependencies on DEVELOPER MODE.
Check this article
https://www.cadence-labs.com/2017/07/magento-2-run-setupdicompile/