Questions tagged [plugin]
Denotes questions about Magento 2 Plugins (BeforePlugin , AfterPlugin and AroundPlugin). Plugins are also known as interceptors in the Magento documentation.
618
questions
50
votes
3
answers
20k
views
Magento2: what is the basic difference between plugin and preference?
I used both Plugin and Preference in Magento2 tutorial and both are working fine but what is the basic difference between them.
Code for plugin:
1.1) Add a plugin declaration into di.xml:
<type ...
33
votes
3
answers
11k
views
Magento 2: Plugin before/around/after Interaction
In Magento 2, when you create an "around" plugin
public function aroundRenderResult(
\Magento\Framework\Controller\ResultInterface $subject,
\Closure $proceed,
ResponseHttp $response
) {
...
30
votes
5
answers
8k
views
Learning Magento Plugin Development
I have been a PHP developer for 13+ years, have extensive knowledge of PHP itself as long as some other popular projects like WordPress. I have no experience with Magento.
I now have a full time job ...
30
votes
3
answers
15k
views
Magento 2: Plugin vs Observer
In Magento 2, what are the pros and cons of using a plugin vs an observer to achieve something?
I understand that observers are subscribed to events whereas plugins can jump in before and/or after a ...
24
votes
2
answers
8k
views
Magento 2: what are the Interceptors file in var/generation?
So I noticed some Interceptor.php files in var/generation
I know that this folder contains generated classes created on the fly for the following:
Factories
Proxies
Plugins
I assume that ...
21
votes
2
answers
17k
views
How to override or disable core Plugins in Magento2?
I am building a marketplace using Magento2. For that reason I need to be able to load the order of the customer using the vendor's customer credentials.
The problem with this is that Magento2 uses a ...
19
votes
3
answers
2k
views
What Classes are "Intercept-able/Plugin-able" in Magento 2
Date: May 30, 2015 (given the changing nature of Magento 2).
Magento 2 introduced a plugin concept, implemented via an interceptor pattern.
What's not clear from the docs is -- which classes and ...
19
votes
4
answers
2k
views
Is there an event or plugin spot for when cart rule is no longer valid?
Is there an event or place I can plugin for when a shopping cart price rule is no longer valid (such as when it expires or if you change the quantity of other products where it no longer applies)? I ...
18
votes
2
answers
3k
views
Rewriting Magento 2 classes vs Plugins
Magento 2 has the concept of Plugins/Interception/Interceptors opposed to Magento 1.
These act like a before|after the event for every public method. Which is nice.
You can also use the around plugin ...
16
votes
4
answers
25k
views
Override abstract class in Magento 2
In Magento 1 I could copy abstract class to local or community directory and Magento used it, when autoload load this class.
Is there some solution to make to Magento loads my class instead vendor/...
15
votes
3
answers
25k
views
Is it possible to disable plugins defined in di.xml programatically?
Given a plugin defined in di.xml such as the following:
<type name="\Magento\Catalog\Model\Product">
<plugin name="se_catalog_product_plugin_ample"
type="Example\Module\Model\...
14
votes
1
answer
5k
views
Magento2 plugin around method different between callable and Closure paramters on param $proceed
I have checked magento2 ,There are two types of parameters that can be sent to
around method
\Closure $proceed example aroundSave(\Magento\Catalog\Model\Product $subject, \closure $proceed)
callable ...
14
votes
2
answers
1k
views
Magento 2: Consequences of not Naming a plugin class `\Plugin`
Are there any consequences for using a plugin class in Magento 2 that doesn't end in \Plugin? The docs suggest that this class should end in the name \Plugin.
The name of a plug-in’s class or its ...
12
votes
4
answers
8k
views
What are the top useful Phpstorm plugins for Magento 2 development?
What are the list of useful magento2 development tools?
What are the top phpstorm useful plugins for magento2 development?
11
votes
2
answers
3k
views
Plugins for magic getters/setters
I'm trying to make the status of a review be approved instead of pending when the user posts it in the frontend in Magento 2.
And I took this approach. Create a before plugin, available only in the ...
11
votes
1
answer
5k
views
Magento 2: get a list of all plugins (interceptors) and preferences
Is there a way I can retrieve the list of all plugins (with the methods they're plugged onto) and all preferences (and their original class) on a Magento 2 install.
10
votes
2
answers
4k
views
Magento 2: virtual types plugins
I'm confused by Magento 2 documentation regarding plugins:
It is first said that:
Plugins cannot be used with virtual types
But then it is said that:
You can specify a class, interface, or ...
9
votes
3
answers
2k
views
Magento 2: Which extension mechanism to choose?
We can extend controller in two ways: using preference and using plugin.
But I do not understand that, which one is good and advantages/disadvantages of preference vs plugin.
<preference for="...
9
votes
2
answers
7k
views
Magento 2 Plugin Sort Order
I am trying to understand the concept of sort order when using the plugin.
As per my understanding, the sort order works in lower to higher when used before method and higher to lower when used in ...
9
votes
1
answer
2k
views
Saving custom payment field data in magento 2 through plugin not working,
I am trying to save my custom field data through plugin but it's not working.
Plugin Class
namespace Vendor\Module\Model\Checkout;
class PaymentInformationManagementPlugin {
protected $...
8
votes
2
answers
2k
views
Plugins - is it bad habit to inherit from modified class in order to use protected properties
If I make plugin it is not neccessary to inherit from class I override. But, sometimes method I change uses properties that has protected access and they can't be used by plugin class.
But if I ...
8
votes
2
answers
4k
views
Circular dependency: Magento\Customer\Model\Session depends on Company\Modulename\Plugin\Config\Share and vice versa
How to override or Use plugin for isWebsiteScope() function from
Magento\Customer\Model\Config\Share.php file,
I have used plugin for below function but I want to get current customer session in ...
8
votes
1
answer
2k
views
What causes the following error: Warning: Illegal string offset 'is_in_stock' ... AdvancedInventory.php on line 87
During module development I've been writing a plugin which modifies the product options collection before it was loaded (adds a description field). Here is it:
etc/di.xml
<type name="Magento\...
8
votes
3
answers
4k
views
Magento 2 create plugin for my module
I have created plugin to add link for every product as below:
<?php
namespace Vendorname\Modulename\Plugin;
class ProductData
{
protected $urlInterface;
protected $scopeConfig;
...
7
votes
2
answers
19k
views
Magento 2 - Get Request Params / Api Request Params From Plugin
I am trying to access request parameters made to the api url which I am setting a response for via a plugin.
The call is to: rest/default/V1/guest-carts/a9e6330920e85d09a123a396f77a9275/shipping-...
7
votes
2
answers
3k
views
Magento 2 javascript plugin after method is executed in wrong time
Following this post answer I have used mixins of shipping.js file to change the result of validateShippingInformation method. My requirers-config.js file is:
var config = {
config: {
...
7
votes
5
answers
13k
views
Redirect from plugin Magento 2
I am trying to redirect to custom URL by using plugin feature of Magento 2 but somehow I am not able to redirect it. For this, I tried a couple of options like,
Magento2: redirection from Observer
...
7
votes
4
answers
18k
views
Get content of CMS block by identifier
I need to create a module which lets the backend user add tooltips to the products custom options. So I created a field which the user fills with the unique identifier of a cms block which contains ...
7
votes
2
answers
3k
views
How to write tests when closures are involved
For learning purposes I was trying to write a unit test for one of my Magento 2 around plugins (interception).
The method I'm testing receives as parameter a \Closure object that cannot be mocked ...
7
votes
1
answer
5k
views
Reference to undeclared plugin with name 'stockedProductsFilterPlugin' warning in di compile magento 2.3.2
I have recently upgraded my site from Magento 2.2.6 to Magento 2.3.2.
During each di compilation it shows a warning like
main.INFO: Reference to undeclared plugin with name '...
6
votes
1
answer
5k
views
Magento 2 Plugin implementation for js frontend?
A plugin as far as I read is created for intercepting a PHP function call and running code before, after, or around that function call. Is there a way how to accomplish that in js file?
How can i ...
6
votes
1
answer
5k
views
Magento2 - plugin / event after invoice is created
I need to execute some custom code after invoice is created
I have some code working fine, when invoices are created in admin storeview (I am observing sales_order_save_before event & checking for ...
6
votes
2
answers
968
views
Magento 2: Disable and enable payment method programmatically
I want to place order programmatically. I do not have COD enable when I placed the order programmatically so can it be possible that I can enable the COD before order place and disable COD after Order ...
6
votes
2
answers
1k
views
Does <sequence> also affect the load order of plugin?
According to magento devdocs
declares the list of components that must be loaded before the current component is loaded. It’s used for loading different kind of files: configuration files, view ...
6
votes
1
answer
1k
views
Custom Module for Custom Column using Plugin Yes/No option
I have been digging all day trying to figure out a way to enable/disable the plugins of my custom module with system configuration yes/no. Basically, I have a custom module that adds the Company ...
6
votes
1
answer
1k
views
Magento 2 : How to reload minicart from Plugin?
I've written plugin for Magento\Checkout\Controller\Cart::Delete
Plugin works great and removed my desirable product from cart.
As much as I know Minicart is render with local storage. So that we ...
6
votes
0
answers
3k
views
How to restrict access to user for particular store in Magento 2?
I have a requirement where multiple stores are created under one website.
Now, I want to create role so that role has access only to the particular store.
For e.g. If there is role Dell Manager so ...
6
votes
0
answers
1k
views
How to override class Virtual Type class
I saw this, but it don't work for me.
How to override Virtual Type class in Magento 2
<virtualType name="categoryFilterList" type="Magento\Catalog\Model\Layer\FilterList">
<arguments>...
5
votes
3
answers
2k
views
Add after method with plugin on underscore methods
I try to add plugin after a method that start with underscore like this : "_myMethod".
My plugin work, I can add method after normal method, but I can't add my method after the one with " _ " before ...
5
votes
2
answers
3k
views
Magento 2 :How to change or update request data using beforeExecute plugin?
i just want to change some request params by using beforeExecute plugin so can i do same.... ?
etc/di.xml
**
<type name="Magento\Customer\Controller\Account\CreatePassword">
<plugin ...
5
votes
3
answers
11k
views
Magento 2: How to show/hide payment method on basis of amount
I'm using Magento 2 CE Version 2.1.0.
I have 2 payment method Paypal Express Checkout & Bank Transfer.
When the amount is greater than X then Paypal should not be displayed only Bank Transfer.
...
5
votes
1
answer
4k
views
Magento 2.2.4 Show error message returned by plugin
I'm beginner to Magento2 and I want to validate pincode which exists in custom table or not on Checkout page (www.test.com/checkout/), according to that I want to display error message on same page. ...
5
votes
2
answers
2k
views
Magento 2: Can you use a Plugin with the `Psr\Log\LoggerInterface` type?
I've got a di.xml that looks something like this
<config>
<type name="Psr\Log\LoggerInterface">
<plugin name="namespace_modulename_plugins_psr"
type="...
5
votes
1
answer
2k
views
How can I change the shipping price at checkout with an observer or plugin?
The shipping method may be flatrate or FedEx or freeshipping, but I want to override this price with $1. How can I do this?
5
votes
3
answers
2k
views
How can we get stock data in product listing via afterGetList plugin in Magento 2.2.3
Since magento 2.2.3 is displaying out of stock items in product listing, I would like to get the qty attribute in the listing using rest API. I'm using afterGetList plugin.
di.xml
<type name="...
5
votes
2
answers
6k
views
Magento 2 : Use plugin / interceptor on abstract class
I am trying to create a plugin that fires after \Magento\Sales\Controller\Adminhtml\Shipment\AbstractShipment\PrintAction::execute.
So I have my plugin setup in di.xml and an afterExecute() method, ...
5
votes
1
answer
10k
views
Magento2: plugin around method not working
I'm trying to use the plugin around method to override the execute method of \Magento\Checkout\Controller\Onepage\Success.php. I'm trying to create a module that allows you to view the checkout ...
5
votes
1
answer
621
views
Magento 2 - Plugins on some classes don't work in etc/frontend/di.xml
I'm trying to do this:
<type name="Magento\Payment\Model\MethodList">
<plugin name="a_name_plugin" type="Mynamespace\Mymodule\Plugin\Model\Payment\MethodList\Plugin" sortOrder="10"/>
&...
5
votes
2
answers
2k
views
Overwrite magento2 function using plugin method?
I want to customize return value of $block->getProductDetailsHtml($_product) (in list.phtml) using plugin method, not overrite list.phtml
5
votes
4
answers
2k
views
Magento 2 developer mode doesn't generates Interceptors
If a class has plugins and the deploy mode is set to developer the ObjectManager is supposed to generate an Interceptor of the class as needed. That's what happens when running bin/magento setup:di:...