0

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 call my around method action in di.xml for same controller Action, can any one has any idea. Thank In Advance.

1
  • Can you tell me what you have try archive using this? Commented May 8, 2018 at 12:06

2 Answers 2

0

You can create the plugin for the Controller which is overriding the vendor file.

You can try this method as well: How to override core class which is already overrided by other custom module in Magento 2

7
  • I need to overrride Controller Files But in the link he has explained block override, Is it Worth? @xMagestore Commented May 8, 2018 at 9:43
  • It was just for a reference. you can override the controller in a similar way.
    – xMageStore
    Commented May 8, 2018 at 10:14
  • I know overridding the module with custom module using another preference but here i need is plugin for already overriden perference, can you answer my question? Commented May 8, 2018 at 11:29
  • Yes, suppose the core class A is overridden in B, then You can create a plugin for class B which would work efficiently.
    – xMageStore
    Commented May 8, 2018 at 12:29
  • then how would i define that in di.xml, i tried but it not calling the plugin method ,can You please mention the di.xml file how to use. @xMageStore Commented May 8, 2018 at 12:33
0

use sortOrder in plugin declaration :

<config>
  <type name="{ObservedType}">
    <plugin name="{pluginName}" type="{PluginClassName}" sortOrder="1" />
  </type>
</config>
6
  • if i use sort Order what would happen can You explain it clear @Prasanta Hatui Commented May 8, 2018 at 9:40
  • 1
    When multiple Plugin has declare for same method then the sortOrder is used which plugins will run first. Commented May 8, 2018 at 9:44
  • I have Plugin and Preference concept not both are plugins in my scenerio @Prasanta Hatui Commented May 8, 2018 at 9:45
  • In this case you will only can use for overridden class method to change the behavior Commented May 8, 2018 at 9:51
  • is their any change to use both preference and plugin Concept @Prasanta Hatui Commented May 8, 2018 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.